You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by he...@apache.org on 2005/05/19 12:11:54 UTC

svn commit: r170904 - in /webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/tcp: ./ TCPServer.java TCPTransportSender.java

Author: hemapani
Date: Thu May 19 03:11:53 2005
New Revision: 170904

URL: http://svn.apache.org/viewcvs?rev=170904&view=rev
Log:
add initial code for tcp transport

Added:
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/tcp/
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/tcp/TCPServer.java
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/tcp/TCPTransportSender.java

Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/tcp/TCPServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/tcp/TCPServer.java?rev=170904&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/tcp/TCPServer.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/tcp/TCPServer.java Thu May 19 03:11:53 2005
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.axis.transport.tcp;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axis.Constants;
+import org.apache.axis.context.ConfigurationContext;
+import org.apache.axis.context.EngineContextFactory;
+import org.apache.axis.context.MessageContext;
+import org.apache.axis.deployment.DeploymentException;
+import org.apache.axis.description.TransportOutDescription;
+import org.apache.axis.engine.AxisEngine;
+import org.apache.axis.engine.AxisFault;
+import org.apache.axis.om.impl.llom.builder.StAXBuilder;
+import org.apache.axis.soap.SOAPEnvelope;
+import org.apache.axis.soap.impl.llom.builder.StAXSOAPModelBuilder;
+import org.apache.axis.transport.http.SimpleHTTPServer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Class HTTPTransportReceiver
+ */
+public class TCPServer implements Runnable {
+    private int port = 8000;
+    private ServerSocket serversocket;
+    private boolean started = false;
+    private ConfigurationContext configContext;
+
+    protected Log log = LogFactory.getLog(SimpleHTTPServer.class.getName());
+
+    public TCPServer(int port, String dir) throws AxisFault {
+        try {
+            EngineContextFactory erfac = new EngineContextFactory();
+            ConfigurationContext configContext = erfac.buildEngineContext(dir);
+            this.configContext = configContext;
+            serversocket = new ServerSocket(port);
+        } catch (DeploymentException e1) {
+            throw new AxisFault(e1);
+        } catch (IOException e1) {
+            throw new AxisFault(e1);
+        }
+    }
+
+    public TCPServer(int port, ConfigurationContext configContext) throws AxisFault {
+        try {
+            this.configContext = configContext;
+            serversocket = new ServerSocket(port);
+        } catch (IOException e1) {
+            throw new AxisFault(e1);
+        }
+    }
+
+    public void run() {
+        while (started) {
+            try {
+                Socket socket = null;
+                try {
+                    socket = serversocket.accept();
+                } catch (java.io.InterruptedIOException iie) {
+                } catch (Exception e) {
+                    log.debug(e);
+                    break;
+                }
+                
+                Writer out = new OutputStreamWriter(socket.getOutputStream());
+                Reader in = new InputStreamReader(socket.getInputStream());
+                TransportOutDescription transportOut =
+                    configContext.getEngineConfig().getTransportOut(
+                        new QName(Constants.TRANSPORT_HTTP));
+                MessageContext msgContext =
+                    new MessageContext(
+                        null,
+                        configContext.getEngineConfig().getTransportIn(
+                            new QName(Constants.TRANSPORT_HTTP)),
+                        transportOut,
+                        configContext);
+                msgContext.setServerSide(true);
+                
+                
+                AxisEngine engine = new AxisEngine(configContext);
+                try {
+                    XMLStreamReader xmlreader = XMLInputFactory.newInstance().createXMLStreamReader(in);
+                    StAXBuilder builder = new StAXSOAPModelBuilder(xmlreader);
+                    msgContext.setEnvelope((SOAPEnvelope) builder.getDocumentElement());
+                } catch (Exception e) {
+                    throw new AxisFault(e.getMessage(), e);
+                }
+                engine.receive(msgContext);
+            } catch (Throwable e) {
+                log.error(e);
+            } 
+        }
+    }
+
+    public synchronized void start() {
+        started = true;
+        Thread thread = new Thread(this);
+        thread.start();
+    }
+
+}

Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/tcp/TCPTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/tcp/TCPTransportSender.java?rev=170904&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/tcp/TCPTransportSender.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/tcp/TCPTransportSender.java Thu May 19 03:11:53 2005
@@ -0,0 +1,102 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.axis.transport.tcp;
+
+import org.apache.axis.addressing.EndpointReference;
+import org.apache.axis.context.MessageContext;
+import org.apache.axis.engine.AxisFault;
+import org.apache.axis.transport.AbstractTransportSender;
+
+import java.io.*;
+import java.net.*;
+
+/**
+ * Class HTTPTransportSender
+ */
+public class TCPTransportSender extends AbstractTransportSender {
+    /**
+     * Field out
+     */
+    protected Writer out;
+
+    /**
+     * Field socket
+     */
+    private Socket socket;
+    private ByteArrayOutputStream outputStream;
+
+    /**
+     * Method writeTransportHeaders
+     *
+     * @param out
+     * @param url
+     * @param msgContext
+     * @throws IOException
+     */
+    protected void writeTransportHeaders(
+        Writer out,
+        URL url,
+        MessageContext msgContext,
+        int contentLength)
+        throws IOException {
+        //TCP no headers   :)
+    }
+
+    public void finalizeSendWithOutputStreamFromIncomingConnection(
+        MessageContext msgContext,
+        Writer writer) {
+        throw new UnsupportedOperationException();
+    }
+
+    public void finalizeSendWithToAddress(MessageContext msgContext, Writer writer)
+        throws AxisFault {
+        try {
+            socket.close();
+        } catch (IOException e) {
+            throw new AxisFault(e);
+        }
+    }
+
+    protected Writer openTheConnection(EndpointReference toURL) 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 new OutputStreamWriter(socket.getOutputStream());
+            } catch (MalformedURLException e) {
+                throw new AxisFault(e.getMessage(), e);
+            } catch (IOException e) {
+                throw new AxisFault(e.getMessage(), e);
+            }
+        } else {
+            throw new AxisFault("to EPR must be specified");
+        }
+    }
+
+    public void startSendWithOutputStreamFromIncomingConnection(
+        MessageContext msgContext,
+        Writer writer)
+        throws AxisFault {
+        throw new UnsupportedOperationException();
+    }
+
+    public void startSendWithToAddress(MessageContext msgContext, Writer writer) {
+    }
+
+}