You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2010/06/01 22:04:25 UTC

svn commit: r950232 - in /axis/axis2/java/transports/trunk: modules/tcp/ modules/tcp/conf/ modules/tcp/src/org/apache/axis2/transport/tcp/ modules/tcp/test/org/apache/axis2/transport/tcp/ src/site/apt/

Author: veithen
Date: Tue Jun  1 20:04:25 2010
New Revision: 950232

URL: http://svn.apache.org/viewvc?rev=950232&view=rev
Log:
AXIS2-4723: Applied Hiranya Jayathilaka's patch containing a refactored and improved version of the TCP transport. In particular, it is now possible to configure the TCP transport at service level (i.e. open a TCP port and link it to a particular service). This makes usage of WS-Addressing optional.

Added:
    axis/axis2/java/transports/trunk/modules/tcp/conf/client_axis2.xml   (with props)
    axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPConstants.java   (with props)
    axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPEndpoint.java   (with props)
    axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPOutTransportInfo.java   (with props)
    axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPTransportListener.java   (with props)
Modified:
    axis/axis2/java/transports/trunk/modules/tcp/conf/axis2.xml
    axis/axis2/java/transports/trunk/modules/tcp/pom.xml
    axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPServer.java
    axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPTransportSender.java
    axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPWorker.java
    axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/TCPEchoRawXMLTest.java
    axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/TCPTwoChannelEchoRawXMLTest.java
    axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/UtilsTCPServer.java
    axis/axis2/java/transports/trunk/src/site/apt/tcp-transport.apt

Modified: axis/axis2/java/transports/trunk/modules/tcp/conf/axis2.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/modules/tcp/conf/axis2.xml?rev=950232&r1=950231&r2=950232&view=diff
==============================================================================
--- axis/axis2/java/transports/trunk/modules/tcp/conf/axis2.xml (original)
+++ axis/axis2/java/transports/trunk/modules/tcp/conf/axis2.xml Tue Jun  1 20:04:25 2010
@@ -137,11 +137,13 @@
     <!--</targetResolvers>-->
 
     <transportReceiver name="tcp"
-                       class="org.apache.axis2.transport.tcp.TCPServer">
-        <parameter name="port">6060</parameter>
+                       class="org.apache.axis2.transport.tcp.TCPTransportListener">
+        <parameter name="transport.tcp.port">5555</parameter>
         <!--If you want to give your own host address for EPR generation-->
         <!--uncommet following paramter , and set as you required.-->
-        <!--<parameter name="hostname">tcp://myApp.com/ws</parameter>-->
+        <!--<parameter name="transport.tcp.hostname">tcp://myApp.com/ws</parameter>-->
+        <!--parameter name="transport.tcp.contentType">text/xml</parameter-->
+        <!--<parameter name="transport.tcp.backlog">50</parameter>-->
     </transportReceiver>
 
     <transportSender name="tcp"

Added: axis/axis2/java/transports/trunk/modules/tcp/conf/client_axis2.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/modules/tcp/conf/client_axis2.xml?rev=950232&view=auto
==============================================================================
--- axis/axis2/java/transports/trunk/modules/tcp/conf/client_axis2.xml (added)
+++ axis/axis2/java/transports/trunk/modules/tcp/conf/client_axis2.xml Tue Jun  1 20:04:25 2010
@@ -0,0 +1,246 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License. You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied. See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<axisconfig name="AxisJava2.0">
+    <!-- ================================================= -->
+    <!-- Parameters -->
+    <!-- ================================================= -->
+    <parameter name="hotdeployment">true</parameter>
+    <parameter name="hotupdate">false</parameter>
+    <parameter name="enableMTOM">false</parameter>
+
+    <!--If turned on with use the Accept header of the request to determine the contentType of the
+    response-->
+    <parameter name="httpContentNegotiation">false</parameter>
+
+    <!--During a fault, stacktrace can be sent with the fault message. The following flag will control -->
+    <!--that behaviour.-->
+    <parameter name="sendStacktraceDetailsWithFaults">true</parameter>
+
+    <!--If there aren't any information available to find out the fault reason, we set the message of the exception-->
+    <!--as the faultreason/Reason. But when a fault is thrown from a service or some where, it will be -->
+    <!--wrapped by different levels. Due to this the initial exception message can be lost. If this flag-->
+    <!--is set then, Axis2 tries to get the first exception and set its message as the faultreason/Reason.-->
+    <parameter name="DrillDownToRootCauseForFaultReason">false</parameter>
+
+    <!--This is the user name and password of admin console-->
+    <parameter name="userName">admin</parameter>
+    <parameter name="password">axis2</parameter>
+
+    <!--To override repository/services you need to uncomment following parameter and value SHOULD be absolute file path.-->
+    <!--ServicesDirectory only works on the following cases-->
+    <!---File based configurator and in that case the value should be a file URL (http:// not allowed)-->
+    <!---When creating URL Based configurator with URL “file://”  -->
+    <!--- War based configurator with expanded case , -->
+
+    <!--All the other scenarios it will be ignored.-->
+    <!--<parameter name="ServicesDirectory">service</parameter>-->
+    <!--To override repository/modules you need to uncomment following parameter and value SHOULD be absolute file path-->
+    <!--<parameter name="ModulesDirectory">modules</parameter>-->
+
+    <!--Following params will set the proper context paths for invocations. All the endpoints will have a commons context-->
+    <!--root which can configured using the following contextRoot parameter-->
+    <!--<parameter name="contextRoot">axis2</parameter>-->
+
+    <!--Our HTTP endpoints can handle both REST and SOAP. Following parameters can be used to distinguish those endpoints-->
+    <!--<parameter name="servicePath">services</parameter>-->
+    <!--<parameter name="restPath">rest</parameter>-->
+
+    <!-- Following parameter will completely disable REST handling in Axis2-->
+    <parameter name="disableREST" locked="false">false</parameter>
+
+    <!--POJO deployer , this will alow users to drop .class file and make that into a service-->
+    <deployer extension=".class" directory="pojo" class="org.apache.axis2.deployment.POJODeployer"/>
+    <deployer extension=".jar" directory="transports" class="org.apache.axis2.deployment.TransportDeployer"/>
+
+    <!-- Following parameter will set the host name for the epr-->
+    <!--<parameter name="hostname" locked="true">myhost.com</parameter>-->
+
+    <!-- ================================================= -->
+    <!-- Message Receivers -->
+    <!-- ================================================= -->
+    <!--This is the Default Message Receiver for the system , if you want to have MessageReceivers for -->
+    <!--all the other MEP implement it and add the correct entry to here , so that you can refer from-->
+    <!--any operation -->
+    <!--Note : You can override this for particular service by adding the same element with your requirement-->
+    <messageReceivers>
+        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
+                         class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
+        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
+                         class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+        <messageReceiver mep="http://www.w3.org/2006/01/wsdl/in-only"
+                         class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
+        <messageReceiver mep="http://www.w3.org/2006/01/wsdl/in-out"
+                         class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+    </messageReceivers>
+
+    <!-- ================================================= -->
+    <!-- Message Formatter -->
+    <!-- ================================================= -->
+    <!--Following content type to message formatter mapping can be used to implement support for different message -->
+    <!--format  serialization in Axis2. These message formats are expected to be resolved based on the content type. -->
+    <messageFormatters>
+        <messageFormatter contentType="application/x-www-form-urlencoded"
+                         class="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/>
+        <messageFormatter contentType="multipart/form-data"
+                         class="org.apache.axis2.transport.http.MultipartFormDataFormatter"/>
+        <messageFormatter contentType="application/xml"
+                         class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
+        <messageFormatter contentType="text/xml"
+                         class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
+        <messageFormatter contentType="application/soap+xml"
+                         class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
+    </messageFormatters>
+
+    <!-- ================================================= -->
+    <!-- Message Builders -->
+    <!-- ================================================= -->
+    <!--Following content type to builder mapping can be used to implement support for different message -->
+    <!--formats in Axis2. These message formats are expected to be resolved based on the content type. -->
+    <messageBuilders>
+        <messageBuilder contentType="application/xml"
+                         class="org.apache.axis2.builder.ApplicationXMLBuilder"/>
+        <messageBuilder contentType="application/x-www-form-urlencoded"
+                         class="org.apache.axis2.builder.XFormURLEncodedBuilder"/>
+        <!--Left commented because it adds the depandancy of servlet-api to other modules.
+        Please uncomment to Receive messages in multipart/form-data format-->
+        <!--<messageBuilder contentType="multipart/form-data"-->
+                         <!--class="org.apache.axis2.builder.MultipartFormDataBuilder"/>-->
+    </messageBuilders>
+
+    <module ref="addressing"/>
+
+    <!-- ================================================= -->
+    <!-- Target Resolvers -->
+    <!-- ================================================= -->
+    <!-- Uncomment the following and specify the class name for your TargetResolver to add -->
+    <!-- a TargetResolver. TargetResolvers are used to process the To EPR for example to -->
+    <!-- choose a server in a cluster -->
+    <!--<targetResolvers>-->
+    <!--<targetResolver class="" />-->
+    <!--</targetResolvers>-->
+
+    <transportReceiver name="tcp"
+                       class="org.apache.axis2.transport.tcp.TCPTransportListener">
+        <parameter name="transport.tcp.port">5556</parameter>
+    </transportReceiver>
+
+    <transportSender name="tcp"
+                     class="org.apache.axis2.transport.tcp.TCPTransportSender"/>
+
+
+    <!-- ================================================= -->
+    <!--  SOAP Role Configuration                          -->
+    <!-- ================================================= -->
+    <!-- Use the following pattern to configure this axis2
+         instance to act in particular roles. Note that in
+         the absence of any configuration, Axis2 will act
+         only in the ultimate receiver role -->
+    <!--
+    <SOAPRoleConfiguration isUltimateReceiver="true">
+    	<role>http://my/custom/role</role>
+    </SOAPRoleConfiguration>
+	-->
+
+    <!-- ================================================= -->
+    <!-- Phases  -->
+    <!-- ================================================= -->
+    <phaseOrder type="InFlow">
+        <!--  System pre-defined phases       -->
+         <phase name="Transport">
+            <handler name="RequestURIBasedDispatcher"
+                     class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher">
+                <order phase="Transport"/>
+            </handler>
+            <handler name="SOAPActionBasedDispatcher"
+                     class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher">
+                <order phase="Transport"/>
+            </handler>
+         </phase>
+        <phase name="Addressing">
+            <handler name="AddressingBasedDispatcher"
+                     class="org.apache.axis2.dispatchers.AddressingBasedDispatcher">
+                <order phase="Addressing"/>
+            </handler>
+        </phase>
+        <phase name="Security"/>
+        <phase name="PreDispatch"/>
+        <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase">
+            <handler name="RequestURIBasedDispatcher"
+                     class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/>
+            <handler name="SOAPActionBasedDispatcher"
+                     class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/>
+            <handler name="RequestURIOperationDispatcher"
+                     class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/>
+            <handler name="SOAPMessageBodyBasedDispatcher"
+                     class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/>
+
+            <handler name="HTTPLocationBasedDispatcher"
+                     class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/>
+        </phase>
+        <phase name="RMPhase"/>
+        <!--  System pre defined phases       -->
+        <!--   After Postdispatch phase module author or or service author can add any phase he want      -->
+        <phase name="OperationInPhase"/>
+    </phaseOrder>
+    <phaseOrder type="OutFlow">
+        <!--      user can add his own phases to this area  -->
+        <phase name="OperationOutPhase"/>
+        <!--system predefined phase-->
+        <!--these phase will run irrespective of the service-->
+        <phase name="RMPhase"/>
+        <phase name="PolicyDetermination"/>
+        <phase name="MessageOut"/>
+        <phase name="Security"/>
+    </phaseOrder>
+    <phaseOrder type="InFaultFlow">
+        <phase name="Addressing">
+             <handler name="AddressingBasedDispatcher"
+                     class="org.apache.axis2.dispatchers.AddressingBasedDispatcher">
+                 <order phase="Addressing"/>
+            </handler>
+        </phase>
+        <phase name="Security"/>
+        <phase name="PreDispatch"/>
+        <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase">
+            <handler name="RequestURIBasedDispatcher"
+                     class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/>
+            <handler name="SOAPActionBasedDispatcher"
+                     class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/>
+            <handler name="RequestURIOperationDispatcher"
+                     class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/>
+            <handler name="SOAPMessageBodyBasedDispatcher"
+                     class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/>
+
+            <handler name="HTTPLocationBasedDispatcher"
+                     class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/>
+        </phase>
+        <phase name="RMPhase"/>
+        <!--      user can add his own phases to this area  -->
+        <phase name="OperationInFaultPhase"/>
+    </phaseOrder>
+    <phaseOrder type="OutFaultFlow">
+        <!--      user can add his own phases to this area  -->
+        <phase name="OperationOutFaultPhase"/>
+        <phase name="RMPhase"/>
+        <phase name="PolicyDetermination"/>
+        <phase name="MessageOut"/>
+        <phase name="Security"/>
+    </phaseOrder>
+</axisconfig>

Propchange: axis/axis2/java/transports/trunk/modules/tcp/conf/client_axis2.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: axis/axis2/java/transports/trunk/modules/tcp/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/modules/tcp/pom.xml?rev=950232&r1=950231&r2=950232&view=diff
==============================================================================
--- axis/axis2/java/transports/trunk/modules/tcp/pom.xml (original)
+++ axis/axis2/java/transports/trunk/modules/tcp/pom.xml Tue Jun  1 20:04:25 2010
@@ -67,6 +67,8 @@
     	                              tofile="target/test-resources/samples/modules/addressing.mar"/>
                                 <copy file="conf/axis2.xml"
     	                              tofile="target/test-resources/samples/conf/axis2.xml"/>
+                                <copy file="conf/client_axis2.xml"
+    	                              tofile="target/test-resources/samples/conf/client_axis2.xml"/>
                             </tasks>
                         </configuration>
                        <goals>

Added: axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPConstants.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPConstants.java?rev=950232&view=auto
==============================================================================
--- axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPConstants.java (added)
+++ axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPConstants.java Tue Jun  1 20:04:25 2010
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.transport.tcp;
+
+public class TCPConstants {
+
+    public static final String PARAM_PORT = "transport.tcp.port";
+    public static final String PARAM_HOST = "transport.tcp.hostname";
+    public static final String PARAM_BACKLOG = "transport.tcp.backlog";
+    public static final String PARAM_CONTENT_TYPE = "transport.tcp.contentType";
+
+    public static final int TCP_DEFAULT_BACKLOG = 50;
+    public static final String TCP_DEFAULT_CONTENT_TYPE = "text/xml";
+
+    public static final String TCP_OUTPUT_SOCKET = "transport.tcp.outputSocket";
+}

Propchange: axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPEndpoint.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPEndpoint.java?rev=950232&view=auto
==============================================================================
--- axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPEndpoint.java (added)
+++ axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPEndpoint.java Tue Jun  1 20:04:25 2010
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.axis2.transport.tcp;
+
+import org.apache.axis2.transport.base.ProtocolEndpoint;
+import org.apache.axis2.transport.base.ParamUtils;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.util.Utils;
+import org.apache.axis2.description.ParameterInclude;
+import org.apache.axis2.description.AxisService;
+
+import java.net.SocketException;
+
+public class TCPEndpoint extends ProtocolEndpoint {
+
+    private String host = null;
+    private int port = -1;
+    private int backlog = TCPConstants.TCP_DEFAULT_BACKLOG;
+    private String contentType;
+
+    public TCPEndpoint() {
+
+    }
+
+    public TCPEndpoint(String host, int port, int backlog) {
+        this.host = host;
+        this.port = port;
+        this.backlog = backlog;
+    }
+
+    public int getPort() {
+        return port;
+    }
+
+    public String getHost() {
+        return host;
+    }
+
+    public int getBacklog() {
+        return backlog;
+    }
+
+    public String getContentType() {
+        return contentType;
+    }
+
+    public boolean loadConfiguration(ParameterInclude params) throws AxisFault {
+        port = ParamUtils.getOptionalParamInt(params, TCPConstants.PARAM_PORT, -1);
+        if (port == -1) {
+            return false;
+        }
+
+        contentType = ParamUtils.getOptionalParam(params, TCPConstants.PARAM_CONTENT_TYPE);
+        if (contentType == null) {
+            contentType = TCPConstants.TCP_DEFAULT_CONTENT_TYPE;
+        }
+
+        host = ParamUtils.getOptionalParam(params, TCPConstants.PARAM_HOST);
+        backlog = ParamUtils.getOptionalParamInt(params, TCPConstants.PARAM_BACKLOG,
+                TCPConstants.TCP_DEFAULT_BACKLOG);
+        return true;
+    }
+
+    public EndpointReference[] getEndpointReferences(AxisService service,
+                                                     String ip) throws AxisFault {
+        if (host == null && ip == null) {
+            try {
+                ip = Utils.getIpAddress(getListener().getConfigurationContext().
+                        getAxisConfiguration());
+            } catch (SocketException ex) {
+                throw new AxisFault("Unable to determine the host's IP address", ex);
+            }
+        }
+
+        String url = "tcp://" + (host != null ? host : ip) + ":" + port;
+        String context = getListener().getConfigurationContext().getServiceContextPath();
+        url +=  (context.startsWith("/") ? "" : "/") + context +
+                (context.endsWith("/") ? "" : "/") +
+                (getService() == null ? service.getName() : getServiceName());
+
+        if (!contentType.equals(TCPConstants.TCP_DEFAULT_CONTENT_TYPE)) {
+            url += "?contentType=" + contentType;
+        }
+
+        return new EndpointReference[] { new EndpointReference(url) };
+    }
+    
+}

Propchange: axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPOutTransportInfo.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPOutTransportInfo.java?rev=950232&view=auto
==============================================================================
--- axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPOutTransportInfo.java (added)
+++ axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPOutTransportInfo.java Tue Jun  1 20:04:25 2010
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.transport.tcp;
+
+import org.apache.axis2.transport.OutTransportInfo;
+
+import java.io.OutputStream;
+import java.net.Socket;
+
+public class TCPOutTransportInfo implements OutTransportInfo {
+
+    private Socket socket;
+    private String contentType;
+
+    public Socket getSocket() {
+        return socket;
+    }
+
+    public void setSocket(Socket socket) {
+        this.socket = socket;
+    }
+
+    public void setContentType(String contentType) {
+        this.contentType = contentType;
+    }
+
+    public String getContentType() {
+        return contentType;
+    }
+}

Propchange: axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPOutTransportInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPServer.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPServer.java?rev=950232&r1=950231&r2=950232&view=diff
==============================================================================
--- axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPServer.java (original)
+++ axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPServer.java Tue Jun  1 20:04:25 2010
@@ -20,101 +20,27 @@
 
 package org.apache.axis2.transport.tcp;
 
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.Constants;
-import org.apache.axis2.util.Utils;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.SessionContext;
-import org.apache.axis2.description.Parameter;
-import org.apache.axis2.description.TransportInDescription;
-import org.apache.axis2.engine.ListenerManager;
-import org.apache.axis2.i18n.Messages;
-import org.apache.axis2.transport.TransportListener;
-import org.apache.commons.logging.Log;
+import org.apache.axis2.transport.base.threads.WorkerPool;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
 
-import java.io.File;
-import java.io.IOException;
 import java.net.ServerSocket;
 import java.net.Socket;
-import java.net.SocketException;
+import java.net.InetAddress;
+import java.io.IOException;
 
-/**
- * Class TCPServer
- */
-public class TCPServer implements Runnable, TransportListener {
-    private int port = 8000;
+public class TCPServer implements Runnable {
+    
+    private TCPEndpoint endpoint;
+    private ServerSocket serverSocket;
+    private WorkerPool workerPool;
     private boolean started = false;
-    private static final Log log = LogFactory.getLog(TCPServer.class);
-    private ConfigurationContext configContext;
-    private ServerSocket serversocket;
-    private String hostAddress = null;
-    private String contextPath;
-
-    public TCPServer() {
-    }
-
-    public TCPServer(int port, ConfigurationContext configContext) throws AxisFault {
-        try {
-            this.configContext = configContext;
-            serversocket = new ServerSocket(port);
-
-            ListenerManager listenerManager = configContext.getListenerManager();
-            TransportInDescription trsIn = new TransportInDescription(Constants.TRANSPORT_TCP);
-            trsIn.setReceiver(this);
-            if (listenerManager == null) {
-                listenerManager = new ListenerManager();
-                listenerManager.init(configContext);
-            }
-            listenerManager.addListener(trsIn, true);
-            contextPath = configContext.getServiceContextPath();
-
-        } catch (IOException e1) {
-            throw AxisFault.makeFault(e1);
-        }
-    }
-
-    public TCPServer(int port, String dir) throws AxisFault {
-        this(port, ConfigurationContextFactory.createConfigurationContextFromFileSystem(dir, null));
-    }
 
-    public void init(ConfigurationContext axisConf, TransportInDescription transprtIn)
-            throws AxisFault {
-        this.configContext = axisConf;
-
-        Parameter param = transprtIn.getParameter(PARAM_PORT);
-
-        if (param != null) {
-            this.port = Integer.parseInt((String) param.getValue());
-        }
-        param = transprtIn.getParameter(HOST_ADDRESS);
-        if (param != null) {
-            hostAddress = ((String) param.getValue()).trim();
-        }
-        contextPath = configContext.getServiceContextPath();
-    }
-
-    public static void main(String[] args) throws AxisFault, NumberFormatException {
-        if (args.length != 2) {
-            System.out.println("TCPServer repositoryLocation port");
-        } else {
-            File repository = new File(args[0]);
-
-            if (!repository.exists()) {
-                System.out.print("Repository file does not exists .. initializing repository");
-            }
-
-            TCPServer tcpServer = new TCPServer(Integer.parseInt(args[1]),
-                                                repository.getAbsolutePath());
+    private static final Log log = LogFactory.getLog(TCPServer.class);
 
-            System.out.println("[Axis2] Using the Repository " + repository.getAbsolutePath());
-            System.out.println("[Axis2] Starting the TCP Server on port " + args[1]);
-            tcpServer.start();
-            Runtime.getRuntime().addShutdownHook(new Thread(tcpServer));
-        }
+    public TCPServer(TCPEndpoint endpoint, WorkerPool workerPool) {
+        this.endpoint = endpoint;
+        this.workerPool = workerPool;
     }
 
     public void run() {
@@ -122,110 +48,38 @@ public class TCPServer implements Runnab
             Socket socket = null;
 
             try {
-                socket = serversocket.accept();
-            } catch (java.io.InterruptedIOException iie) {
-            }
-            catch (Exception e) {
-                log.debug(e);
+                socket = serverSocket.accept();
+            } catch (java.io.InterruptedIOException ignored) {
 
+            } catch (Exception e) {
+                log.debug(e);
                 break;
             }
 
             if (socket != null) {
-                configContext.getThreadPool().execute(new TCPWorker(configContext, socket));
-            }
-        }
-    }
-
-    public synchronized void start() throws AxisFault {
-        if (serversocket == null) {
-            serversocket = openSocket(port);
-        }
-        started = true;
-        this.configContext.getThreadPool().execute(this);
-    }
-
-
-    /**
-     * Controls the number of server sockets kept open.
-     */
-    public ServerSocket openSocket(int port) throws AxisFault {
-        for (int i = 0; i < 5; i++) {
-            try {
-                return new ServerSocket(port + i);
-            } catch (IOException e) {
-                // What I'm gonna do here. Try again.
+                workerPool.execute(new TCPWorker(endpoint, socket));
             }
         }
-
-        throw new AxisFault(Messages.getMessage("failedToOpenSocket"));
     }
 
-
-    /*
-    *  (non-Javadoc)
-    * @see org.apache.axis2.transport.TransportListener#stop()
-    */
-    public void stop() throws AxisFault {
-        try {
-            this.serversocket.close();
-            started = false;
-        } catch (IOException e) {
-            throw AxisFault.makeFault(e);
-        }
-    }
-
-    public ConfigurationContext getConfigurationContext() {
-        return this.configContext;
-    }
-
-    /**
-     * I fthe hostAddress parameter is present in axis2.xml then the EPR will be
-     * created by taking the hostAddres into account
-     * (non-Javadoc)
-     *
-     * @see org.apache.axis2.transport.TransportListener#getEPRForService(String, String)
-     */
-    public EndpointReference getEPRForService(String serviceName, String ip) throws AxisFault {
-        EndpointReference[] epRsForService = getEPRsForService(serviceName, ip);
-        return epRsForService != null ? epRsForService[0] : null;
-    }
-
-    public EndpointReference[] getEPRsForService(String serviceName, String ip) throws AxisFault {
-        //if host address is present
-        if (hostAddress != null) {
-            if (serversocket != null) {
-                // todo this has to fix
-                return new EndpointReference[]{
-                        new EndpointReference(hostAddress + "/" + contextPath + serviceName)};
+    public void startServer() throws IOException {
+        if (serverSocket == null) {
+            if (endpoint.getHost() != null) {
+                InetAddress address = InetAddress.getByName(endpoint.getHost());
+                serverSocket = new ServerSocket(endpoint.getPort(), endpoint.getBacklog(), address);
             } else {
-                log.debug("Unable to generate EPR for the transport tcp");
-                return null;
+                serverSocket = new ServerSocket(endpoint.getPort(), endpoint.getBacklog());
             }
         }
-        if (ip == null) {
-            try {
-                ip = Utils.getIpAddress(configContext.getAxisConfiguration());
-            } catch (SocketException e) {
-                throw AxisFault.makeFault(e);
-            }
-        }
-        if (serversocket != null) {
-            // todo this has to fix
-            return new EndpointReference[]{
-                    new EndpointReference("tcp://" + ip + ":" + (serversocket.getLocalPort())
-                                          + "/" + contextPath + "/" + serviceName)};
-        } else {
-            log.debug("Unable to generate EPR for the transport tcp");
-            return null;
-        }
-    }
-
-    public SessionContext getSessionContext(MessageContext messageContext) {
-        return null;
+        started = true;
+        endpoint.getListener().getConfigurationContext().getThreadPool().execute(this);
+        log.info("TCP server started on port : " + endpoint.getPort());
     }
 
-    public void destroy() {
-        this.configContext = null;
+    public void stopServer() throws IOException {
+        started = false;
+        serverSocket.close();
+        serverSocket = null;
+        log.info("TCP server stopped on port : " + endpoint.getPort());
     }
 }

Added: axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPTransportListener.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPTransportListener.java?rev=950232&view=auto
==============================================================================
--- axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPTransportListener.java (added)
+++ axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPTransportListener.java Tue Jun  1 20:04:25 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.transport.tcp;
+
+import org.apache.axis2.transport.base.AbstractTransportListenerEx;
+import org.apache.axis2.AxisFault;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class TCPTransportListener extends AbstractTransportListenerEx<TCPEndpoint> {
+
+    private Map<TCPEndpoint, TCPServer> serverTable = new ConcurrentHashMap<TCPEndpoint, TCPServer>();
+
+    protected void doInit() throws AxisFault {
+
+    }
+
+    protected TCPEndpoint createEndpoint() {
+        return new TCPEndpoint();
+    }
+
+    protected void startEndpoint(TCPEndpoint endpoint) throws AxisFault {
+        try {
+            TCPServer server = new TCPServer(endpoint, workerPool);
+            server.startServer();
+            serverTable.put(endpoint, server);
+        } catch (IOException e) {
+            handleException("Error while starting the TCP endpoint", e);
+        }
+    }
+
+    protected void stopEndpoint(TCPEndpoint endpoint) {
+        try {
+            TCPServer server = serverTable.get(endpoint);
+            if (server != null) {
+                server.stopServer();
+            }
+        } catch (IOException e) {
+            log.error("Error while stopping the TCP endpoint", e);
+        } finally {
+            serverTable.remove(endpoint);
+        }
+    }
+}

Propchange: axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPTransportListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPTransportSender.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPTransportSender.java?rev=950232&r1=950231&r2=950232&view=diff
==============================================================================
--- axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPTransportSender.java (original)
+++ axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPTransportSender.java Tue Jun  1 20:04:25 2010
@@ -21,113 +21,128 @@
 package org.apache.axis2.transport.tcp;
 
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.OutInAxisOperation;
+import org.apache.axis2.engine.AxisEngine;
 import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.TransportOutDescription;
-import org.apache.axis2.handlers.AbstractHandler;
-import org.apache.axis2.i18n.Messages;
-import org.apache.axis2.transport.TransportSender;
+import org.apache.axis2.transport.OutTransportInfo;
 import org.apache.axis2.transport.TransportUtils;
-import org.apache.axis2.util.URL;
+import org.apache.axis2.transport.base.AbstractTransportSender;
+import org.apache.axiom.soap.SOAPEnvelope;
 
 import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Writer;
-import java.net.InetSocketAddress;
-import java.net.MalformedURLException;
-import java.net.Socket;
-import java.net.SocketAddress;
-
-public class TCPTransportSender extends AbstractHandler implements TransportSender {
-    protected Writer out;
-    private Socket socket;
+import java.net.*;
+import java.util.Map;
+import java.util.HashMap;
+
+public class TCPTransportSender extends AbstractTransportSender {
+
+    public void sendMessage(MessageContext msgContext, String targetEPR,
+                            OutTransportInfo outTransportInfo) throws AxisFault {
+
+        if (targetEPR != null) {
+            Map<String,String> params = getURLParameters(targetEPR);
+            int timeout = -1;
+            if (params.containsKey("timeout")) {
+                timeout = Integer.parseInt(params.get("timeout"));
+            }
+            Socket socket = openTCPConnection(targetEPR, timeout);
+            msgContext.setProperty(TCPConstants.TCP_OUTPUT_SOCKET, socket);
 
-    public void init(ConfigurationContext confContext, TransportOutDescription transportOut)
-            throws AxisFault {
-    }
+            try {
+                TransportUtils.writeMessage(msgContext, socket.getOutputStream());
+                if (!msgContext.getOptions().isUseSeparateListener() && !msgContext.isServerSide()){
+                    waitForReply(msgContext, socket, params.get("contentType"));
+                }
+            } catch (IOException e) {
+                handleException("Error while sending a TCP request", e);
+            }
 
-    public void stop() {
+        } else if (outTransportInfo != null && (outTransportInfo instanceof TCPOutTransportInfo)) {
+            TCPOutTransportInfo outInfo = (TCPOutTransportInfo) outTransportInfo;
+            try {
+                TransportUtils.writeMessage(msgContext, outInfo.getSocket().getOutputStream());
+            } catch (IOException e) {
+                handleException("Error while sending a TCP response", e);
+            } finally {
+                closeConnection(outInfo.getSocket());
+            }
+        }
     }
 
+    @Override
     public void cleanup(MessageContext msgContext) throws AxisFault {
+        Object socketObj = msgContext.getProperty(TCPConstants.TCP_OUTPUT_SOCKET);
+        if (socketObj != null) {
+            closeConnection((Socket) socketObj);
+        }
+    }
+
+    private void waitForReply(MessageContext msgContext, Socket socket,
+                              String contentType) throws AxisFault {
+
+        if (!(msgContext.getAxisOperation() instanceof OutInAxisOperation) &&
+                msgContext.getProperty(org.apache.axis2.Constants.PIGGYBACK_MESSAGE) == null) {
+            return;
+        }
+
+        if (contentType == null) {
+            contentType = TCPConstants.TCP_DEFAULT_CONTENT_TYPE;
+        }
+
         try {
-            if (socket != null) {
-                socket.close();
-                socket = null;
-            }
-        } catch (IOException e) {
-            // TODO: Log this?
+            MessageContext responseMsgCtx = createResponseMessageContext(msgContext);
+            SOAPEnvelope envelope = TransportUtils.createSOAPMessage(msgContext,
+                        socket.getInputStream(), contentType);
+            responseMsgCtx.setEnvelope(envelope);
+            AxisEngine.receive(responseMsgCtx);
+        } catch (Exception e) {
+            handleException("Error while processing response", e);
         }
     }
 
-    /**
-     * Method invoke
-     *
-     * @param msgContext
-     * @throws AxisFault
-     */
-    public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
-
-        // Check for the REST behaviour, if you desire rest beahaviour
-        // put a <parameter name="doREST" value="true"/> at the axis2.xml
-        msgContext.setDoingMTOM(TransportUtils.doWriteMTOM(msgContext));
-        msgContext.setDoingSwA(TransportUtils.doWriteSwA(msgContext));
-
-        OutputStream out;
-        EndpointReference epr = null;
-
-        if (msgContext.getTo() != null && !msgContext.getTo().hasAnonymousAddress()) {
-            epr = msgContext.getTo();
-        }
-
-        if (epr != null) {
-            if (!epr.hasNoneAddress()) {
-                out = openTheConnection(epr, msgContext);
-                TransportUtils.writeMessage(msgContext, out);
-                try {
-                    socket.shutdownOutput();
-                    msgContext.setProperty(MessageContext.TRANSPORT_IN, socket.getInputStream());
-                } catch (IOException e) {
-                    throw AxisFault.makeFault(e);
+    private Map<String,String> getURLParameters(String url) throws AxisFault {
+        try {
+            Map<String,String> params = new HashMap<String,String>();
+            URI tcpUrl = new URI(url);
+            String query = tcpUrl.getQuery();
+            if (query != null) {
+                String[] paramStrings = query.split("&");
+                for (String p : paramStrings) {
+                    int index = p.indexOf('=');
+                    params.put(p.substring(0, index), p.substring(index+1));
                 }
             }
-        } else {
-            out = (OutputStream) msgContext.getProperty(MessageContext.TRANSPORT_OUT);
+            return params;
+        } catch (URISyntaxException e) {
+            handleException("Malformed tcp url", e);
+        }
+        return null;
+    }
 
-            if (out != null) {
-                TransportUtils.writeMessage(msgContext, out);
-            } else {
-                throw new AxisFault(
-                        "Both the TO and Property MessageContext.TRANSPORT_OUT is Null, No where to send");
+    private Socket openTCPConnection(String url, int timeout) throws AxisFault {
+        try {
+            URI tcpUrl = new URI(url);
+            if (!tcpUrl.getScheme().equals("tcp")) {
+                throw new Exception("Invalid protocol prefix : " + tcpUrl.getScheme());
             }
+            SocketAddress address = new InetSocketAddress(tcpUrl.getHost(), tcpUrl.getPort());
+            Socket socket = new Socket();
+            if (timeout != -1) {
+                socket.setSoTimeout(timeout);
+            }
+            socket.connect(address);
+            return socket;
+        } catch (Exception e) {
+            handleException("Error while opening TCP connection to : " + url, e);
         }
-
-        TransportUtils.setResponseWritten(msgContext, true);
-        
-        return InvocationResponse.CONTINUE;
+        return null;
     }
 
-    protected OutputStream openTheConnection(EndpointReference toURL, MessageContext msgContext)
-            throws AxisFault {
-        if (toURL != null) {
-            try {
-                URL url = new URL(toURL.getAddress());
-                SocketAddress add = new InetSocketAddress(url.getHost(), (url.getPort() == -1)
-                        ? 80
-                        : url.getPort());
-
-                socket = new Socket();
-                socket.connect(add);
-
-                return socket.getOutputStream();
-            } catch (MalformedURLException e) {
-                throw AxisFault.makeFault(e);
-            } catch (IOException e) {
-                throw AxisFault.makeFault(e);
-            }
-        } else {
-            throw new AxisFault(Messages.getMessage("canNotBeNull", "End point reference"));
+    private void closeConnection(Socket socket) {
+        try {
+            socket.close();
+        } catch (IOException e) {
+            log.error("Error while closing a TCP socket", e);
         }
     }
 }

Modified: axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPWorker.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPWorker.java?rev=950232&r1=950231&r2=950232&view=diff
==============================================================================
--- axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPWorker.java (original)
+++ axis/axis2/java/transports/trunk/modules/tcp/src/org/apache/axis2/transport/tcp/TCPWorker.java Tue Jun  1 20:04:25 2010
@@ -17,101 +17,81 @@
  * under the License.
  */
 
-
 package org.apache.axis2.transport.tcp;
 
-import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
-import org.apache.axis2.builder.BuilderUtil;
-import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.transport.TransportUtils;
 import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.TransportInDescription;
-import org.apache.axis2.description.TransportOutDescription;
-import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.AxisEngine;
-import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.util.MessageContextBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.Reader;
 import java.net.Socket;
 
 /**
  * This Class is the work hoarse of the TCP request, this process the incomming SOAP Message.
  */
 public class TCPWorker implements Runnable {
+
     private static final Log log = LogFactory.getLog(TCPWorker.class);
-    private ConfigurationContext configurationContext;
+
+    private TCPEndpoint endpoint;
     private Socket socket;
 
-    public TCPWorker(ConfigurationContext configurationContext, Socket socket) {
-        this.configurationContext = configurationContext;
+    public TCPWorker(TCPEndpoint endpoint, Socket socket) {
+        this.endpoint = endpoint;
         this.socket = socket;
     }
 
     public void run() {
+
         MessageContext msgContext = null;
 
         try {
-            AxisConfiguration axisConf = configurationContext.getAxisConfiguration();
-            TransportOutDescription transportOut =
-                    axisConf.getTransportOut(Constants.TRANSPORT_TCP);
-            TransportInDescription transportIn =
-                    axisConf.getTransportIn(Constants.TRANSPORT_TCP);
-
-            if ((transportOut != null) && (transportIn != null)) {
-
-                // create the Message Context and fill in the values
-                msgContext = configurationContext.createMessageContext();
-                msgContext.setIncomingTransportName(Constants.TRANSPORT_TCP);
-                msgContext.setTransportIn(transportIn);
-                msgContext.setTransportOut(transportOut);
-                msgContext.setServerSide(true);
-
-                OutputStream out = socket.getOutputStream();
-
-                msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
-
-                // create the SOAP Envelope
-                Reader in = new InputStreamReader(socket.getInputStream());
-                OMXMLParserWrapper builder = BuilderUtil.getBuilder(in);
-                SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
-
-                msgContext.setEnvelope(envelope);
-                AxisEngine.receive(msgContext);
-            } else {
-                throw new AxisFault(Messages.getMessage("unknownTransport",
-                                                        Constants.TRANSPORT_TCP));
-            }
-        } catch (Throwable e) {
-            log.error(e.getMessage(), e);
-            try {
+            msgContext = endpoint.createMessageContext();
+            msgContext.setIncomingTransportName(Constants.TRANSPORT_TCP);
+            //msgContext.setTransportIn(endpoint.getListener().getTransportInDescription());
+
+            TCPOutTransportInfo outInfo = new TCPOutTransportInfo();
+            outInfo.setSocket(socket);
+            outInfo.setContentType(endpoint.getContentType());
+            msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, outInfo);
+
+            // create the SOAP Envelope
+            SOAPEnvelope envelope = TransportUtils.createSOAPMessage(msgContext,
+                    socket.getInputStream(), endpoint.getContentType());
+            msgContext.setEnvelope(envelope);
 
-                if (msgContext != null) {
-                    msgContext.setProperty(MessageContext.TRANSPORT_OUT, socket.getOutputStream());
+            AxisEngine.receive(msgContext);
 
-                    MessageContext faultContext =
-                            MessageContextBuilder.createFaultMessageContext(msgContext, e);
+        } catch (Exception e) {
+            sendFault(msgContext, e);
 
-                    AxisEngine.sendFault(faultContext);
-                }
-            } catch (Exception e1) {
-                log.error(e1.getMessage(), e1);
-            }
         } finally {
-            if (socket != null) {
-                try {
-                    this.socket.close();
-                } catch (IOException e1) {
-                    // Do nothing
-                }
+            try {
+                socket.close();
+            } catch (IOException e) {
+                log.error("Error while closing a TCP socket", e);
+            }
+        }
+    }
+
+    private void sendFault(MessageContext msgContext, Exception fault) {
+        log.error("Error while processing TCP request through the Axis2 engine", fault);
+        try {
+            if (msgContext != null) {
+                msgContext.setProperty(MessageContext.TRANSPORT_OUT, socket.getOutputStream());
+
+                MessageContext faultContext =
+                        MessageContextBuilder.createFaultMessageContext(msgContext, fault);
+
+                AxisEngine.sendFault(faultContext);
             }
+        } catch (Exception e) {
+            log.error("Error while sending the fault response", e);
         }
     }
 }

Modified: axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/TCPEchoRawXMLTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/TCPEchoRawXMLTest.java?rev=950232&r1=950231&r2=950232&view=diff
==============================================================================
--- axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/TCPEchoRawXMLTest.java (original)
+++ axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/TCPEchoRawXMLTest.java Tue Jun  1 20:04:25 2010
@@ -42,6 +42,7 @@ import org.apache.axis2.context.MessageC
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.OutInAxisOperation;
+import org.apache.axis2.description.Parameter;
 import org.apache.axis2.util.Utils;
 import org.apache.axis2.wsdl.WSDLConstants;
 import org.apache.commons.logging.Log;
@@ -90,6 +91,7 @@ public class TCPEchoRawXMLTest extends T
 
     protected void tearDown() throws Exception {
         UtilsTCPServer.stop();
+        configContext.getListenerManager().destroy();
     }
 
     private OMElement createPayload() {
@@ -188,10 +190,7 @@ public class TCPEchoRawXMLTest extends T
 
     }
 
-    public void testEchoXMLSyncMC() throws Exception {
-        ConfigurationContext configContext =
-                ConfigurationContextFactory.createConfigurationContextFromFileSystem(Constants.TESTING_REPOSITORY, Constants.TESTING_REPOSITORY + "/conf/axis2.xml");
-
+    public void testEchoXMLSyncMC() throws Exception {        
         AxisOperation opdesc = new OutInAxisOperation(new QName("echoOMElement"));
         Options options = new Options();
         options.setTo(targetEPR);

Modified: axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/TCPTwoChannelEchoRawXMLTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/TCPTwoChannelEchoRawXMLTest.java?rev=950232&r1=950231&r2=950232&view=diff
==============================================================================
--- axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/TCPTwoChannelEchoRawXMLTest.java (original)
+++ axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/TCPTwoChannelEchoRawXMLTest.java Tue Jun  1 20:04:25 2010
@@ -79,6 +79,7 @@ public class TCPTwoChannelEchoRawXMLTest
 
     protected void tearDown() throws Exception {
         UtilsTCPServer.stop();
+        configContext.getListenerManager().destroy();
     }
 
     public void testEchoXMLCompleteASync() throws Exception {

Modified: axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/UtilsTCPServer.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/UtilsTCPServer.java?rev=950232&r1=950231&r2=950232&view=diff
==============================================================================
--- axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/UtilsTCPServer.java (original)
+++ axis/axis2/java/transports/trunk/modules/tcp/test/org/apache/axis2/transport/tcp/UtilsTCPServer.java Tue Jun  1 20:04:25 2010
@@ -24,7 +24,6 @@ import org.apache.axis2.Constants;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.axis2.description.AxisService;
-import org.apache.axis2.transport.tcp.TCPServer;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -35,7 +34,7 @@ import java.io.File;
 public class UtilsTCPServer {
     private static int count = 0;
 
-    private static TCPServer receiver;
+    private static TCPTransportListener receiver;
 
     public static final int TESTING_PORT = 5555;
 
@@ -66,16 +65,16 @@ public class UtilsTCPServer {
                 throw new Exception("Repository directory does not exist");
             }
             ConfigurationContext er =
-                ConfigurationContextFactory.createConfigurationContextFromFileSystem(file.getAbsolutePath(), 
-                                                                                     file.getAbsolutePath() + "/conf/axis2.xml");
+                ConfigurationContextFactory.createConfigurationContextFromFileSystem(
+                        file.getAbsolutePath(), file.getAbsolutePath() + "/conf/axis2.xml");
             try {
                 Thread.sleep(1000);
             } catch (InterruptedException e1) {
                 throw new AxisFault("Thread interuptted", e1);
             }
-            receiver = new TCPServer(TESTING_PORT, er);
+            receiver = new TCPTransportListener();
+            receiver.init(er, er.getAxisConfiguration().getTransportIn(Constants.TRANSPORT_TCP));
             receiver.start();
-
         }
         count++;
     }
@@ -84,6 +83,7 @@ public class UtilsTCPServer {
         try {
             if (count == 1) {
                 receiver.stop();
+                receiver.destroy();
                 count = 0;
                 System.out.print("Server stopped .....");
             } else {
@@ -98,8 +98,8 @@ public class UtilsTCPServer {
     public static ConfigurationContext createClientConfigurationContext() throws Exception {
         File file = new File(prefixBaseDirectory(Constants.TESTING_REPOSITORY));
         ConfigurationContext configContext = 
-            ConfigurationContextFactory.createConfigurationContextFromFileSystem(file.getAbsolutePath(), 
-                                                                                 file.getAbsolutePath() + "/conf/axis2.xml");
+            ConfigurationContextFactory.createConfigurationContextFromFileSystem(
+                    file.getAbsolutePath(), file.getAbsolutePath() + "/conf/client_axis2.xml");
         return configContext;
     }
 

Modified: axis/axis2/java/transports/trunk/src/site/apt/tcp-transport.apt
URL: http://svn.apache.org/viewvc/axis/axis2/java/transports/trunk/src/site/apt/tcp-transport.apt?rev=950232&r1=950231&r2=950232&view=diff
==============================================================================
--- axis/axis2/java/transports/trunk/src/site/apt/tcp-transport.apt (original)
+++ axis/axis2/java/transports/trunk/src/site/apt/tcp-transport.apt Tue Jun  1 20:04:25 2010
@@ -17,102 +17,134 @@
 
 TCP Transport
 
-  This document explains how to send and receive SOAP messages via TCP in Axis2.
-
 * {Content}
 
 %{toc|section=1|fromDepth=1}
 
-* {Introduction}
+* {Transport listener}
+
+** {Listener configuration}
+
+  The TCP transport listener is configured in <<<axis2.xml>>> using the following declaration:
+
++----------------------------+
+<transportReceiver name="tcp" class="org.apache.axis2.transport.tcp.TCPTransportListener"/>
++----------------------------+
+
+  Depending on how the TCP transport is set up, additional parameters may be required inside the
+  <<<transportReceiver>>> element (see next section).
+
+** {Endpoint configuration}
+
+  Endpoints can be configured both at the transport level and at the service level. Each endpoint
+  opens a TCP server socket for listening. TCP requests received on a port that is configured on a
+  service will be pre-dispatched to that service. Packets received by a port that is configured
+  at the transport level need to be dispatched using one of the following mechanisms:
 
-  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:
-  
-  [[1]] Use the name space URI of the first child element of SOAPBody.
-    (SOAPMessageBodyBasedDispatcher).
-  
-  [[2]] Enable WS-Addressing. In the case of version 1.1 and 1.1.1 releases
-    Addressing is default (SOAPActionBasedDispatcher).
-
-  []
-  
-  When the TCP request is sent, it is the user's responsibility to use
-  either Addressing or the 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 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.
+  [[1]] Using the namespace URI of the first child element of SOAPBody
+  (SOAPMessageBodyBasedDispatcher).
 
-* {How to Send SOAP Messages Using TCP Transport}
+  [[2]] Using WS-Addressing headers (SOAPActionBasedDispatcher).
 
-  TCP transport can be enabled easily from the call API. The following code
-  segment demonstrates how this can be done.
+  Endpoints are configured by adding <<<parameter>>> elements to the <<<transportReceiver>>>
+  element in <<<axis2.xml>>> or to a <<<service>>> element in an <<<services.xml>>> file. The
+  set of parameters is the same for both scenarios:
+
+  [<<<transport.tcp.port>>> (required)]
+  The port number over which the TCP server socket should be opened.
+
+  [<<<transport.tcp.hostname>>> (optional)]
+  The hostname to which the TCP server socket should be bound.
+
+  [<<<transport.tcp.contentType>>> (optional, defaults to text/xml)]
+  Specifies the content type of the messages received on the endpoint.
+
+  [<<<transport.tcp.backlog>>> (optional, defaults to 50)]
+  The length of the backlog (queue) supported by the TCP server socket.
+
+* {Transport sender}
+
+  The TCP transport sender can be enabled in <<<axis2.xml>>> using the following declaration:
+
++----------------------------+
+<transportSender name="tcp" class="org.apache.axis2.transport.tcp.TCPTransportSender"/>
++----------------------------+
+
+* {Examples}
+
+** {Enabling TCP listener at the transport level}
+
+  The following declaration in <<<axis2.xml>>> initializes a TCP server socket on port 6060
+  and allows all services (for which TCP is in the list of exposed transports) to receive
+  messages over that port:
+
++----------------------------+
+<transportReceiver name="tcp" class="org.apache.axis2.transport.tcp.TCPTransportListener">
+  <parameter name="transport.tcp.port">6060</parameter>
+</transportReceiver>
++----------------------------+
+
+  For this to work, WS-Addressing must be enabled, and messages sent to port 6060 must
+  have the relevant WS-Addressing headers.
+
++----------------------------+
+<module ref="addressing"/>
++----------------------------+
+
+  With the configuration shown above, the TCP transport would generate bindings with the
+  following EPR:
+
++----------------------------+
+tcp://localhost:6060/services/Version?contentType=text/xml
++----------------------------+
+
+  Similar EPRs will be generated for services when the transport is configured at service
+  level.
+
+  The following example shows a message that can be sent to the Version service over TCP:
+
++----------------------------+
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
+                   xmlns:wsa="http://www.w3.org/2005/08/addressing">
+    <SOAP-ENV:Header>
+        <wsa:MessageID>1234</wsa:MessageID>
+        <wsa:To>tcp://localhost:6060/services/Version?contentType=text/xml</wsa:To>
+        <wsa:Action>urn:getVersion</wsa:Action>
+    </SOAP-ENV:Header>
+    <SOAP-ENV:Body>
+    </SOAP-ENV:Body>
+</SOAP-ENV:Envelope>
++----------------------------+
+
+  Axis2 client API can be used to easily send TCP requests to a remote service.
+  The following code snippet shows how to do that. The TCP transport sender
+  must be enabled in the <<axis2.xml>> in order for this to work.
 
 +------------------------------------------------------+
+
+String url = "tcp://localhost:6060/services/Version?contentType=text/xml";
 OMElement payload = ...
+
 ServiceClient serviceClient = new ServiceClient();
 Options options = new Options();
+EndpointReference targetEPR = new EndpointReference(url);
 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
+  The transport sender 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.
-
-* {Samples}
-
-  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.
-
-* {Transport Components}
-
-  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:
+  message has to be self contained in order to use Addressing.
+  The parameter is of the type OMElement, the XML representation of Axis2.
 
-+-------------------------------------------------------------------------------------+
-<transportSender name="tcp" class="org.apache.axis2.transport.tcp.TCPTransportSender"/>
-+-------------------------------------------------------------------------------------+
+  A TCP URL may contain an optional timeout value, as a query parameter, to
+  indicate how long (in milliseconds) the client should wait for a response.
+  Once this period has expired, the client TCP socket will timeout:
+
++----------------------------+
+tcp://localhost:6060/services/Version?contentType=text/xml&timeout=10000
++----------------------------+
 
-  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)
+  If the Axis2 client API is used to send a request to the above URL, the client
+  socket will timeout after waiting for 10 seconds, for the response.
\ No newline at end of file