TCP transport

Axis2 supports TCP as a transport. Axis2 has support for both send and receive SOAP Messages via TCP. TCP transport does not have any application level headers and the SOAP Message that is send should be self contained. This makes the interaction fast and simple. Since there are no application headers, it does not have the privilege of having request URI, and Service dispatching should be done with a alternative method. Thus, RequestURIBasedDispatcher can not be used. Following are the two main alternatives available in dispatching in Axis2 Environment.

  1. Use the name space URI of the first child element of SOAPBody. (SOAPMessageBodyBasedDispatcher)
  2. Enable the WS-Addressing. in the case of 0.94 release addressing is default (SOAPActionBasedDispatcher)

When TCP request is sent it's user's responsibility to use either addressing or SOAP body base mechanism.

How to start the TCPServer

The TCP server can be started by running the class org.apache.axis2.transport.tcp.TCPServer with two parameters repository and port number as argument. 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 repository (See User Guide for more information)

Alternatively the TCP Server can run with tcp-server.bat/ tcp-server.sh file in the bin directory of the Binary distribution of TCP Server.

How to send SOAP Messages using TCP transport

The TCP transport can be enabled easily from the call API. Following code segment demonstrate how it can be done.

OMElement payload = ...

ServiceClient serviceClient = new ServiceClient();
Options options = new Options();
options.setTo(targetEPR);
options.useSeperateListener(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, also TCP . SOAP Message has to be self contained in order to use addressing. Only other option one can think of 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.

Sample

Sample for a TCP Client can be found from the samples/userguide/src/userguide/clients/TCPClient.java in the binary distribution. This access the same web service explained in the Axis2 userguide. The client first starts the TCPServer with the same repository used for the Axis2 userguide samples. Since sample is already deployed in the repository while trying the userguide it will be automatically available.

Transport Components

Axis2 TCP transport has two components, a transport Listener for receiving the Messages and transport Sender to send the SOAP Messages. Axis2 installation has both the components built in to itself by default. In the axis2.xml configuration file the two TCP transport components would look like as follows.

If the TCP server is started manually this configuration does not take effect. In return this effects the transport Listener's start by Axis2. (e.g. Listener started by the Complete Async interaction)

Following xml lines initializes the TCPTransport Receiver:

<transportReceiver name="tcp" class="org.apache.axis2.transport.tcp.TCPServer">
    <parameter name="port" locked="false">6060</parameter>
</transportReceiver>

Following xml lines adds the TCPTransport Sender:

<transportSender name="tcp" class="org.apache.axis2.transport.tcp.TCPTransportSender"/>