You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2005/08/12 22:59:19 UTC

svn commit: r232392 [2/2] - in /webservices/axis/trunk/java/modules: core/src/org/apache/axis2/transport/http/ core/src/org/apache/axis2/transport/http/server/ integration/ integration/src/org/apache/axis2/soap12testing/server/ integration/test/org/apa...

Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,111 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimpleConnectionThread.java,v 1.3 2004/11/13 22:38:27 mbecke Exp $
+ * $Revision: 224451 $
+ * $Date: 2005-07-23 06:23:59 -0400 (Sat, 23 Jul 2005) $
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Simple HTTP connection thread.
+ * 
+ * @author Christian Kohlschuetter
+ * @author Oleg Kalnichevski
+ */
+public class SimpleConnectionThread extends Thread {
+
+    private static final Log LOG = LogFactory.getLog(SimpleConnectionThread.class);
+    
+    public static final String DEFAULT_CONTENT_CHARSET = "ISO-8859-1";
+
+    private SimpleHttpServerConnection conn = null;
+    private SimpleConnSet connpool = null;    
+    private HttpRequestHandler handler = null;
+    transient boolean stopped; 
+
+    public SimpleConnectionThread(
+            final ThreadGroup tg,
+            final String name,
+            final SimpleHttpServerConnection conn,
+            final SimpleConnSet connpool,
+            final HttpRequestHandler handler) 
+    throws IOException {
+        super(tg, name);
+        if (conn == null) {
+            throw new IllegalArgumentException("Connection may not be null");
+        }
+        if (connpool == null) {
+            throw new IllegalArgumentException("Connection pool not be null");
+        }
+        if (handler == null) {
+            throw new IllegalArgumentException("Request handler may not be null");
+        }
+        this.conn = conn;
+        this.connpool = connpool;
+        this.handler = handler;
+        this.stopped = false; 
+    }
+
+    public synchronized void destroy() {
+        if (this.stopped) {
+            return;
+        }
+        this.stopped = true; 
+        if (conn != null) {
+            conn.close();
+            conn = null;
+        }
+        interrupt();
+    }
+
+    public void run() {
+        try {
+            do {
+                this.conn.setKeepAlive(false);
+                SimpleRequest request = this.conn.readRequest();
+                if (request != null) {
+                    this.handler.processRequest(this.conn, request);
+                }
+            } while (this.conn.isKeepAlive());
+        } catch (InterruptedIOException e) {
+        } catch (IOException e) {
+            if (!this.stopped && !isInterrupted() && LOG.isWarnEnabled()) {
+                LOG.warn("[" + getName() + "] I/O error: " + e.getMessage());
+            }
+        } finally {
+            destroy();
+            this.connpool.removeConnection(this.conn);
+        }
+    }
+
+}
+    
\ No newline at end of file

Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHost.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHost.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHost.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHost.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,102 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimpleHost.java,v 1.1 2004/11/13 12:21:28 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ *  Copyright 2002-2004 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+/**
+ * @author Oleg Kalnichevski
+ */
+public class SimpleHost implements Cloneable {
+
+    private String hostname = null;
+
+    private int port = -1;
+
+    public SimpleHost(final String hostname, int port) {
+        super();
+        if (hostname == null) {
+            throw new IllegalArgumentException("Host name may not be null");
+        }
+        if (port < 0) {
+            throw new IllegalArgumentException("Port may not be negative");
+        }
+        this.hostname = hostname;
+        this.port = port;
+    }
+
+    public SimpleHost (final SimpleHost httphost) {
+        super();
+        this.hostname = httphost.hostname;
+        this.port = httphost.port;
+    }
+
+    public Object clone() {
+        return new SimpleHost(this);
+    }    
+    
+    public String getHostName() {
+        return this.hostname;
+    }
+
+    public int getPort() {
+        return this.port;
+    }
+
+    public String toString() {
+        StringBuffer buffer = new StringBuffer(50);        
+        buffer.append(this.hostname);
+        buffer.append(':');
+        buffer.append(this.port);
+        return buffer.toString();
+    }    
+    
+    public boolean equals(final Object o) {
+        
+        if (o instanceof SimpleHost) {
+            if (o == this) { 
+                return true;
+            }
+            SimpleHost that = (SimpleHost) o;
+            if (!this.hostname.equalsIgnoreCase(that.hostname)) {
+                return false;
+            }
+            if (this.port != that.port) {
+                return false;
+            }
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public int hashCode() {
+        return this.hostname.hashCode() + this.port;
+    }
+
+}

Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHost.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServer.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServer.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServer.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,229 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimpleHttpServer.java,v 1.15 2004/12/11 22:35:26 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A simple, but extensible HTTP server, mostly for testing purposes.
+ * 
+ * @author Christian Kohlschuetter
+ * @author Oleg Kalnichevski
+ */
+public class SimpleHttpServer implements Runnable {
+    private static final Log LOG = LogFactory.getLog(SimpleHttpServer.class);
+    
+    private String testname = "Simple test";
+    private long count = 0;
+    private ServerSocket listener = null;
+    private Thread t;
+    private ThreadGroup tg;
+    private boolean stopped = false;
+
+    private SimpleConnSet connections = new SimpleConnSet();
+
+    private HttpRequestHandler requestHandler = null;
+
+    /**
+     * Creates a new HTTP server instance, using an arbitrary free TCP port
+     * 
+     * @throws IOException  if anything goes wrong during initialization
+     */
+    public SimpleHttpServer() throws IOException {
+        this(null, 0);
+    }
+
+    /**
+     * Creates a new HTTP server instance, using the specified socket
+     * factory and the TCP port
+     * 
+     * @param   port    Desired TCP port
+     * @throws IOException  if anything goes wrong during initialization
+     */
+    public SimpleHttpServer(SimpleSocketFactory socketfactory, int port) 
+        throws IOException {
+        if (socketfactory == null) {
+        	socketfactory = new SimplePlainSocketFactory();
+        }
+        listener = socketfactory.createServerSocket(port);
+        if(LOG.isDebugEnabled()) {
+            LOG.debug("Starting test HTTP server on port " + getLocalPort());
+        }
+        tg = new ThreadGroup("SimpleHttpServer thread group");
+        t = new Thread(tg, this, "SimpleHttpServer listener");
+        t.setDaemon(true);
+        t.start();
+    }
+
+    /**
+     * Creates a new HTTP server instance, using the specified TCP port
+     * 
+     * @param   port    Desired TCP port
+     * @throws IOException  if anything goes wrong during initialization
+     */
+    public SimpleHttpServer(int port) throws IOException {
+        this(null, port);
+    }
+
+    public String getTestname() {
+        return this.testname;
+    }
+
+    public void setTestname(final String testname) {
+        this.testname = testname;
+    }
+    
+    /**
+     * Returns the TCP port that this HTTP server instance is bound to.
+     *
+     * @return  TCP port, or -1 if not running
+     */
+    public int getLocalPort() {
+        return listener.getLocalPort();
+    }
+    
+    /**
+     * Returns the IP address that this HTTP server instance is bound to.
+     * @return String representation of the IP address or <code>null</code> if not running
+     */
+    public String getLocalAddress() {
+        InetAddress address = listener.getInetAddress();
+        // Ugly work-around for older JDKs
+        byte[] octets = address.getAddress();
+        if ((octets[0] == 0) 
+         && (octets[1] == 0) 
+         && (octets[2] == 0) 
+         && (octets[3] == 0)) {
+            return "localhost"; 
+        } else {
+            return address.getHostAddress();
+        }
+    }
+
+    /**
+     * Checks if this HTTP server instance is running.
+     * 
+     * @return  true/false
+     */
+    public boolean isRunning() {
+        if(t == null) {
+            return false;
+        }
+        return t.isAlive();
+    }
+
+    /**
+     * Stops this HTTP server instance.
+     */
+    public synchronized void destroy() {
+        if (stopped) {
+            return;
+        }
+
+        this.stopped = true;
+        if(LOG.isDebugEnabled()) {
+            LOG.debug("Stopping test HTTP server on port " + getLocalPort());
+        }
+        tg.interrupt();
+        
+        if (listener != null) {
+            try {
+                listener.close();
+            } catch(IOException e) {
+                
+            }
+        }
+        this.connections.shutdown();
+    }
+
+    /**
+     * Returns the currently used HttpRequestHandler by this SimpleHttpServer
+     * 
+     * @return The used HttpRequestHandler, or null.
+     */
+    public HttpRequestHandler getRequestHandler() {
+        return requestHandler;
+    }
+
+    /**
+     * Sets the HttpRequestHandler to be used for this SimpleHttpServer.
+     * 
+     * @param rh    Request handler to be used, or null to disable.
+     */
+    public void setRequestHandler(HttpRequestHandler rh) {
+        this.requestHandler = rh;
+    }
+
+    public void setHttpService(HttpService service) {
+        setRequestHandler(new HttpServiceHandler(service));
+    }
+
+    public void run() {
+        try {
+            while (!this.stopped && !Thread.interrupted()) {
+                Socket socket = listener.accept();
+                try {
+                    if (this.requestHandler == null) {
+                        socket.close();
+                        break;
+                    }
+                    SimpleHttpServerConnection conn = new SimpleHttpServerConnection(socket); 
+                    this.connections.addConnection(conn);
+
+                    Thread t = new SimpleConnectionThread(
+                            tg,
+                            this.testname + " thread " + this.count,
+                            conn, 
+                            this.connections,
+                            this.requestHandler);
+                    t.setDaemon(true);
+                    t.start();
+                } catch (IOException e) {
+                    LOG.error("I/O error: " + e.getMessage());
+                }
+                this.count++;
+                Thread.sleep(100);
+            }
+        } catch (InterruptedException accept) {
+        } catch (IOException e) {
+            if (!stopped) {
+                LOG.error("I/O error: " + e.getMessage());
+            }
+        } finally {
+            destroy();
+        }
+    }
+}

Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServerConnection.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServerConnection.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServerConnection.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServerConnection.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,241 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimpleHttpServerConnection.java,v 1.21 2004/12/11 22:35:26 olegk Exp $
+ * $Revision: 224451 $
+ * $Date: 2005-07-23 06:23:59 -0400 (Sat, 23 Jul 2005) $
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.Socket;
+import java.net.SocketException;
+import java.util.Iterator;
+
+import org.apache.commons.httpclient.ChunkedOutputStream;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpParser;
+import org.apache.commons.httpclient.StatusLine;
+
+/**
+ * A connection to the SimpleHttpServer.
+ * 
+ * @author Christian Kohlschuetter
+ * @author Oleg Kalnichevski
+ */
+public class SimpleHttpServerConnection {
+    
+    private static final String HTTP_ELEMENT_CHARSET = "US-ASCII";
+
+    private Socket socket = null;
+    private InputStream in = null;
+    private OutputStream out = null;
+    private boolean keepAlive = false;
+
+    public SimpleHttpServerConnection(final Socket socket) 
+    throws IOException {
+        super();
+        if (socket == null) {
+            throw new IllegalArgumentException("Socket may not be null");
+        }
+        this.socket = socket;
+        this.socket.setSoTimeout(500);
+        this.in = socket.getInputStream();
+        this.out = socket.getOutputStream();
+    }
+
+    public synchronized void close() {
+        try {
+            if (socket != null) {
+                in.close();
+                out.close();
+                socket.close();
+                socket = null;
+            }
+        } catch (IOException e) {
+        }
+    }
+
+    public synchronized boolean isOpen() {
+        return this.socket != null;
+    }
+    
+    public void setKeepAlive(boolean b) {
+        this.keepAlive = b;
+    }
+
+    public boolean isKeepAlive() {
+        return this.keepAlive;
+    }
+
+    public InputStream getInputStream() {
+        return this.in;
+    }
+
+    public OutputStream getOutputStream() {
+        return this.out;
+    }
+
+    /**
+     * Returns the ResponseWriter used to write the output to the socket.
+     * 
+     * @return This connection's ResponseWriter
+     */
+    public ResponseWriter getWriter() throws UnsupportedEncodingException {
+        return new ResponseWriter(out);
+    }
+
+    public SimpleRequest readRequest() throws IOException {
+        try {
+            String line = null;
+            do {
+                line = HttpParser.readLine(in, HTTP_ELEMENT_CHARSET);
+            } while (line != null && line.length() == 0);
+
+            if (line == null) {
+                setKeepAlive(false);
+                return null;
+            }
+            SimpleRequest request = new SimpleRequest( 
+                    RequestLine.parseLine(line),
+                    HttpParser.parseHeaders(this.in, HTTP_ELEMENT_CHARSET),
+                    this.in);
+            return request;
+        } catch (IOException e) {
+            close();
+            throw e;
+        }
+    }
+
+    public SimpleResponse readResponse() throws IOException {
+        try {
+            String line = null;
+            do {
+                line = HttpParser.readLine(in, HTTP_ELEMENT_CHARSET);
+            } while (line != null && line.length() == 0);
+
+            if (line == null) {
+                setKeepAlive(false);
+                return null;
+            }
+            SimpleResponse response = new SimpleResponse(
+                    new StatusLine(line),
+                    HttpParser.parseHeaders(this.in, HTTP_ELEMENT_CHARSET),
+                    this.in);
+            return response;
+        } catch (IOException e) {
+            close();
+            throw e;
+        }
+    }
+
+    public void writeRequest(final SimpleRequest request) throws IOException {
+        if (request == null) {
+            return;
+        }
+        ResponseWriter writer = new ResponseWriter(this.out, HTTP_ELEMENT_CHARSET);
+        writer.println(request.getRequestLine().toString());
+        Iterator item = request.getHeaderIterator();
+        while (item.hasNext()) {
+            Header header = (Header) item.next();
+            writer.print(header.toExternalForm());
+        }
+        writer.println();
+        writer.flush();
+        
+        OutputStream outsream = this.out;
+        InputStream content = request.getBody(); 
+        if (content != null) {
+
+            Header transferenc = request.getFirstHeader("Transfer-Encoding");
+            if (transferenc != null) {
+                request.removeHeaders("Content-Length");
+                if (transferenc.getValue().indexOf("chunked") != -1) {
+                    outsream = new ChunkedOutputStream(outsream);
+                }
+            }
+            byte[] tmp = new byte[4096];
+            int i = 0;
+            while ((i = content.read(tmp)) >= 0) {
+                outsream.write(tmp, 0, i);
+            }        
+            if (outsream instanceof ChunkedOutputStream) {
+                ((ChunkedOutputStream)outsream).finish();
+            }
+        }
+        outsream.flush();
+    }
+    
+    public void writeResponse(final SimpleResponse response) throws IOException {
+        if (response == null) {
+            return;
+        }
+        ResponseWriter writer = new ResponseWriter(this.out, HTTP_ELEMENT_CHARSET);
+        writer.println(response.getStatusLine());
+        Iterator item = response.getHeaderIterator();
+        while (item.hasNext()) {
+            Header header = (Header) item.next();
+            writer.print(header.toExternalForm());
+        }
+        writer.println();
+        writer.flush();
+        
+        OutputStream outsream = this.out;
+        InputStream content = response.getBody(); 
+        if (content != null) {
+
+            Header transferenc = response.getFirstHeader("Transfer-Encoding");
+            if (transferenc != null) {
+                response.removeHeaders("Content-Length");
+                if (transferenc.getValue().indexOf("chunked") != -1) {
+                    outsream = new ChunkedOutputStream(outsream);
+                }
+            }
+                        
+            byte[] tmp = new byte[1024];
+            int i = 0;
+            while ((i = content.read(tmp)) >= 0) {
+                outsream.write(tmp, 0, i);
+            }        
+            if (outsream instanceof ChunkedOutputStream) {
+                ((ChunkedOutputStream)outsream).finish();
+            }
+        }
+        outsream.flush();
+    }
+
+    public int getSocketTimeout() throws SocketException {
+        return this.socket.getSoTimeout();
+    }
+    
+    public void setSocketTimeout(int timeout) throws SocketException {
+        this.socket.setSoTimeout(timeout);
+    }
+        
+}
+    
\ No newline at end of file

Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServerConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimplePlainSocketFactory.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimplePlainSocketFactory.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimplePlainSocketFactory.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimplePlainSocketFactory.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,50 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimplePlainSocketFactory.java,v 1.1 2004/12/11 22:35:26 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+
+/**
+ * Defines a plain socket factory
+ * 
+ * @author Oleg Kalnichevski
+ */
+public class SimplePlainSocketFactory implements SimpleSocketFactory {
+    
+    public SimplePlainSocketFactory() {
+    	super();
+    }
+    
+    public ServerSocket createServerSocket(int port) throws IOException {
+        return new ServerSocket(port);
+    }
+    
+}

Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimplePlainSocketFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleProxy.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleProxy.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleProxy.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleProxy.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,81 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimpleProxy.java,v 1.8 2004/12/11 22:35:26 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.IOException;
+
+import org.apache.commons.httpclient.Credentials;
+
+/**
+ * Simple server that registers default request handlers to act as a proxy.
+ * 
+ * @author Ortwin Glueck
+ * @author Oleg Kalnichevski
+ */
+public class SimpleProxy extends SimpleHttpServer {
+    
+    private SimpleConnManager connmanager = null; 
+    private HttpRequestHandlerChain stdchain = null;
+
+    public SimpleProxy(int port) throws IOException {
+        super(port);
+        this.connmanager = new SimpleConnManager(); 
+        this.stdchain = new HttpRequestHandlerChain();
+        this.stdchain.appendHandler(new TransparentProxyRequestHandler());
+        this.stdchain.appendHandler(new ProxyRequestHandler(this.connmanager));
+        setRequestHandler(this.stdchain);
+    }
+
+    public SimpleProxy() throws IOException {
+        this(0);
+    }
+
+    public void requireAuthentication(final Credentials creds, final String realm, boolean keepalive) {
+        HttpRequestHandlerChain chain = new HttpRequestHandlerChain(this.stdchain); 
+        chain.prependHandler(new ProxyAuthRequestHandler(creds ,realm, keepalive));
+        setRequestHandler(chain);
+    }
+
+    public void requireAuthentication(final Credentials creds) {
+        HttpRequestHandlerChain chain = new HttpRequestHandlerChain(this.stdchain); 
+        chain.prependHandler(new ProxyAuthRequestHandler(creds));
+        setRequestHandler(chain);
+    }
+
+    public void destroy() {
+        super.destroy();
+        this.connmanager.shutdown();
+    }
+    
+    public void addHandler(final HttpRequestHandler handler) {
+        this.stdchain.prependHandler(handler);
+    }
+    
+}

Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleRequest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleRequest.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleRequest.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleRequest.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,221 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimpleRequest.java,v 1.3 2004/11/13 12:21:28 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+
+import org.apache.commons.httpclient.ChunkedInputStream;
+import org.apache.commons.httpclient.ContentLengthInputStream;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HeaderElement;
+import org.apache.commons.httpclient.HeaderGroup;
+import org.apache.commons.httpclient.NameValuePair;
+
+/**
+ * A generic HTTP request.
+ * 
+ * @author Oleg Kalnichevski
+ */
+public class SimpleRequest {
+    
+    public static final String DEFAULT_CONTENT_CHARSET = "ISO-8859-1";
+    
+    private RequestLine requestLine = null;
+    private HeaderGroup headers = new HeaderGroup();
+    private InputStream entity = null;
+
+    public SimpleRequest() {
+        super();
+    }
+
+    public SimpleRequest(
+        final RequestLine requestLine,
+        final Header[] headers,
+        final InputStream content) throws IOException
+    {
+        super();
+        if (requestLine == null) {
+            throw new IllegalArgumentException("Request line may not be null");
+        }
+        this.requestLine = requestLine;
+        if (headers != null) {
+            this.headers.setHeaders(headers);
+        }
+        if (content != null) {
+            // only PUT and POST have content
+            String methodname = requestLine.getMethod(); 
+            if ("POST".equalsIgnoreCase(methodname) || "PUT".equalsIgnoreCase(methodname)) {
+                Header contentLength = this.headers.getFirstHeader("Content-Length");
+                Header transferEncoding = this.headers.getFirstHeader("Transfer-Encoding");
+                InputStream in = content;
+                if (transferEncoding != null) {
+                    if (transferEncoding.getValue().indexOf("chunked") != -1) {
+                        in = new ChunkedInputStream(in);
+                    }
+                } else if (contentLength != null) {
+                    long len = getContentLength();
+                    if (len >= 0) {
+                        in = new ContentLengthInputStream(in, len);
+                    }
+                }
+                this.entity = in;
+            }
+        }
+    }
+
+    public SimpleRequest(final RequestLine requestLine, final Header[] headers)
+        throws IOException {
+        this(requestLine, headers, null);
+    }
+    
+    public RequestLine getRequestLine() {
+        return this.requestLine;
+    }
+
+    public void setRequestLine(final RequestLine requestline) {
+        if (requestline == null) {
+            throw new IllegalArgumentException("Request line may not be null");
+        }
+        this.requestLine = requestline;
+    }
+
+    public boolean containsHeader(final String name) {
+        return this.headers.containsHeader(name);
+    }
+
+    public Header[] getHeaders() {
+        return this.headers.getAllHeaders();
+    }
+
+    public Header getFirstHeader(final String s) {
+        return this.headers.getFirstHeader(s);
+    }
+
+    public void removeHeaders(final String s) {
+        if (s == null) {
+            return;
+        }
+        Header[] headers = this.headers.getHeaders(s);
+        for (int i = 0; i < headers.length; i++) {
+            this.headers.removeHeader(headers[i]);
+        }
+    }
+
+    public void addHeader(final Header header) {
+        if (header == null) {
+            return;
+        }
+        this.headers.addHeader(header);
+    }
+
+    public void setHeader(final Header header) {
+        if (header == null) {
+            return;
+        }
+        removeHeaders(header.getName());
+        addHeader(header);
+    }
+
+    public Iterator getHeaderIterator() {
+        return this.headers.getIterator();
+    }
+
+    public String getContentType() {
+        Header contenttype = this.headers.getFirstHeader("Content-Type");
+        if (contenttype != null) {
+            return contenttype.getValue(); 
+        } else {
+            return "text/plain"; 
+        }
+    }
+    
+    public String getCharset() {
+        String charset = null;
+        Header contenttype = this.headers.getFirstHeader("Content-Type");
+        if (contenttype != null) {
+            HeaderElement values[] = contenttype.getElements();
+            if (values.length == 1) {
+                NameValuePair param = values[0].getParameterByName("charset");
+                if (param != null) {
+                    charset = param.getValue();
+                }
+            }
+        }
+        if (charset != null) {
+            return charset;
+        } else {
+            return DEFAULT_CONTENT_CHARSET;
+        }
+    }
+    
+    public long getContentLength() {
+        Header contentLength = this.headers.getFirstHeader("Content-Length");
+        if (contentLength != null) {
+            try {
+                return Long.parseLong(contentLength.getValue());
+            } catch (NumberFormatException e) {
+                return -1;
+            }
+        } else {
+            return -1;
+        }
+    }
+    
+    public InputStream getBody() {
+        return this.entity;
+    }
+    
+    public byte[] getBodyBytes() throws IOException {
+        InputStream in = getBody();
+        if (in != null) {
+            byte[] tmp = new byte[4096];
+            int bytesRead = 0;
+            ByteArrayOutputStream buffer = new ByteArrayOutputStream(1024);
+            while ((bytesRead = in.read(tmp)) != -1) {
+                buffer.write(tmp, 0, bytesRead);
+            }
+            return buffer.toByteArray();
+        } else {
+            return null;
+        }
+    }
+    
+    public String getBodyString() throws IOException {
+        byte[] raw = getBodyBytes();
+        if (raw != null) {
+            return new String(raw, getCharset());
+        } else {
+            return null;
+        }
+    }
+}

Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleResponse.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleResponse.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleResponse.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleResponse.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,270 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimpleResponse.java,v 1.8 2004/11/13 12:21:28 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Iterator;
+
+import org.apache.commons.httpclient.ChunkedInputStream;
+import org.apache.commons.httpclient.ContentLengthInputStream;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HeaderElement;
+import org.apache.commons.httpclient.HeaderGroup;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.StatusLine;
+
+/**
+ * A generic HTTP response.
+ * 
+ * @author Christian Kohlschuetter
+ * @author Oleg Kalnichevski
+ */
+public class SimpleResponse {
+    
+    public static final String DEFAULT_CONTENT_CHARSET = "ISO-8859-1";
+    
+    private HttpVersion ver = HttpVersion.HTTP_1_1;
+    private int statuscode = HttpStatus.SC_OK;
+    private String phrase = HttpStatus.getStatusText(HttpStatus.SC_OK);
+    private HeaderGroup headers = new HeaderGroup();
+    private InputStream entity = null;
+
+    public SimpleResponse() {
+        super();
+    }
+
+    public SimpleResponse(
+            final StatusLine statusline, 
+            final Header[] headers, 
+            final InputStream content) 
+            throws IOException {
+        super();
+        if (statusline == null) {
+            throw new IllegalArgumentException("Status line may not be null");
+        }
+        setStatusLine(HttpVersion.parse(statusline.getHttpVersion()),
+                statusline.getStatusCode(), statusline.getReasonPhrase());
+        setHeaders(headers);
+        if (content != null) {
+            InputStream in = content;
+            Header contentLength = this.headers.getFirstHeader("Content-Length");
+            Header transferEncoding = this.headers.getFirstHeader("Transfer-Encoding");
+
+            if (transferEncoding != null) {
+                if (transferEncoding.getValue().indexOf("chunked") != -1) {
+                    in = new ChunkedInputStream(in);
+                }
+            } else if (contentLength != null) {
+                long len = getContentLength();
+                if (len >= 0) {
+                    in = new ContentLengthInputStream(in, len);
+                }
+            }
+            this.entity = in;
+        }
+    }
+
+
+    public void setStatusLine(final HttpVersion ver, int statuscode, final String phrase) {
+        if (ver == null) {
+            throw new IllegalArgumentException("HTTP version may not be null");
+        }
+        if (statuscode <= 0) {
+            throw new IllegalArgumentException("Status code may not be negative or zero");
+        }
+        this.ver = ver;
+        this.statuscode = statuscode;
+        if (phrase != null) {
+            this.phrase = phrase;
+        } else {
+            this.phrase = HttpStatus.getStatusText(statuscode);
+        }
+    }
+
+    public void setStatusLine(final HttpVersion ver, int statuscode) {
+        setStatusLine(ver, statuscode, null);
+    }
+
+    public String getPhrase() {
+        return this.phrase;
+    }
+
+    public int getStatuscode() {
+        return this.statuscode;
+    }
+
+    public HttpVersion getHttpVersion() {
+        return this.ver;
+    }
+
+    public String getStatusLine() {
+        StringBuffer buffer = new StringBuffer();
+        buffer.append(this.ver);
+        buffer.append(' ');
+        buffer.append(this.statuscode);
+        if (this.phrase != null) {
+            buffer.append(' ');
+            buffer.append(this.phrase);
+        }
+        return buffer.toString();
+    }
+
+    public boolean containsHeader(final String name) {
+        return this.headers.containsHeader(name);
+    }
+
+    public Header[] getHeaders() {
+        return this.headers.getAllHeaders();
+    }
+
+    public Header getFirstHeader(final String name) {
+        return this.headers.getFirstHeader(name);
+    }
+
+    public void removeHeaders(final String s) {
+        if (s == null) {
+            return;
+        }
+        Header[] headers = this.headers.getHeaders(s);
+        for (int i = 0; i < headers.length; i++) {
+            this.headers.removeHeader(headers[i]);
+        }
+    }
+
+    public void addHeader(final Header header) {
+        if (header == null) {
+            return;
+        }
+        this.headers.addHeader(header);
+    }
+
+    public void setHeader(final Header header) {
+        if (header == null) {
+            return;
+        }
+        removeHeaders(header.getName());
+        addHeader(header);
+    }
+
+    public void setHeaders(final Header[] headers) {
+        if (headers == null) {
+            return;
+        }
+        this.headers.setHeaders(headers);
+    }
+
+    public Iterator getHeaderIterator() {
+        return this.headers.getIterator();
+    }
+    
+    public String getCharset() {
+        String charset = DEFAULT_CONTENT_CHARSET;
+        Header contenttype = this.headers.getFirstHeader("Content-Type");
+        if (contenttype != null) {
+            HeaderElement values[] = contenttype.getElements();
+            if (values.length == 1) {
+                NameValuePair param = values[0].getParameterByName("charset");
+                if (param != null) {
+                    charset = param.getValue();
+                }
+            }
+        }
+        return charset;
+    }
+
+    public long getContentLength() {
+        Header contentLength = this.headers.getFirstHeader("Content-Length");
+        if (contentLength != null) {
+            try {
+                return Long.parseLong(contentLength.getValue());
+            } catch (NumberFormatException e) {
+                return -1;
+            }
+        } else {
+            return -1;
+        }
+    }
+    
+    public void setBodyString(final String string) {
+        if (string != null) {
+            byte[] raw = null;
+            try {
+                raw = string.getBytes(DEFAULT_CONTENT_CHARSET);
+            } catch (UnsupportedEncodingException e) {
+                raw = string.getBytes();
+            }
+            this.entity = new ByteArrayInputStream(raw);
+            if (!containsHeader("Content-Type")) {
+                setHeader(new Header("Content-Type", "text/plain"));
+            }
+            setHeader(new Header("Content-Length", Long.toString(raw.length)));
+        } else {
+            this.entity = null;
+        }
+    }
+    
+    public void setBody(final InputStream instream) {
+        this.entity = instream;
+    }
+    
+    public InputStream getBody() {
+        return this.entity;
+    }
+    
+    public byte[] getBodyBytes() throws IOException {
+        InputStream in = getBody();
+        if (in != null) {
+            byte[] tmp = new byte[4096];
+            int bytesRead = 0;
+            ByteArrayOutputStream buffer = new ByteArrayOutputStream(1024);
+            while ((bytesRead = in.read(tmp)) != -1) {
+                buffer.write(tmp, 0, bytesRead);
+            }
+            return buffer.toByteArray();
+        } else {
+            return null;
+        }
+    }
+    
+    public String getBodyString() throws IOException {
+        byte[] raw = getBodyBytes();
+        if (raw != null) {
+            return new String(raw, getCharset());
+        } else {
+            return null;
+        }
+    }
+}

Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleSocketFactory.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleSocketFactory.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleSocketFactory.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleSocketFactory.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,44 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimpleSocketFactory.java,v 1.1 2004/12/11 22:35:26 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+
+/**
+ * Defines a socket factory interface
+ * 
+ * @author Oleg Kalnichevski
+ */
+public interface SimpleSocketFactory {
+    
+    ServerSocket createServerSocket(int port) throws IOException;
+    
+}

Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleSocketFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/TransparentProxyRequestHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/TransparentProxyRequestHandler.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/TransparentProxyRequestHandler.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/TransparentProxyRequestHandler.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,147 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/TransparentProxyRequestHandler.java,v 1.7 2004/12/11 22:35:26 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InterruptedIOException;
+import java.io.OutputStream;
+import java.net.Socket;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.HttpVersion;
+
+/**
+ * This request handler can handle the CONNECT method. It does nothing for any
+ * other HTTP methods.
+ * 
+ * @author Ortwin Glueck
+ */
+public class TransparentProxyRequestHandler implements HttpRequestHandler {
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.commons.httpclient.server.HttpRequestHandler#processRequest(org.apache.commons.httpclient.server.SimpleHttpServerConnection)
+     */
+    public boolean processRequest(
+        final SimpleHttpServerConnection conn,
+        final SimpleRequest request) throws IOException
+    {
+
+        RequestLine line = request.getRequestLine();
+        HttpVersion ver = line.getHttpVersion();
+        String method = line.getMethod();
+        if (!"CONNECT".equalsIgnoreCase(method)) {
+            return false;
+        }
+        Socket targetSocket = null;
+        try {
+            targetSocket = connect(line.getUri());
+        } catch (IOException e) {
+            SimpleResponse response = new SimpleResponse();
+            response.setStatusLine(ver, HttpStatus.SC_NOT_FOUND);
+            response.setHeader(new Header("Server", "test proxy"));
+            response.setBodyString("Cannot connect to " + line.getUri());
+            conn.writeResponse(response);
+            return true;
+        }
+        SimpleResponse response = new SimpleResponse();
+        response.setHeader(new Header("Server", "test proxy"));
+        response.setStatusLine(ver, HttpStatus.SC_OK, "Connection established");
+        conn.writeResponse(response);
+        
+        SimpleHttpServerConnection target = new SimpleHttpServerConnection(targetSocket); 
+        pump(conn, target);
+        return true;
+    }
+
+    private void pump(final SimpleHttpServerConnection source, final SimpleHttpServerConnection target)
+        throws IOException {
+
+        source.setSocketTimeout(100);
+        target.setSocketTimeout(100);
+
+        InputStream sourceIn = source.getInputStream();
+        OutputStream sourceOut = source.getOutputStream();
+        InputStream targetIn = target.getInputStream();
+        OutputStream targetOut = target.getOutputStream();
+        
+        byte[] tmp = new byte[1024];
+        int l;
+        for (;;) {
+            if (!source.isOpen() || !target.isOpen()) { 
+                break;
+            }
+            try {
+                l = sourceIn.read(tmp);
+                if (l == -1) {
+                    break;
+                }
+                targetOut.write(tmp, 0, l);
+            } catch (InterruptedIOException ignore) {
+                if (Thread.interrupted()) {
+                    break;
+                }
+            }
+            try {
+                l = targetIn.read(tmp);
+                if (l == -1) {
+                    break;
+                }
+                sourceOut.write(tmp, 0, l);
+            } catch (InterruptedIOException ignore) {
+                if (Thread.interrupted()) {
+                    break;
+                }
+            }
+        }
+    }
+    
+    private static Socket connect(final String host) throws IOException {
+        String hostname = null; 
+        int port; 
+        int i = host.indexOf(':');
+        if (i != -1) {
+            hostname = host.substring(0, i);
+            try {
+                port = Integer.parseInt(host.substring(i + 1));
+            } catch (NumberFormatException ex) {
+                throw new IOException("Invalid host address: " + host);
+            }
+        } else {
+            hostname = host;
+            port = 80;
+        }
+        return new Socket(hostname, port);        
+    }
+    
+}
\ No newline at end of file

Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/TransparentProxyRequestHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axis/trunk/java/modules/integration/project.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/integration/project.xml?rev=232392&r1=232391&r2=232392&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/integration/project.xml (original)
+++ webservices/axis/trunk/java/modules/integration/project.xml Fri Aug 12 13:59:07 2005
@@ -170,13 +170,11 @@
                 <exclude>**/*Abstract*.java</exclude>
                 <exclude>**/*Util*.java</exclude>
                 <exclude>**/*InteropStubTest.java</exclude>
-                <!--  <exclude>**/*Groovy*.java</exclude> -->
-                <!-- <exclude>**/*EchoRawXMLChunckedTest.java</exclude> -->
                 <exclude>**org/apache/axis2/mail/*.java</exclude>
                 <exclude>**/*EchoRawSwATest.java</exclude>
                 <exclude>**org/apache/axis2/soap12testing/soap12testsuite/*.java</exclude>
-                  
-<!--                  <exclude>**/*GroovyServiceTest.java</exclude>-->
+                <exclude>**/*EchoRawMTOMTest.java</exclude>
+                <exclude>**/*EchoRawMTOMFileCacheTest.java</exclude>
                 
             </excludes>
             <includes>

Modified: webservices/axis/trunk/java/modules/integration/src/org/apache/axis2/soap12testing/server/SimpleServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/integration/src/org/apache/axis2/soap12testing/server/SimpleServer.java?rev=232392&r1=232391&r2=232392&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/integration/src/org/apache/axis2/soap12testing/server/SimpleServer.java (original)
+++ webservices/axis/trunk/java/modules/integration/src/org/apache/axis2/soap12testing/server/SimpleServer.java Fri Aug 12 13:59:07 2005
@@ -23,7 +23,6 @@
 import org.apache.commons.logging.LogFactory;
 
 import java.io.File;
-import java.net.ServerSocket;
 
 public class SimpleServer {
     private int port;
@@ -38,13 +37,11 @@
 
     public void start() {
         try {
-            ServerSocket serverSoc = null;
-            serverSoc = new ServerSocket(port);
             File file = new File(MessageComparator.TEST_MAIN_DIR+ "target/Repository");
             if(!file.exists()){
                 throw new AxisFault(file.getAbsolutePath() + " File does not exisits");
             }
-            SimpleHTTPServer reciver = new SimpleHTTPServer(file.getAbsolutePath(), serverSoc);
+            SimpleHTTPServer reciver = new SimpleHTTPServer(file.getAbsolutePath(), port);
             Thread thread = new Thread(reciver);
             thread.setDaemon(true);
             thread.start();

Modified: webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilServer.java?rev=232392&r1=232391&r2=232392&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilServer.java (original)
+++ webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilServer.java Fri Aug 12 13:59:07 2005
@@ -29,7 +29,6 @@
 
 import javax.xml.namespace.QName;
 import java.io.File;
-import java.net.ServerSocket;
 
 public class UtilServer {
     private static int count = 0;
@@ -63,15 +62,8 @@
             }
             ConfigurationContext er = erfac.buildConfigurationContext(
                     file.getAbsolutePath());
-            try {
-                Thread.sleep(2000);
-            } catch (InterruptedException e1) {
-                throw new AxisFault("Thread interuptted", e1);
-            }
 
-            ServerSocket serverSoc = null;
-            serverSoc = new ServerSocket(Constants.TESTING_PORT);
-            receiver = new SimpleHTTPServer(er, serverSoc);
+            receiver = new SimpleHTTPServer(er, Constants.TESTING_PORT);
             Thread thread = new Thread(receiver);
             thread.setDaemon(true);
 
@@ -83,6 +75,13 @@
             } finally {
 
             }
+
+            try {
+                Thread.sleep(2000);
+            } catch (InterruptedException e1) {
+                throw new AxisFault("Thread interuptted", e1);
+            }
+
         }
         count++;
     }