ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r154537 [5/6] - in webservices/axis/trunk/java/modules: core/src/java/org/apache/axis/ core/src/java/org/apache/axis/addressing/ core/src/java/org/apache/axis/addressing/miheaders/ core/src/java/org/apache/axis/addressing/om/ core/src/java/org/apache/axis/clientapi/ core/src/java/org/apache/axis/context/ core/src/java/org/apache/axis/description/ core/src/java/org/apache/axis/engine/ core/src/java/org/apache/axis/handlers/ core/src/java/org/apache/axis/phaseresolver/ core/src/java/org/apache/axis/providers/ core/src/java/org/apache/axis/receivers/ core/src/java/org/apache/axis/transport/ core/src/java/org/apache/axis/transport/http/ core/src/java/org/apache/axis/util/ deployment/src/samples/deployment/service1/org/apache/axis/sample/echo/ samples/src/java/encoding/sample1/ samples/src/java/encoding/sample2/benchMark/ samples/src/java/org/apache/axis/testUtils/
Date Sun, 20 Feb 2005 17:57:03 GMT
Modified: webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/transport/http/HTTPTransportReceiver.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/transport/http/HTTPTransportReceiver.java?view=diff&r1=154536&r2=154537
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/transport/http/HTTPTransportReceiver.java
(original)
+++ webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/transport/http/HTTPTransportReceiver.java
Sun Feb 20 09:56:49 2005
@@ -1,12 +1,12 @@
 /*
  * 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.
@@ -33,18 +33,61 @@
 import java.util.HashMap;
 import java.util.Map;
 
+/**
+ * Class HTTPTransportReceiver
+ */
 public class HTTPTransportReceiver extends TransportReceiver {
+    /**
+     * Field END
+     */
     private static final int END = 1;
+
+    /**
+     * Field END_OF_LINE
+     */
     private static final int END_OF_LINE = 2;
+
+    /**
+     * Field BEFORE_SEPERATOR
+     */
     private static final int BEFORE_SEPERATOR = 3;
+
+    /**
+     * Field AFTER_SEPERATOR
+     */
     private static final int AFTER_SEPERATOR = 4;
+
+    /**
+     * Field lastRead
+     */
     private int lastRead = -1;
 
+    /**
+     * Field buf
+     */
     private char[] buf = new char[1024];
+
+    /**
+     * Field index
+     */
     int index = 0;
+
+    /**
+     * Field length
+     */
     int length = 0;
+
+    /**
+     * Field done
+     */
     private boolean done = false;
 
+    /**
+     * Method invoke
+     *
+     * @param msgContext
+     * @throws AxisFault
+     */
     public void invoke(MessageContext msgContext) throws AxisFault {
         Reader in =
                 (Reader) msgContext.getProperty(MessageContext.TRANSPORT_READER);
@@ -52,19 +95,25 @@
             boolean serverSide = msgContext.isServerSide();
             Map map = parseTheHeaders(in, serverSide);
             if (serverSide) {
-                msgContext.setProperty(MessageContext.SOAP_ACTION,
+                msgContext.setProperty(
+                        MessageContext.SOAP_ACTION,
                         map.get(HTTPConstants.HEADER_SOAP_ACTION));
-                msgContext.setTo(new EndpointReference(AddressingConstants.WSA_TO,
+                msgContext.setTo(
+                        new EndpointReference(
+                                AddressingConstants.WSA_TO,
                                 (String) map.get(HTTPConstants.REQUEST_URI)));
-                //TODO see is it a Service request e.g. WSDL, list ....
-                //              TODO take care of the other HTTPHeaders
 
+                // TODO see is it a Service request e.g. WSDL, list ....
+                // TODO take care of the other HTTPHeaders
             } else {
-                if (HTTPConstants.RESPONSE_ACK_CODE_VAL.equals(map.get(HTTPConstants.RESPONSE_CODE)))
{
-                    msgContext.setProperty(MessageContext.TRANSPORT_SUCCEED, HTTPConstants.RESPONSE_ACK_CODE_VAL);
+                if (HTTPConstants.RESPONSE_ACK_CODE_VAL.equals(
+                        map.get(HTTPConstants.RESPONSE_CODE))) {
+                    msgContext.setProperty(MessageContext.TRANSPORT_SUCCEED,
+                            HTTPConstants.RESPONSE_ACK_CODE_VAL);
                     return;
                 }
-                //TODO take care of other HTTP Headers
+
+                // TODO take care of other HTTP Headers
             }
             AxisEngine axisEngine =
             new AxisEngine(msgContext.getGlobalContext().getRegistry());
@@ -74,7 +123,8 @@
                 StAXBuilder builder =
                 new StAXSOAPModelBuilder(OMFactory.newInstance(),
                         xmlreader);
-                msgContext.setEnvelope((SOAPEnvelope) builder.getDocumentElement());
+                msgContext.setEnvelope(
+                        (SOAPEnvelope) builder.getDocumentElement());
             } catch (Exception e) {
                 throw new AxisFault(e.getMessage(), e);
             }
@@ -82,7 +132,6 @@
         } else {
             throw new AxisFault("Input reader not found");
         }
-
     }
 
     /**
@@ -90,7 +139,7 @@
      * Server Side
      * POST /axis2/services/echo HTTP/1.0
      * Content-Type: text/xml; charset=utf-8
-     * Accept: application/soap+xml, application/dime, multipart/related, text/*
+     * Accept: application/soap+xml, application/dime, multipart/related, text
      * User-Agent: Axis/1.2RC1
      * Host: 127.0.0.1:8081
      * Cache-Control: no-cache
@@ -104,7 +153,9 @@
      * Connection: close
      *
      * @param reader
+     * @param serverSide
      * @return
+     * @throws AxisFault
      */
     public HashMap parseTheHeaders(Reader reader, boolean serverSide)
             throws AxisFault {
@@ -117,10 +168,8 @@
             int start = 0;
             length = readLine(reader, buf);
             if (serverSide) {
-                if (buf[0] == 'P'
-                        && buf[1] == 'O'
-                        && buf[2] == 'S'
-                        && buf[3] == 'T') {
+                if ((buf[0] == 'P') && (buf[1] == 'O') && (buf[2] == 'S')
+                        && (buf[3] == 'T')) {
                     index = 5;
                     value = readFirstLineArg(' ');
                     map.put(HTTPConstants.REQUEST_URI, value);
@@ -152,7 +201,7 @@
                                 str = new StringBuffer();
                                 state = AFTER_SEPERATOR;
                                 if (buf[i + 1] == ' ') {
-                                    i++; //ignore next space
+                                    i++;    // ignore next space
                                 }
                             } else {
                                 str.append(buf[i]);
@@ -168,24 +217,24 @@
                                 str.append(buf[i]);
                             }
                             break;
-                            //                            case END_OF_LINE :
-                            //                                if (buf[i] == '\n') {
-                            //                                    state = END;
-                            //                                    break;
-                            //                                } else {
-                            //                                    state = BEFORE_SEPERATOR;
-                            //                                    str.append(buf[i]);
-                            //                                }
-                            //                                break;
-                            //                            case END:
-                            //                            break;    
-                            default :
-                            throw new AxisFault("Error Occured Unknown state " + state);
 
+                            // case END_OF_LINE :
+                            // if (buf[i] == '\n') {
+                            // state = END;
+                            // break;
+                            // } else {
+                            // state = BEFORE_SEPERATOR;
+                            // str.append(buf[i]);
+                            // }
+                            // break;
+                            // case END:
+                            // break;
+                            default :
+                            throw new AxisFault("Error Occured Unknown state "
+                                            + state);
                     }
                 }
                 state = BEFORE_SEPERATOR;
-
             }
         } catch (IOException e) {
             throw new AxisFault(e.getMessage(), e);
@@ -193,113 +242,121 @@
         return map;
     }
 
-    //    public HashMap parseTheHeaders(Reader reader, boolean serverSide)
-    //        throws AxisFault {
-    //        HashMap map = new HashMap();
-    //        try {
-    //    
-    //            StringBuffer str = new StringBuffer();
-    //    
-    //            int state = BEFORE_SEPERATOR;
-    //    
-    //            String key = null;
-    //            String value = null;
-    //    
-    //            int start = 0;
-    //    
-    //            length = readLine(reader,buf);
-    //                
-    //                
-    //                
-    //            if (serverSide) {
-    //                if (buf[0] == 'P'
-    //                    && buf[1] == 'O'
-    //                    && buf[2] == 'S'
-    //                    && buf[3] == 'T') {
-    //                    index = 5;
-    //                    value = readFirstLineArg(' ');
-    //                    map.put(HTTPConstants.REQUEST_URI,value );
-    //                    value = readFirstLineArg('\n');
-    //                    map.put(
-    //                        HTTPConstants.PROTOCOL_VERSION,value);
-    //                    start = index;
-    //                } else {
-    //                    throw new AxisFault("Only the POST requests are supported");
-    //                }
-    //            } else {
-    //                index = 0;
-    //                value = readFirstLineArg(' ');
-    //                map.put(HTTPConstants.PROTOCOL_VERSION, value);
-    //                value = readFirstLineArg(' ');
-    //                map.put(HTTPConstants.RESPONSE_CODE,value);
-    //                value = readFirstLineArg('\n');
-    //                map.put(HTTPConstants.RESPONSE_WORD, value);
-    //                start = index;
-    //            }
-    //    
-    //            while (state != END) {
-    //                if(length <= 0){
-    //                    throw new AxisFault("Premature end of steam");
-    //                }
-    //                for (int i = start; i < length; i++) {
-    //                    System.out.println(state);
-    //                    switch (state) {
-    //                        case BEFORE_SEPERATOR :
-    //                            if (buf[i] == ':') {
-    //                                key = str.toString();
-    //                                str = new StringBuffer();
-    //                                state = AFTER_SEPERATOR;
-    //                                    
-    //                                if(buf[i+1] == ' '){
-    //                                    i++;//ignore next space
-    //                                }
-    //                            } else {
-    //                                str.append(buf[i]);
-    //                            }
-    //                            break;
-    //                        case AFTER_SEPERATOR :
-    //                            if (buf[i] == '\n') {
-    //                                value = str.toString();
-    //                                map.put(key, value);
-    //                                str = new StringBuffer();
-    //                                state = END_OF_LINE;
-    //                            } else {
-    //                                str.append(buf[i]);
-    //                            }
-    //                            break;
-    //                        case END_OF_LINE :
-    //                            if (buf[i] == '\n') {
-    //                                state = END;
-    //                                break;
-    //                            } else {
-    //                                state = BEFORE_SEPERATOR;
-    //                                str.append(buf[i]);
-    //                            }
-    //                            break;
-    //                        case END:
-    //                        break;    
-    //                        default :
-    //                            throw new AxisFault(
-    //                                "Error Occured Unknown state " + state);
-    //    
-    //                    }
-    //                }
-    //                start = 0;
-    //                if(state != END){
-    //                    length = reader.read(buf);
-    //                }
-    //                    
-    //    
-    //            }
-    //        } catch (IOException e) {
-    //            throw new AxisFault(e.getMessage(), e);
-    //        }
-    //        return map;
-    //    }
+    // public HashMap parseTheHeaders(Reader reader, boolean serverSide)
+    // throws AxisFault {
+    // HashMap map = new HashMap();
+    // try {
+    // 
+    // StringBuffer str = new StringBuffer();
+    // 
+    // int state = BEFORE_SEPERATOR;
+    // 
+    // String key = null;
+    // String value = null;
+    // 
+    // int start = 0;
+    // 
+    // length = readLine(reader,buf);
+    // 
+    // 
+    // 
+    // if (serverSide) {
+    // if (buf[0] == 'P'
+    // && buf[1] == 'O'
+    // && buf[2] == 'S'
+    // && buf[3] == 'T') {
+    // index = 5;
+    // value = readFirstLineArg(' ');
+    // map.put(HTTPConstants.REQUEST_URI,value );
+    // value = readFirstLineArg('\n');
+    // map.put(
+    // HTTPConstants.PROTOCOL_VERSION,value);
+    // start = index;
+    // } else {
+    // throw new AxisFault("Only the POST requests are supported");
+    // }
+    // } else {
+    // index = 0;
+    // value = readFirstLineArg(' ');
+    // map.put(HTTPConstants.PROTOCOL_VERSION, value);
+    // value = readFirstLineArg(' ');
+    // map.put(HTTPConstants.RESPONSE_CODE,value);
+    // value = readFirstLineArg('\n');
+    // map.put(HTTPConstants.RESPONSE_WORD, value);
+    // start = index;
+    // }
+    // 
+    // while (state != END) {
+    // if(length <= 0){
+    // throw new AxisFault("Premature end of steam");
+    // }
+    // for (int i = start; i < length; i++) {
+    // System.out.println(state);
+    // switch (state) {
+    // case BEFORE_SEPERATOR :
+    // if (buf[i] == ':') {
+    // key = str.toString();
+    // str = new StringBuffer();
+    // state = AFTER_SEPERATOR;
+    // 
+    // if(buf[i+1] == ' '){
+    // i++;//ignore next space
+    // }
+    // } else {
+    // str.append(buf[i]);
+    // }
+    // break;
+    // case AFTER_SEPERATOR :
+    // if (buf[i] == '\n') {
+    // value = str.toString();
+    // map.put(key, value);
+    // str = new StringBuffer();
+    // state = END_OF_LINE;
+    // } else {
+    // str.append(buf[i]);
+    // }
+    // break;
+    // case END_OF_LINE :
+    // if (buf[i] == '\n') {
+    // state = END;
+    // break;
+    // } else {
+    // state = BEFORE_SEPERATOR;
+    // str.append(buf[i]);
+    // }
+    // break;
+    // case END:
+    // break;
+    // default :
+    // throw new AxisFault(
+    // "Error Occured Unknown state " + state);
+    // 
+    // }
+    // }
+    // start = 0;
+    // if(state != END){
+    // length = reader.read(buf);
+    // }
+    // 
+    // 
+    // }
+    // } catch (IOException e) {
+    // throw new AxisFault(e.getMessage(), e);
+    // }
+    // return map;
+    // }
+
+    /**
+     * Method readFirstLineArg
+     *
+     * @param terminal
+     * @return
+     * @throws AxisFault
+     */
     private String readFirstLineArg(char terminal) throws AxisFault {
         StringBuffer str = new StringBuffer();
         try {
-            while (buf[index] != terminal && index < length) {
+            while ((buf[index] != terminal) && (index < length)) {
                 str.append(buf[index]);
                 index++;
             }
@@ -308,17 +365,18 @@
         } catch (Exception e) {
             throw new AxisFault(e.getMessage(), e);
         }
-
     }
 
     /**
-     * Read a single line from the input stream
-     *
-     * @param is  inputstream to read from
-     * @param b   byte array to read into
-     * @param off starting offset into the byte array
-     * @param len maximum number of bytes to read
-     */
+         * Read a single line from the input stream
+         *
+         * @param is  inputstream to read from
+         * @param b   byte array to read into
+         * @param off starting offset into the byte array
+         * @param len maximum number of bytes to read
+         * @return
+         * @throws java.io.IOException
+         */
     protected int readLine(Reader is, char[] b) throws java.io.IOException {
         int count = 0, c;
 
@@ -330,7 +388,7 @@
         }
         int off = 0;
         while (c != -1) {
-            if (c != '\n' && c != '\r') {
+            if ((c != '\n') && (c != '\r')) {
                 b[off++] = (char) c;
                 count++;
                 c = is.read();
@@ -340,8 +398,9 @@
                     if (c == '\r') {
                         c = is.read();
                     }
-                    //If the next line begins with tab or space then this is a continuation.
-                    if (c != ' ' && c != '\t') {
+
+                    // If the next line begins with tab or space then this is a continuation.
+                    if ((c != ' ') && (c != '\t')) {
                         if (c == '\n') {
                             done = true;
                         }
@@ -350,20 +409,18 @@
                         count++;
                         break;
                     }
-
                 } else {
                     c = is.read();
                 }
             }
-
-
         }
         if (c == -1) {
-            throw new AxisFault("Every line should ends with the \n, unexpected End of stream");
+            throw new AxisFault(
+                    "Every line should ends with the \n, unexpected End of stream");
         } else {
-            return count > 0 ? count : -1;
+            return (count > 0)
+                    ? count
+                    : -1;
         }
-
     }
-
 }

Modified: webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/transport/http/HTTPTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/transport/http/HTTPTransportSender.java?view=diff&r1=154536&r2=154537
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/transport/http/HTTPTransportSender.java
(original)
+++ webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/transport/http/HTTPTransportSender.java
Sun Feb 20 09:56:49 2005
@@ -1,12 +1,12 @@
 /*
  * 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.
@@ -32,10 +32,27 @@
 import java.net.SocketAddress;
 import java.net.URL;
 
+/**
+ * Class HTTPTransportSender
+ */
 public class HTTPTransportSender extends AbstractTransportSender {
+    /**
+     * Field out
+     */
     protected Writer out;
+
+    /**
+     * Field socket
+     */
     private Socket socket;
 
+    /**
+     * Method obtainOutputStream
+     *
+     * @param msgContext
+     * @return
+     * @throws AxisFault
+     */
     protected Writer obtainOutputStream(MessageContext msgContext)
             throws AxisFault {
         if (!msgContext.isServerSide()) {
@@ -43,54 +60,86 @@
             if (toURL != null) {
                 try {
                     URL url = new URL(toURL.getAddress());
-                    SocketAddress add = new InetSocketAddress(url.getHost(), url.getPort());
+                    SocketAddress add = new InetSocketAddress(url.getHost(),
+                            url.getPort());
                     socket = new Socket();
                     socket.connect(add);
                     outS = socket.getOutputStream();
                     out = new BufferedWriter(new OutputStreamWriter(outS));
                     writeTransportHeaders(out, url);
-                    msgContext.setProperty(MessageContext.TRANSPORT_READER, new BufferedReader(new
InputStreamReader(socket.getInputStream())));
+                    msgContext.setProperty(
+                            MessageContext.TRANSPORT_READER,
+                            new BufferedReader(
+                                    new InputStreamReader(socket.getInputStream())));
                     msgContext.setProperty(HTTPConstants.SOCKET, socket);
                 } 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");
             }
-
         } else {
-            out =
-            (Writer) msgContext.getProperty(MessageContext.TRANSPORT_WRITER);
+            out = (Writer) msgContext.getProperty(
+                    MessageContext.TRANSPORT_WRITER);
         }
         if (out == null) {
-            throw new AxisFault("can not find the suffient information to find endpoint");
+            throw new AxisFault(
+                    "can not find the suffient information to find endpoint");
         } else {
             return out;
         }
-
     }
 
-    protected Writer obtainOutputStream(MessageContext msgContext,
-                                        EndpointReference epr)
-            throws AxisFault {
-        //TODO this is temporay work around
+    /**
+     * Method obtainOutputStream
+     *
+     * @param msgContext
+     * @param epr
+     * @return
+     * @throws AxisFault
+     */
+    protected Writer obtainOutputStream(
+            MessageContext msgContext, EndpointReference epr) throws AxisFault {
+
+        // TODO this is temporay work around
         return obtainOutputStream(msgContext);
     }
 
-    protected void finalizeSending(MessageContext msgContext) throws AxisFault {
+    /**
+     * Method finalizeSending
+     *
+     * @param msgContext
+     * @throws AxisFault
+     */
+    protected void finalizeSending(MessageContext msgContext)
+            throws AxisFault {
     }
 
+    /**
+     * Method startSending
+     *
+     * @param msgContext
+     * @throws AxisFault
+     */
     protected void startSending(MessageContext msgContext) throws AxisFault {
     }
 
-    protected void writeTransportHeaders(Writer out, URL url) throws IOException {
+    /**
+         * Method writeTransportHeaders
+         *
+         * @param out
+         * @param url
+         * @throws IOException
+         */
+    protected void writeTransportHeaders(Writer out, URL url)
+            throws IOException {
         StringBuffer buf = new StringBuffer();
         buf.append("POST ").append(url.getFile()).append(" HTTP/1.0\n");
         buf.append("Content-Type: text/xml; charset=utf-8\n");
-        buf.append("Accept: application/soap+xml, application/dime, multipart/related, text/*\n");
+        buf.append(
+                "Accept: application/soap+xml, application/dime, multipart/related, text/*\n");
         buf.append("Host: ").append(url.getHost()).append("\n");
         buf.append("Cache-Control: no-cache\n");
         buf.append("Pragma: no-cache\n");

Modified: webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/transport/http/SimpleHTTPServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/transport/http/SimpleHTTPServer.java?view=diff&r1=154536&r2=154537
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/transport/http/SimpleHTTPServer.java
(original)
+++ webservices/axis/trunk/java/modules/core/src/java/org/apache/axis/transport/http/SimpleHTTPServer.java
Sun Feb 20 09:56:49 2005
@@ -1,225 +1,270 @@
-/*
- * 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.http;
-
-import org.apache.axis.Constants;
-import org.apache.axis.context.MessageContext;
-import org.apache.axis.engine.AxisFault;
-import org.apache.axis.engine.EngineRegistry;
-import org.apache.axis.engine.EngineRegistryFactory;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-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;
-
-/**
- * This is a simple implementation of an HTTP server for processing
- * SOAP requests via Apache's xml-axis.  This is not intended for production
- * use.  Its intended uses are for demos, debugging, and performance
- * profiling.
- * Note this classes uses static objects to provide a thread pool, so you should
- * not use multiple instances of this class in the same JVM/classloader unless
- * you want bad things to happen at shutdown.
- */
-public class SimpleHTTPServer implements Runnable {
-    protected Log log = LogFactory.getLog(SimpleHTTPServer.class.getName());
-    protected EngineRegistry engineReg;
-    protected ServerSocket serverSocket;
-    protected Socket socket;
-    /**
-     * are we stopped?
-     * latch to true if stop() is called
-     */
-    private boolean stopped = false;
-
-    public SimpleHTTPServer(EngineRegistry reg) {
-        this.engineReg = reg;
-
-    }
-
-    public SimpleHTTPServer(String dir) throws AxisFault {
-        try {
-            Class erClass = Class.forName("org.apache.axis.deployment.EngineRegistryFactoryImpl");
-            EngineRegistryFactory erfac = (EngineRegistryFactory) erClass.newInstance();
-            this.engineReg = erfac.createEngineRegistry(dir);
-            Thread.sleep(2000);
-        } catch (Exception e1) {
-            throw new AxisFault("Thread interuptted", e1);
-        }
-    }
-
-    /**
-     * stop the server if not already told to.
-     *
-     * @throws Throwable
-     */
-    protected void finalize() throws Throwable {
-        stop();
-        super.finalize();
-    }
-
-    /**
-     * Accept requests from a given TCP port and send them through the
-     * Axis engine for processing.
-     */
-    public void run() {
-        try {
-            while (!stopped) {
-                try {
-                    // Accept and process requests from the socket
-
-                    try {
-                        socket = serverSocket.accept();
-                    } catch (java.io.InterruptedIOException iie) {
-                    } catch (Exception e) {
-                        log.debug(e);
-                        break;
-                    }
-                    if (socket != null) {
-                        if (engineReg == null) {
-                            throw new AxisFault("Engine Must be null");
-                        }
-                        Writer out =
-                        new OutputStreamWriter(socket.getOutputStream());
-                        Reader in =
-                        new InputStreamReader(socket.getInputStream());
-                        MessageContext msgContext =
-                        new MessageContext(this.engineReg, null, null);
-                        msgContext.setServerSide(true);
-                        out.write(HTTPConstants.HTTP);
-                        out.write(HTTPConstants.OK);
-                        out.write("\n\n".toCharArray());
-                        log.info("status written");
-                        //We do not have any Addressing Headers to put
-                        //let us put the information about incoming transport
-                        msgContext.setProperty(MessageContext.TRANSPORT_TYPE,
-                                Constants.TRANSPORT_HTTP);
-                        msgContext.setProperty(MessageContext.TRANSPORT_WRITER,
-                                out);
-                        msgContext.setProperty(MessageContext.TRANSPORT_READER,
-                                in);
-                        HTTPTransportReceiver reciver =
-                        new HTTPTransportReceiver();
-                        reciver.invoke(msgContext);
-
-                    }
-                } catch (Throwable e) {
-                    log.error(e);
-                } finally {
-                    if (socket != null) {
-                        this.socket.close();
-                        this.socket = null;
-                    }
-                }
-            }
-
-        } catch (IOException e) {
-            log.error(e);
-        }
-        stop();
-        log.info("Simple Axis Server Quit");
-    }
-
-    /**
-     * Obtain the serverSocket that that SimpleAxisServer is listening on.
-     */
-    public ServerSocket getServerSocket() {
-        return serverSocket;
-    }
-
-    /**
-     * Set the serverSocket this server should listen on.
-     * (note : changing this will not affect a running server, but if you
-     * stop() and then start() the server, the new socket will be used).
-     */
-    public void setServerSocket(ServerSocket serverSocket) {
-        this.serverSocket = serverSocket;
-    }
-
-    /**
-     * Start this server as a NON-daemon.
-     */
-    public void start() throws Exception {
-        run();
-    }
-
-    /**
-     * Stop this server. Can be called safely if the system is already stopped,
-     * or if it was never started.
-     * This will interrupt any pending accept().
-     */
-    public void stop() {
-        log.info("stop called");
-        //recognise use before we are live
-        if (stopped) {
-            return;
-        }
-        /*
-         * Close the server socket cleanly, but avoid fresh accepts while
-         * the socket is closing.
-         */
-        stopped = true;
-        try {
-            if (serverSocket != null) {
-                serverSocket.close();
-                //                while(socket != null){
-                //                    try {
-                //                        //make sure all sockets closed by the time 
-                //                        //else we got in to lot of trouble testing
-                //                        Thread.sleep(1000);
-                //                    } catch (InterruptedException e1) {
-                //                        log.error(e1);
-                //                    }
-                //                }
-            }
-        } catch (IOException e) {
-            log.info(e);
-        } finally {
-            serverSocket = null;
-        }
-        log.info("Simple Axis Server Quits");
-    }
-
-    public EngineRegistry getEngineReg() {
-        return engineReg;
-    }
-
-    public static void main(String[] args) throws Exception {
-        if (args.length != 2) {
-            System.out.println("SimpeHttpReciver repositoryLocation port");
-        }
-        SimpleHTTPServer reciver = new SimpleHTTPServer(args[0]);
-        ServerSocket serverSoc = null;
-        serverSoc = new ServerSocket(Integer.parseInt(args[1]));
-        reciver.setServerSocket(serverSoc);
-        Thread thread = new Thread(reciver);
-        thread.setDaemon(true);
-        try {
-            thread.start();
-            System.in.read();
-        } finally {
-            reciver.stop();
-
-        }
-    }
-
-}
+/*
+ * 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.http;
+
+import org.apache.axis.Constants;
+import org.apache.axis.context.MessageContext;
+import org.apache.axis.engine.AxisFault;
+import org.apache.axis.engine.EngineRegistry;
+import org.apache.axis.engine.EngineRegistryFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+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;
+
+/**
+ * This is a simple implementation of an HTTP server for processing
+ * SOAP requests via Apache's xml-axis.  This is not intended for production
+ * use.  Its intended uses are for demos, debugging, and performance
+ * profiling.
+ * Note this classes uses static objects to provide a thread pool, so you should
+ * not use multiple instances of this class in the same JVM/classloader unless
+ * you want bad things to happen at shutdown.
+ */
+public class SimpleHTTPServer implements Runnable {
+    /**
+     * Field log
+     */
+    protected Log log = LogFactory.getLog(SimpleHTTPServer.class.getName());
+
+    /**
+     * Field engineReg
+     */
+    protected EngineRegistry engineReg;
+
+    /**
+     * Field serverSocket
+     */
+    protected ServerSocket serverSocket;
+
+    /**
+     * Field socket
+     */
+    protected Socket socket;
+
+    /**
+     * are we stopped?
+     * latch to true if stop() is called
+     */
+    private boolean stopped = false;
+
+    /**
+     * Constructor SimpleHTTPServer
+     *
+     * @param reg
+     */
+    public SimpleHTTPServer(EngineRegistry reg) {
+        this.engineReg = reg;
+    }
+
+    /**
+     * Constructor SimpleHTTPServer
+     *
+     * @param dir
+     * @throws AxisFault
+     */
+    public SimpleHTTPServer(String dir) throws AxisFault {
+        try {
+            Class erClass = Class.forName(
+                    "org.apache.axis.deployment.EngineRegistryFactoryImpl");
+            EngineRegistryFactory erfac =
+                    (EngineRegistryFactory) erClass.newInstance();
+            this.engineReg = erfac.createEngineRegistry(dir);
+            Thread.sleep(2000);
+        } catch (Exception e1) {
+            throw new AxisFault("Thread interuptted", e1);
+        }
+    }
+
+    /**
+     * stop the server if not already told to.
+     *
+     * @throws Throwable
+     */
+    protected void finalize() throws Throwable {
+        stop();
+        super.finalize();
+    }
+
+    /**
+     * Accept requests from a given TCP port and send them through the
+     * Axis engine for processing.
+     */
+    public void run() {
+        try {
+            while (!stopped) {
+                try {
+
+                    // Accept and process requests from the socket
+                    try {
+                        socket = serverSocket.accept();
+                    } catch (java.io.InterruptedIOException iie) {
+                    } catch (Exception e) {
+                        log.debug(e);
+                        break;
+                    }
+                    if (socket != null) {
+                        if (engineReg == null) {
+                            throw new AxisFault("Engine Must be null");
+                        }
+                        Writer out =
+                        new OutputStreamWriter(socket.getOutputStream());
+                        Reader in =
+                        new InputStreamReader(socket.getInputStream());
+                        MessageContext msgContext =
+                        new MessageContext(this.engineReg, null, null);
+                        msgContext.setServerSide(true);
+                        out.write(HTTPConstants.HTTP);
+                        out.write(HTTPConstants.OK);
+                        out.write("\n\n".toCharArray());
+                        log.info("status written");
+
+                        // We do not have any Addressing Headers to put
+                        // let us put the information about incoming transport
+                        msgContext.setProperty(MessageContext.TRANSPORT_TYPE,
+                                Constants.TRANSPORT_HTTP);
+                        msgContext.setProperty(MessageContext.TRANSPORT_WRITER,
+                                out);
+                        msgContext.setProperty(MessageContext.TRANSPORT_READER,
+                                in);
+                        HTTPTransportReceiver reciver =
+                        new HTTPTransportReceiver();
+                        reciver.invoke(msgContext);
+                    }
+                } catch (Throwable e) {
+                    log.error(e);
+                } finally {
+                    if (socket != null) {
+                        this.socket.close();
+                        this.socket = null;
+                    }
+                }
+            }
+        } catch (IOException e) {
+            log.error(e);
+        }
+        stop();
+        log.info("Simple Axis Server Quit");
+    }
+
+    /**
+     * Obtain the serverSocket that that SimpleAxisServer is listening on.
+     *
+     * @return
+     */
+    public ServerSocket getServerSocket() {
+        return serverSocket;
+    }
+
+    /**
+     * Set the serverSocket this server should listen on.
+     * (note : changing this will not affect a running server, but if you
+     * stop() and then start() the server, the new socket will be used).
+     *
+     * @param serverSocket
+     */
+    public void setServerSocket(ServerSocket serverSocket) {
+        this.serverSocket = serverSocket;
+    }
+
+    /**
+     * Start this server as a NON-daemon.
+     *
+     * @throws Exception
+     */
+    public void start() throws Exception {
+        run();
+    }
+
+    /**
+     * Stop this server. Can be called safely if the system is already stopped,
+     * or if it was never started.
+     * This will interrupt any pending accept().
+     */
+    public void stop() {
+        log.info("stop called");
+
+        // recognise use before we are live
+        if (stopped) {
+            return;
+        }
+
+        /*
+         * Close the server socket cleanly, but avoid fresh accepts while
+         * the socket is closing.
+         */
+        stopped = true;
+        try {
+            if (serverSocket != null) {
+                serverSocket.close();
+
+                // while(socket != null){
+                // try {
+                // //make sure all sockets closed by the time
+                // //else we got in to lot of trouble testing
+                // Thread.sleep(1000);
+                // } catch (InterruptedException e1) {
+                // log.error(e1);
+                // }
+                // }
+            }
+        } catch (IOException e) {
+            log.info(e);
+        } finally {
+            serverSocket = null;
+        }
+        log.info("Simple Axis Server Quits");
+    }
+
+    /**
+     * Method getEngineReg
+     *
+     * @return
+     */
+    public EngineRegistry getEngineReg() {
+        return engineReg;
+    }
+
+    /**
+     * Method main
+     *
+     * @param args
+     * @throws Exception
+     */
+    public static void main(String[] args) throws Exception {
+        if (args.length != 2) {
+            System.out.println("SimpeHttpReciver repositoryLocation port");
+        }
+        SimpleHTTPServer reciver = new SimpleHTTPServer(args[0]);
+        ServerSocket serverSoc = null;
+        serverSoc = new ServerSocket(Integer.parseInt(args[1]));
+        reciver.setServerSocket(serverSoc);
+        Thread thread = new Thread(reciver);
+        thread.setDaemon(true);
+        try {
+            thread.start();
+            System.in.read();
+        } finally {
+            reciver.stop();
+        }
+    }
+}



Mime
View raw message