This document explains how to send and receive SOAP messages via TCP in Axis2.
Axis2 supports TCP as a transport. It supports both sending and receiving SOAP messages via TCP. A TCP transport does not have any application level headers and the SOAP message that is sent should be self-contained. This makes the interaction fast and simple. However, since there are no application headers, it does not have the privilege of having a request URI, and Service dispatching should be done by an alternative method. Thus, RequestURIBasedDispatcher cannot be used. The following are the two main alternatives available for dispatching in the Axis2 environment:
When the TCP request is sent, it is the user's responsibility to use either Addressing or the SOAP body base mechanism.
The TCP server can be started by running the class org.apache.axis2.transport.tcp.TCPServer with two parameters - repository and port number, as arguments. This class needs all the Axis dependency JARs in the classpath. New services can be added in the usual way by dropping the archives to the repository.
TCP transport can be enabled easily from the call API. The following code segment demonstrates how this can be done.
OMElement payload = ... ServiceClient serviceClient = new ServiceClient(); Options options = new Options(); options.setTo(targetEPR); options.useSeparateListener(false); serviceClient.setOptions(options); OMElement response = serviceClient.sendReceive(payload);
The transport that should be invoked is inferred from the targetEPR (tcp://...). In this case it is TCP and the listener is also TCP. The SOAP message has to be self contained in order to use Addressing. The other option is to use the URI of the first child of the SOAP Body to dispatch the service. The parameter is of the type OMElement, the XML representation of Axis2.
A sample for a TCP Client can be found from the samples/userguide/src/userguide/clients/TCPClient.java in the binary distribution. This accesses the same Web service explained in the Axis2 Advanced User's Guide. The client first starts the TCPServer with the same repository used for the Axis2 Advanced User's Guide samples. Since the sample is already deployed in the repository, as per the userguide, it will be automatically available.
In order to run the TCPClient.java, addressing should be engaged both in the client and server sides. On the client side, you can engage addressing by copying the addressing-@axis2_version@.mar (AXIS2_HOME/repository/module) to AXIS2_HOME/lib directory.
The Axis2 TCP transport has two components, a transport Listener for receiving the messages and a transport Sender to send the SOAP Messages. The Axis2 installation has both the components built into itself by default. In the axis2.xml configuration file, the two TCP transport components can be configured as shown below.
The following XML lines initialize the TCPTransport Receiver:
<transportReceiver name="tcp" class="org.apache.axis2.transport.tcp.TCPServer"> <parameter name="port">6060</parameter> </transportReceiver>
The following XML lines add the TCPTransport Sender:
<transportSender name="tcp" class="org.apache.axis2.transport.tcp.TCPTransportSender"/>
Note: If the TCP server is started manually, this configuration does not take effect. In return, this affects the transport Listener's start by Axis2. (e.g. Listener started by the Complete Async interaction)