This post describes how to process binary data over TCP transport in WSO2 ESB.
- First we need to enable binary transport. Add following entries in ESB_HOME
/repository/conf/axis2/axis2.xml. This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters<transportReceiver name="tcp" class="org.apache.axis2.transport.tcp.TCPTransportListener" /> <transportSender name="tcp" class="org.apache.axis2.transport.tcp.TCPTransportSender"/>
- Now you need to add the message formatters and message builders to be used. Since we are using binary data, add following entry inside messageFormatters element. This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
<messageFormatter contentType="application/binary" class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
Add following entry inside messageBuilders element.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<messageBuilder contentType="application/binary" class="org.wso2.carbon.relay.BinaryRelayBuilder"/> |
- Now you can add a tcp proxy service to process the message. In that proxy service you need to add the same content type used in messageFormatter and messageBuilder configs. There are several other parameters specific to TCP proxies. Refer [1] for more info on that. Following is a sample proxy service that prints the binary message. This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="http://ws.apache.org/ns/synapse" name="TCPProxy" startOnLoad="true" statistics="disable" trace="disable" transports="tcp"> <target> <inSequence> <log level="full"/> </inSequence> <faultSequence> <log level="full"/> </faultSequence> </target> <parameter name="transport.tcp.recordDelimiter">|</parameter> <parameter name="transport.tcp.inputType">binary</parameter> <parameter name="transport.tcp.port">6060</parameter> <parameter name="transport.tcp.recordDelimiterType">character</parameter> <parameter name="transport.tcp.contentType">application/binary</parameter> <description/> </proxy>
- Now you can invoke this proxy service using a sample TCP client. End of message should be marked with a "|" symbol in this particular proxy service.
No comments:
Post a Comment