[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-commit] r2390 - jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler

Author: gwilkins
Date: 2010-10-23 03:02:35 -0400 (Sat, 23 Oct 2010)
New Revision: 2390

Added:
   jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectSSLTest.java
   jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectTest.java
Removed:
   jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ProxyHandlerConnectSSLTest.java
   jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ProxyHandlerConnectTest.java
Log:
327562 completed rename

Copied: jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectSSLTest.java (from rev 2389, jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ProxyHandlerConnectSSLTest.java)
===================================================================
--- jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectSSLTest.java	                        (rev 0)
+++ jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectSSLTest.java	2010-10-23 07:02:35 UTC (rev 2390)
@@ -0,0 +1,221 @@
+package org.eclipse.jetty.server.handler;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.security.SecureRandom;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class ConnectHandlerConnectSSLTest extends AbstractProxyHandlerTest
+{
+    @BeforeClass
+    public static void init() throws Exception
+    {
+        SslSelectChannelConnector connector = new SslSelectChannelConnector();
+
+        String keyStorePath = System.getProperty("basedir");
+        keyStorePath += File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "keystore";
+        connector.setKeystore(keyStorePath);
+        connector.setPassword("storepwd");
+        connector.setKeyPassword("keypwd");
+
+        startServer(connector, new ServerHandler());
+        startProxy();
+    }
+
+    @Test
+    public void testGETRequest() throws Exception
+    {
+        String hostPort = "localhost:" + serverConnector.getLocalPort();
+        String request = "" +
+                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
+                "Host: " + hostPort + "\r\n" +
+                "\r\n";
+        Socket socket = newSocket();
+        try
+        {
+            OutputStream output = socket.getOutputStream();
+            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            // Expect 200 OK from the CONNECT request
+            Response response = readResponse(input);
+            assertEquals("200", response.getCode());
+
+            // Be sure the buffered input does not have anything buffered
+            assertFalse(input.ready());
+
+            // Upgrade the socket to SSL
+            SSLSocket sslSocket = wrapSocket(socket);
+            try
+            {
+                output = sslSocket.getOutputStream();
+                input = new BufferedReader(new InputStreamReader(sslSocket.getInputStream()));
+
+                request = "" +
+                        "GET /echo HTTP/1.1\r\n" +
+                        "Host: " + hostPort + "\r\n" +
+                        "\r\n";
+                output.write(request.getBytes("UTF-8"));
+                output.flush();
+
+                response = readResponse(input);
+                assertEquals("200", response.getCode());
+                assertEquals("GET /echo", response.getBody());
+            }
+            finally
+            {
+                sslSocket.close();
+            }
+        }
+        finally
+        {
+            socket.close();
+        }
+    }
+
+    @Test
+    public void testPOSTRequests() throws Exception
+    {
+        String hostPort = "localhost:" + serverConnector.getLocalPort();
+        String request = "" +
+                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
+                "Host: " + hostPort + "\r\n" +
+                "\r\n";
+        Socket socket = newSocket();
+        try
+        {
+            OutputStream output = socket.getOutputStream();
+            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            // Expect 200 OK from the CONNECT request
+            Response response = readResponse(input);
+            assertEquals("200", response.getCode());
+
+            // Be sure the buffered input does not have anything buffered
+            assertFalse(input.ready());
+
+            // Upgrade the socket to SSL
+            SSLSocket sslSocket = wrapSocket(socket);
+            try
+            {
+                output = sslSocket.getOutputStream();
+                input = new BufferedReader(new InputStreamReader(sslSocket.getInputStream()));
+
+                for (int i = 0; i < 10; ++i)
+                {
+                    request = "" +
+                            "POST /echo?param=" + i + " HTTP/1.1\r\n" +
+                            "Host: " + hostPort + "\r\n" +
+                            "Content-Length: 5\r\n" +
+                            "\r\n" +
+                            "HELLO";
+                    output.write(request.getBytes("UTF-8"));
+                    output.flush();
+
+                    response = readResponse(input);
+                    assertEquals("200", response.getCode());
+                    assertEquals("POST /echo?param=" + i + "\r\nHELLO", response.getBody());
+                }
+            }
+            finally
+            {
+                sslSocket.close();
+            }
+        }
+        finally
+        {
+            socket.close();
+        }
+    }
+
+    private SSLSocket wrapSocket(Socket socket) throws Exception
+    {
+        SSLContext sslContext = SSLContext.getInstance("SSLv3");
+        sslContext.init(null, new TrustManager[]{new AlwaysTrustManager()}, new SecureRandom());
+        SSLSocketFactory socketFactory = sslContext.getSocketFactory();
+        SSLSocket sslSocket = (SSLSocket)socketFactory.createSocket(socket, socket.getInetAddress().getHostAddress(), socket.getPort(), true);
+        sslSocket.setUseClientMode(true);
+        sslSocket.startHandshake();
+        return sslSocket;
+    }
+
+    private class AlwaysTrustManager implements X509TrustManager
+    {
+        public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException
+        {
+        }
+
+        public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException
+        {
+        }
+
+        public X509Certificate[] getAcceptedIssuers()
+        {
+            return null;
+        }
+    }
+
+    private static class ServerHandler extends AbstractHandler
+    {
+        public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
+        {
+            request.setHandled(true);
+
+            String uri = httpRequest.getRequestURI();
+            if ("/echo".equals(uri))
+            {
+                StringBuilder builder = new StringBuilder();
+                builder.append(httpRequest.getMethod()).append(" ").append(uri);
+                if (httpRequest.getQueryString() != null)
+                    builder.append("?").append(httpRequest.getQueryString());
+
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                InputStream input = httpRequest.getInputStream();
+                int read = -1;
+                while ((read = input.read()) >= 0)
+                    baos.write(read);
+                baos.close();
+
+                ServletOutputStream output = httpResponse.getOutputStream();
+                output.println(builder.toString());
+                output.write(baos.toByteArray());
+            }
+            else
+            {
+                throw new ServletException();
+            }
+        }
+    }
+}


Property changes on: jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectSSLTest.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Copied: jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectTest.java (from rev 2389, jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ProxyHandlerConnectTest.java)
===================================================================
--- jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectTest.java	                        (rev 0)
+++ jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectTest.java	2010-10-23 07:02:35 UTC (rev 2390)
@@ -0,0 +1,517 @@
+package org.eclipse.jetty.server.handler;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.nio.channels.SocketChannel;
+import java.util.concurrent.ConcurrentMap;
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.io.Buffer;
+import org.eclipse.jetty.io.EndPoint;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class ConnectHandlerConnectTest extends AbstractProxyHandlerTest
+{
+    @BeforeClass
+    public static void init() throws Exception
+    {
+        startServer(new SelectChannelConnector(), new ServerHandler());
+        startProxy();
+    }
+
+    @Test
+    public void testCONNECT() throws Exception
+    {
+        String hostPort = "localhost:" + serverConnector.getLocalPort();
+        String request = "" +
+                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
+                "Host: " + hostPort + "\r\n" +
+                "\r\n";
+        Socket socket = newSocket();
+        try
+        {
+            OutputStream output = socket.getOutputStream();
+            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            // Expect 200 OK from the CONNECT request
+            Response response = readResponse(input);
+            assertEquals("200", response.getCode());
+        }
+        finally
+        {
+            socket.close();
+        }
+    }
+
+    @Test
+    public void testCONNECTAndGET() throws Exception
+    {
+        String hostPort = "localhost:" + serverConnector.getLocalPort();
+        String request = "" +
+                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
+                "Host: " + hostPort + "\r\n" +
+                "\r\n";
+        Socket socket = newSocket();
+        try
+        {
+            OutputStream output = socket.getOutputStream();
+            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            // Expect 200 OK from the CONNECT request
+            Response response = readResponse(input);
+            assertEquals("200", response.getCode());
+
+            request = "" +
+                    "GET /echo" + " HTTP/1.1\r\n" +
+                    "Host: " + hostPort + "\r\n" +
+                    "\r\n";
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            response = readResponse(input);
+            assertEquals("200", response.getCode());
+            assertEquals("GET /echo", response.getBody());
+        }
+        finally
+        {
+            socket.close();
+        }
+    }
+
+    @Test
+    public void testCONNECT10AndGET() throws Exception
+    {
+        String hostPort = "localhost:" + serverConnector.getLocalPort();
+        String request = "" +
+                "CONNECT " + hostPort + " HTTP/1.0\r\n" +
+                "Host: " + hostPort + "\r\n" +
+                "\r\n";
+        Socket socket = newSocket();
+        try
+        {
+            OutputStream output = socket.getOutputStream();
+            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            // Expect 200 OK from the CONNECT request
+            Response response = readResponse(input);
+            assertEquals("200", response.getCode());
+
+            request = "" +
+                    "GET /echo" + " HTTP/1.1\r\n" +
+                    "Host: " + hostPort + "\r\n" +
+                    "\r\n";
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            response = readResponse(input);
+            assertEquals("200", response.getCode());
+            assertEquals("GET /echo", response.getBody());
+        }
+        finally
+        {
+            socket.close();
+        }
+    }
+
+    @Test
+    public void testCONNECTAndGETPipelined() throws Exception
+    {
+        String hostPort = "localhost:" + serverConnector.getLocalPort();
+        String request = "" +
+                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
+                "Host: " + hostPort + "\r\n" +
+                "\r\n" +
+                "GET /echo" + " HTTP/1.1\r\n" +
+                "Host: " + hostPort + "\r\n" +
+                "\r\n";
+        Socket socket = newSocket();
+        try
+        {
+            OutputStream output = socket.getOutputStream();
+            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            // Expect 200 OK from the CONNECT request
+            Response response = readResponse(input);
+            assertEquals("200", response.getCode());
+
+            // The pipelined request must have gone up to the server as is
+            response = readResponse(input);
+            assertEquals("200", response.getCode());
+            assertEquals("GET /echo", response.getBody());
+        }
+        finally
+        {
+            socket.close();
+        }
+    }
+
+    @Test
+    public void testCONNECTAndMultipleGETs() throws Exception
+    {
+        String hostPort = "localhost:" + serverConnector.getLocalPort();
+        String request = "" +
+                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
+                "Host: " + hostPort + "\r\n" +
+                "\r\n";
+        Socket socket = newSocket();
+        try
+        {
+            OutputStream output = socket.getOutputStream();
+            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            // Expect 200 OK from the CONNECT request
+            Response response = readResponse(input);
+            assertEquals("200", response.getCode());
+
+            for (int i = 0; i < 10; ++i)
+            {
+                request = "" +
+                        "GET /echo" + " HTTP/1.1\r\n" +
+                        "Host: " + hostPort + "\r\n" +
+                        "\r\n";
+                output.write(request.getBytes("UTF-8"));
+                output.flush();
+
+                response = readResponse(input);
+                assertEquals("200", response.getCode());
+                assertEquals("GET /echo", response.getBody());
+            }
+        }
+        finally
+        {
+            socket.close();
+        }
+    }
+
+    @Test
+    public void testCONNECTAndGETServerStop() throws Exception
+    {
+        String hostPort = "localhost:" + serverConnector.getLocalPort();
+        String request = "" +
+                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
+                "Host: " + hostPort + "\r\n" +
+                "\r\n";
+        Socket socket = newSocket();
+        try
+        {
+            OutputStream output = socket.getOutputStream();
+            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            // Expect 200 OK from the CONNECT request
+            Response response = readResponse(input);
+            assertEquals("200", response.getCode());
+
+            request = "" +
+                    "GET /echo HTTP/1.1\r\n" +
+                    "Host: " + hostPort + "\r\n" +
+                    "\r\n";
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            response = readResponse(input);
+            assertEquals("200", response.getCode());
+            assertEquals("GET /echo", response.getBody());
+
+            // Idle server is shut down
+            stopServer();
+
+            int read = input.read();
+            assertEquals(-1, read);
+        }
+        finally
+        {
+            socket.close();
+            // Restart the server for the next test
+            server.start();
+        }
+    }
+
+    @Test
+    public void testCONNECTAndGETAndServerSideClose() throws Exception
+    {
+        String hostPort = "localhost:" + serverConnector.getLocalPort();
+        String request = "" +
+                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
+                "Host: " + hostPort + "\r\n" +
+                "\r\n";
+        Socket socket = newSocket();
+        try
+        {
+            OutputStream output = socket.getOutputStream();
+            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            // Expect 200 OK from the CONNECT request
+            Response response = readResponse(input);
+            assertEquals("200", response.getCode());
+
+            request = "" +
+                    "GET /close HTTP/1.1\r\n" +
+                    "Host: " + hostPort + "\r\n" +
+                    "\r\n";
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            int read = input.read();
+            assertEquals(-1, read);
+        }
+        finally
+        {
+            socket.close();
+        }
+    }
+
+    @Test
+    public void testCONNECTAndPOSTAndGET() throws Exception
+    {
+        String hostPort = "localhost:" + serverConnector.getLocalPort();
+        String request = "" +
+                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
+                "Host: " + hostPort + "\r\n" +
+                "\r\n";
+        Socket socket = newSocket();
+        try
+        {
+            OutputStream output = socket.getOutputStream();
+            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            // Expect 200 OK from the CONNECT request
+            Response response = readResponse(input);
+            assertEquals("200", response.getCode());
+
+            request = "" +
+                    "POST /echo HTTP/1.1\r\n" +
+                    "Host: " + hostPort + "\r\n" +
+                    "Content-Length: 5\r\n" +
+                    "\r\n" +
+                    "HELLO";
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            response = readResponse(input);
+            assertEquals("200", response.getCode());
+            assertEquals("POST /echo\r\nHELLO", response.getBody());
+
+            request = "" +
+                    "GET /echo" + " HTTP/1.1\r\n" +
+                    "Host: " + hostPort + "\r\n" +
+                    "\r\n";
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            response = readResponse(input);
+            assertEquals("200", response.getCode());
+            assertEquals("GET /echo", response.getBody());
+        }
+        finally
+        {
+            socket.close();
+        }
+    }
+
+    @Test
+    public void testCONNECTAndPOSTWithBigBody() throws Exception
+    {
+        String hostPort = "localhost:" + serverConnector.getLocalPort();
+        String request = "" +
+                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
+                "Host: " + hostPort + "\r\n" +
+                "\r\n";
+        Socket socket = newSocket();
+        try
+        {
+            OutputStream output = socket.getOutputStream();
+            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            // Expect 200 OK from the CONNECT request
+            Response response = readResponse(input);
+            assertEquals("200", response.getCode());
+
+            StringBuilder body = new StringBuilder();
+            String chunk = "0123456789ABCDEF";
+            for (int i = 0; i < 1024; ++i)
+                body.append(chunk);
+
+            request = "" +
+                    "POST /echo HTTP/1.1\r\n" +
+                    "Host: " + hostPort + "\r\n" +
+                    "Content-Length: " + body.length() + "\r\n" +
+                    "\r\n" +
+                    body;
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            response = readResponse(input);
+            assertEquals("200", response.getCode());
+            assertEquals("POST /echo\r\n" + body, response.getBody());
+        }
+        finally
+        {
+            socket.close();
+        }
+    }
+
+    @Test
+    public void testCONNECTAndPOSTWithContext() throws Exception
+    {
+        final String contextKey = "contextKey";
+        final String contextValue = "contextValue";
+
+        // Replace the default ProxyHandler with a subclass to test context information passing
+        stopProxy();
+        proxy.setHandler(new ConnectHandler()
+        {
+            @Override
+            protected boolean handleAuthentication(HttpServletRequest request, HttpServletResponse response, String address) throws ServletException, IOException
+            {
+                request.setAttribute(contextKey, contextValue);
+                return super.handleAuthentication(request, response, address);
+            }
+
+            @Override
+            protected SocketChannel connect(HttpServletRequest request, String host, int port) throws IOException
+            {
+                assertEquals(contextValue, request.getAttribute(contextKey));
+                return super.connect(request, host, port);
+            }
+
+            @Override
+            protected void prepareContext(HttpServletRequest request, ConcurrentMap<String, Object> context)
+            {
+                // Transfer data from the HTTP request to the connection context
+                assertEquals(contextValue, request.getAttribute(contextKey));
+                context.put(contextKey, request.getAttribute(contextKey));
+            }
+
+            @Override
+            protected int read(EndPoint endPoint, Buffer buffer, ConcurrentMap<String, Object> context) throws IOException
+            {
+                assertEquals(contextValue, context.get(contextKey));
+                return super.read(endPoint, buffer, context);
+            }
+
+            @Override
+            protected int write(EndPoint endPoint, Buffer buffer, ConcurrentMap<String, Object> context) throws IOException
+            {
+                assertEquals(contextValue, context.get(contextKey));
+                return super.write(endPoint, buffer, context);
+            }
+        });
+        proxy.start();
+
+        String hostPort = "localhost:" + serverConnector.getLocalPort();
+        String request = "" +
+                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
+                "Host: " + hostPort + "\r\n" +
+                "\r\n";
+        Socket socket = newSocket();
+        try
+        {
+            OutputStream output = socket.getOutputStream();
+            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            // Expect 200 OK from the CONNECT request
+            Response response = readResponse(input);
+            assertEquals("200", response.getCode());
+
+            String body = "0123456789ABCDEF";
+            request = "" +
+                    "POST /echo HTTP/1.1\r\n" +
+                    "Host: " + hostPort + "\r\n" +
+                    "Content-Length: " + body.length() + "\r\n" +
+                    "\r\n" +
+                    body;
+            output.write(request.getBytes("UTF-8"));
+            output.flush();
+
+            response = readResponse(input);
+            assertEquals("200", response.getCode());
+            assertEquals("POST /echo\r\n" + body, response.getBody());
+        }
+        finally
+        {
+            socket.close();
+        }
+    }
+
+    private static class ServerHandler extends AbstractHandler
+    {
+        public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
+        {
+            request.setHandled(true);
+
+            String uri = httpRequest.getRequestURI();
+            if ("/echo".equals(uri))
+            {
+                StringBuilder builder = new StringBuilder();
+                builder.append(httpRequest.getMethod()).append(" ").append(uri);
+                if (httpRequest.getQueryString() != null)
+                    builder.append("?").append(httpRequest.getQueryString());
+
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                InputStream input = httpRequest.getInputStream();
+                int read = -1;
+                while ((read = input.read()) >= 0)
+                    baos.write(read);
+                baos.close();
+
+                ServletOutputStream output = httpResponse.getOutputStream();
+                output.println(builder.toString());
+                output.write(baos.toByteArray());
+            }
+            else if ("/close".equals(uri))
+            {
+                request.getConnection().getEndPoint().close();
+            }
+            else
+            {
+                throw new ServletException();
+            }
+        }
+    }
+}


Property changes on: jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerConnectTest.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Deleted: jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ProxyHandlerConnectSSLTest.java
===================================================================
--- jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ProxyHandlerConnectSSLTest.java	2010-10-23 07:02:17 UTC (rev 2389)
+++ jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ProxyHandlerConnectSSLTest.java	2010-10-23 07:02:35 UTC (rev 2390)
@@ -1,221 +0,0 @@
-package org.eclipse.jetty.server.handler;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.Socket;
-import java.security.SecureRandom;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocket;
-import javax.net.ssl.SSLSocketFactory;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.jetty.server.Request;
-import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
-/**
- * @version $Revision$ $Date$
- */
-public class ProxyHandlerConnectSSLTest extends AbstractProxyHandlerTest
-{
-    @BeforeClass
-    public static void init() throws Exception
-    {
-        SslSelectChannelConnector connector = new SslSelectChannelConnector();
-
-        String keyStorePath = System.getProperty("basedir");
-        keyStorePath += File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "keystore";
-        connector.setKeystore(keyStorePath);
-        connector.setPassword("storepwd");
-        connector.setKeyPassword("keypwd");
-
-        startServer(connector, new ServerHandler());
-        startProxy();
-    }
-
-    @Test
-    public void testGETRequest() throws Exception
-    {
-        String hostPort = "localhost:" + serverConnector.getLocalPort();
-        String request = "" +
-                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
-                "Host: " + hostPort + "\r\n" +
-                "\r\n";
-        Socket socket = newSocket();
-        try
-        {
-            OutputStream output = socket.getOutputStream();
-            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            // Expect 200 OK from the CONNECT request
-            Response response = readResponse(input);
-            assertEquals("200", response.getCode());
-
-            // Be sure the buffered input does not have anything buffered
-            assertFalse(input.ready());
-
-            // Upgrade the socket to SSL
-            SSLSocket sslSocket = wrapSocket(socket);
-            try
-            {
-                output = sslSocket.getOutputStream();
-                input = new BufferedReader(new InputStreamReader(sslSocket.getInputStream()));
-
-                request = "" +
-                        "GET /echo HTTP/1.1\r\n" +
-                        "Host: " + hostPort + "\r\n" +
-                        "\r\n";
-                output.write(request.getBytes("UTF-8"));
-                output.flush();
-
-                response = readResponse(input);
-                assertEquals("200", response.getCode());
-                assertEquals("GET /echo", response.getBody());
-            }
-            finally
-            {
-                sslSocket.close();
-            }
-        }
-        finally
-        {
-            socket.close();
-        }
-    }
-
-    @Test
-    public void testPOSTRequests() throws Exception
-    {
-        String hostPort = "localhost:" + serverConnector.getLocalPort();
-        String request = "" +
-                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
-                "Host: " + hostPort + "\r\n" +
-                "\r\n";
-        Socket socket = newSocket();
-        try
-        {
-            OutputStream output = socket.getOutputStream();
-            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            // Expect 200 OK from the CONNECT request
-            Response response = readResponse(input);
-            assertEquals("200", response.getCode());
-
-            // Be sure the buffered input does not have anything buffered
-            assertFalse(input.ready());
-
-            // Upgrade the socket to SSL
-            SSLSocket sslSocket = wrapSocket(socket);
-            try
-            {
-                output = sslSocket.getOutputStream();
-                input = new BufferedReader(new InputStreamReader(sslSocket.getInputStream()));
-
-                for (int i = 0; i < 10; ++i)
-                {
-                    request = "" +
-                            "POST /echo?param=" + i + " HTTP/1.1\r\n" +
-                            "Host: " + hostPort + "\r\n" +
-                            "Content-Length: 5\r\n" +
-                            "\r\n" +
-                            "HELLO";
-                    output.write(request.getBytes("UTF-8"));
-                    output.flush();
-
-                    response = readResponse(input);
-                    assertEquals("200", response.getCode());
-                    assertEquals("POST /echo?param=" + i + "\r\nHELLO", response.getBody());
-                }
-            }
-            finally
-            {
-                sslSocket.close();
-            }
-        }
-        finally
-        {
-            socket.close();
-        }
-    }
-
-    private SSLSocket wrapSocket(Socket socket) throws Exception
-    {
-        SSLContext sslContext = SSLContext.getInstance("SSLv3");
-        sslContext.init(null, new TrustManager[]{new AlwaysTrustManager()}, new SecureRandom());
-        SSLSocketFactory socketFactory = sslContext.getSocketFactory();
-        SSLSocket sslSocket = (SSLSocket)socketFactory.createSocket(socket, socket.getInetAddress().getHostAddress(), socket.getPort(), true);
-        sslSocket.setUseClientMode(true);
-        sslSocket.startHandshake();
-        return sslSocket;
-    }
-
-    private class AlwaysTrustManager implements X509TrustManager
-    {
-        public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException
-        {
-        }
-
-        public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException
-        {
-        }
-
-        public X509Certificate[] getAcceptedIssuers()
-        {
-            return null;
-        }
-    }
-
-    private static class ServerHandler extends AbstractHandler
-    {
-        public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
-        {
-            request.setHandled(true);
-
-            String uri = httpRequest.getRequestURI();
-            if ("/echo".equals(uri))
-            {
-                StringBuilder builder = new StringBuilder();
-                builder.append(httpRequest.getMethod()).append(" ").append(uri);
-                if (httpRequest.getQueryString() != null)
-                    builder.append("?").append(httpRequest.getQueryString());
-
-                ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                InputStream input = httpRequest.getInputStream();
-                int read = -1;
-                while ((read = input.read()) >= 0)
-                    baos.write(read);
-                baos.close();
-
-                ServletOutputStream output = httpResponse.getOutputStream();
-                output.println(builder.toString());
-                output.write(baos.toByteArray());
-            }
-            else
-            {
-                throw new ServletException();
-            }
-        }
-    }
-}

Deleted: jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ProxyHandlerConnectTest.java
===================================================================
--- jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ProxyHandlerConnectTest.java	2010-10-23 07:02:17 UTC (rev 2389)
+++ jetty/trunk/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ProxyHandlerConnectTest.java	2010-10-23 07:02:35 UTC (rev 2390)
@@ -1,517 +0,0 @@
-package org.eclipse.jetty.server.handler;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.Socket;
-import java.nio.channels.SocketChannel;
-import java.util.concurrent.ConcurrentMap;
-import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.jetty.io.Buffer;
-import org.eclipse.jetty.io.EndPoint;
-import org.eclipse.jetty.server.Request;
-import org.eclipse.jetty.server.nio.SelectChannelConnector;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * @version $Revision$ $Date$
- */
-public class ProxyHandlerConnectTest extends AbstractProxyHandlerTest
-{
-    @BeforeClass
-    public static void init() throws Exception
-    {
-        startServer(new SelectChannelConnector(), new ServerHandler());
-        startProxy();
-    }
-
-    @Test
-    public void testCONNECT() throws Exception
-    {
-        String hostPort = "localhost:" + serverConnector.getLocalPort();
-        String request = "" +
-                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
-                "Host: " + hostPort + "\r\n" +
-                "\r\n";
-        Socket socket = newSocket();
-        try
-        {
-            OutputStream output = socket.getOutputStream();
-            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            // Expect 200 OK from the CONNECT request
-            Response response = readResponse(input);
-            assertEquals("200", response.getCode());
-        }
-        finally
-        {
-            socket.close();
-        }
-    }
-
-    @Test
-    public void testCONNECTAndGET() throws Exception
-    {
-        String hostPort = "localhost:" + serverConnector.getLocalPort();
-        String request = "" +
-                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
-                "Host: " + hostPort + "\r\n" +
-                "\r\n";
-        Socket socket = newSocket();
-        try
-        {
-            OutputStream output = socket.getOutputStream();
-            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            // Expect 200 OK from the CONNECT request
-            Response response = readResponse(input);
-            assertEquals("200", response.getCode());
-
-            request = "" +
-                    "GET /echo" + " HTTP/1.1\r\n" +
-                    "Host: " + hostPort + "\r\n" +
-                    "\r\n";
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            response = readResponse(input);
-            assertEquals("200", response.getCode());
-            assertEquals("GET /echo", response.getBody());
-        }
-        finally
-        {
-            socket.close();
-        }
-    }
-
-    @Test
-    public void testCONNECT10AndGET() throws Exception
-    {
-        String hostPort = "localhost:" + serverConnector.getLocalPort();
-        String request = "" +
-                "CONNECT " + hostPort + " HTTP/1.0\r\n" +
-                "Host: " + hostPort + "\r\n" +
-                "\r\n";
-        Socket socket = newSocket();
-        try
-        {
-            OutputStream output = socket.getOutputStream();
-            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            // Expect 200 OK from the CONNECT request
-            Response response = readResponse(input);
-            assertEquals("200", response.getCode());
-
-            request = "" +
-                    "GET /echo" + " HTTP/1.1\r\n" +
-                    "Host: " + hostPort + "\r\n" +
-                    "\r\n";
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            response = readResponse(input);
-            assertEquals("200", response.getCode());
-            assertEquals("GET /echo", response.getBody());
-        }
-        finally
-        {
-            socket.close();
-        }
-    }
-
-    @Test
-    public void testCONNECTAndGETPipelined() throws Exception
-    {
-        String hostPort = "localhost:" + serverConnector.getLocalPort();
-        String request = "" +
-                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
-                "Host: " + hostPort + "\r\n" +
-                "\r\n" +
-                "GET /echo" + " HTTP/1.1\r\n" +
-                "Host: " + hostPort + "\r\n" +
-                "\r\n";
-        Socket socket = newSocket();
-        try
-        {
-            OutputStream output = socket.getOutputStream();
-            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            // Expect 200 OK from the CONNECT request
-            Response response = readResponse(input);
-            assertEquals("200", response.getCode());
-
-            // The pipelined request must have gone up to the server as is
-            response = readResponse(input);
-            assertEquals("200", response.getCode());
-            assertEquals("GET /echo", response.getBody());
-        }
-        finally
-        {
-            socket.close();
-        }
-    }
-
-    @Test
-    public void testCONNECTAndMultipleGETs() throws Exception
-    {
-        String hostPort = "localhost:" + serverConnector.getLocalPort();
-        String request = "" +
-                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
-                "Host: " + hostPort + "\r\n" +
-                "\r\n";
-        Socket socket = newSocket();
-        try
-        {
-            OutputStream output = socket.getOutputStream();
-            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            // Expect 200 OK from the CONNECT request
-            Response response = readResponse(input);
-            assertEquals("200", response.getCode());
-
-            for (int i = 0; i < 10; ++i)
-            {
-                request = "" +
-                        "GET /echo" + " HTTP/1.1\r\n" +
-                        "Host: " + hostPort + "\r\n" +
-                        "\r\n";
-                output.write(request.getBytes("UTF-8"));
-                output.flush();
-
-                response = readResponse(input);
-                assertEquals("200", response.getCode());
-                assertEquals("GET /echo", response.getBody());
-            }
-        }
-        finally
-        {
-            socket.close();
-        }
-    }
-
-    @Test
-    public void testCONNECTAndGETServerStop() throws Exception
-    {
-        String hostPort = "localhost:" + serverConnector.getLocalPort();
-        String request = "" +
-                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
-                "Host: " + hostPort + "\r\n" +
-                "\r\n";
-        Socket socket = newSocket();
-        try
-        {
-            OutputStream output = socket.getOutputStream();
-            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            // Expect 200 OK from the CONNECT request
-            Response response = readResponse(input);
-            assertEquals("200", response.getCode());
-
-            request = "" +
-                    "GET /echo HTTP/1.1\r\n" +
-                    "Host: " + hostPort + "\r\n" +
-                    "\r\n";
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            response = readResponse(input);
-            assertEquals("200", response.getCode());
-            assertEquals("GET /echo", response.getBody());
-
-            // Idle server is shut down
-            stopServer();
-
-            int read = input.read();
-            assertEquals(-1, read);
-        }
-        finally
-        {
-            socket.close();
-            // Restart the server for the next test
-            server.start();
-        }
-    }
-
-    @Test
-    public void testCONNECTAndGETAndServerSideClose() throws Exception
-    {
-        String hostPort = "localhost:" + serverConnector.getLocalPort();
-        String request = "" +
-                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
-                "Host: " + hostPort + "\r\n" +
-                "\r\n";
-        Socket socket = newSocket();
-        try
-        {
-            OutputStream output = socket.getOutputStream();
-            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            // Expect 200 OK from the CONNECT request
-            Response response = readResponse(input);
-            assertEquals("200", response.getCode());
-
-            request = "" +
-                    "GET /close HTTP/1.1\r\n" +
-                    "Host: " + hostPort + "\r\n" +
-                    "\r\n";
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            int read = input.read();
-            assertEquals(-1, read);
-        }
-        finally
-        {
-            socket.close();
-        }
-    }
-
-    @Test
-    public void testCONNECTAndPOSTAndGET() throws Exception
-    {
-        String hostPort = "localhost:" + serverConnector.getLocalPort();
-        String request = "" +
-                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
-                "Host: " + hostPort + "\r\n" +
-                "\r\n";
-        Socket socket = newSocket();
-        try
-        {
-            OutputStream output = socket.getOutputStream();
-            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            // Expect 200 OK from the CONNECT request
-            Response response = readResponse(input);
-            assertEquals("200", response.getCode());
-
-            request = "" +
-                    "POST /echo HTTP/1.1\r\n" +
-                    "Host: " + hostPort + "\r\n" +
-                    "Content-Length: 5\r\n" +
-                    "\r\n" +
-                    "HELLO";
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            response = readResponse(input);
-            assertEquals("200", response.getCode());
-            assertEquals("POST /echo\r\nHELLO", response.getBody());
-
-            request = "" +
-                    "GET /echo" + " HTTP/1.1\r\n" +
-                    "Host: " + hostPort + "\r\n" +
-                    "\r\n";
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            response = readResponse(input);
-            assertEquals("200", response.getCode());
-            assertEquals("GET /echo", response.getBody());
-        }
-        finally
-        {
-            socket.close();
-        }
-    }
-
-    @Test
-    public void testCONNECTAndPOSTWithBigBody() throws Exception
-    {
-        String hostPort = "localhost:" + serverConnector.getLocalPort();
-        String request = "" +
-                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
-                "Host: " + hostPort + "\r\n" +
-                "\r\n";
-        Socket socket = newSocket();
-        try
-        {
-            OutputStream output = socket.getOutputStream();
-            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            // Expect 200 OK from the CONNECT request
-            Response response = readResponse(input);
-            assertEquals("200", response.getCode());
-
-            StringBuilder body = new StringBuilder();
-            String chunk = "0123456789ABCDEF";
-            for (int i = 0; i < 1024; ++i)
-                body.append(chunk);
-
-            request = "" +
-                    "POST /echo HTTP/1.1\r\n" +
-                    "Host: " + hostPort + "\r\n" +
-                    "Content-Length: " + body.length() + "\r\n" +
-                    "\r\n" +
-                    body;
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            response = readResponse(input);
-            assertEquals("200", response.getCode());
-            assertEquals("POST /echo\r\n" + body, response.getBody());
-        }
-        finally
-        {
-            socket.close();
-        }
-    }
-
-    @Test
-    public void testCONNECTAndPOSTWithContext() throws Exception
-    {
-        final String contextKey = "contextKey";
-        final String contextValue = "contextValue";
-
-        // Replace the default ProxyHandler with a subclass to test context information passing
-        stopProxy();
-        proxy.setHandler(new ConnectHandler()
-        {
-            @Override
-            protected boolean handleAuthentication(HttpServletRequest request, HttpServletResponse response, String address) throws ServletException, IOException
-            {
-                request.setAttribute(contextKey, contextValue);
-                return super.handleAuthentication(request, response, address);
-            }
-
-            @Override
-            protected SocketChannel connect(HttpServletRequest request, String host, int port) throws IOException
-            {
-                assertEquals(contextValue, request.getAttribute(contextKey));
-                return super.connect(request, host, port);
-            }
-
-            @Override
-            protected void prepareContext(HttpServletRequest request, ConcurrentMap<String, Object> context)
-            {
-                // Transfer data from the HTTP request to the connection context
-                assertEquals(contextValue, request.getAttribute(contextKey));
-                context.put(contextKey, request.getAttribute(contextKey));
-            }
-
-            @Override
-            protected int read(EndPoint endPoint, Buffer buffer, ConcurrentMap<String, Object> context) throws IOException
-            {
-                assertEquals(contextValue, context.get(contextKey));
-                return super.read(endPoint, buffer, context);
-            }
-
-            @Override
-            protected int write(EndPoint endPoint, Buffer buffer, ConcurrentMap<String, Object> context) throws IOException
-            {
-                assertEquals(contextValue, context.get(contextKey));
-                return super.write(endPoint, buffer, context);
-            }
-        });
-        proxy.start();
-
-        String hostPort = "localhost:" + serverConnector.getLocalPort();
-        String request = "" +
-                "CONNECT " + hostPort + " HTTP/1.1\r\n" +
-                "Host: " + hostPort + "\r\n" +
-                "\r\n";
-        Socket socket = newSocket();
-        try
-        {
-            OutputStream output = socket.getOutputStream();
-            BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            // Expect 200 OK from the CONNECT request
-            Response response = readResponse(input);
-            assertEquals("200", response.getCode());
-
-            String body = "0123456789ABCDEF";
-            request = "" +
-                    "POST /echo HTTP/1.1\r\n" +
-                    "Host: " + hostPort + "\r\n" +
-                    "Content-Length: " + body.length() + "\r\n" +
-                    "\r\n" +
-                    body;
-            output.write(request.getBytes("UTF-8"));
-            output.flush();
-
-            response = readResponse(input);
-            assertEquals("200", response.getCode());
-            assertEquals("POST /echo\r\n" + body, response.getBody());
-        }
-        finally
-        {
-            socket.close();
-        }
-    }
-
-    private static class ServerHandler extends AbstractHandler
-    {
-        public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
-        {
-            request.setHandled(true);
-
-            String uri = httpRequest.getRequestURI();
-            if ("/echo".equals(uri))
-            {
-                StringBuilder builder = new StringBuilder();
-                builder.append(httpRequest.getMethod()).append(" ").append(uri);
-                if (httpRequest.getQueryString() != null)
-                    builder.append("?").append(httpRequest.getQueryString());
-
-                ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                InputStream input = httpRequest.getInputStream();
-                int read = -1;
-                while ((read = input.read()) >= 0)
-                    baos.write(read);
-                baos.close();
-
-                ServletOutputStream output = httpResponse.getOutputStream();
-                output.println(builder.toString());
-                output.write(baos.toByteArray());
-            }
-            else if ("/close".equals(uri))
-            {
-                request.getConnection().getEndPoint().close();
-            }
-            else
-            {
-                throw new ServletException();
-            }
-        }
-    }
-}