Package org.apache.commons.httpclient.server

Examples of org.apache.commons.httpclient.server.ResponseWriter


    public void testMalformed204Response() throws Exception {
        this.server.setRequestHandler(new HttpRequestHandler() {
            public boolean processRequest(SimpleHttpServerConnection conn,
                    SimpleRequest request) throws IOException {
                conn.setSocketTimeout(20000);
                ResponseWriter out = conn.getWriter();
                out.println("HTTP/1.1 204 OK");
                out.println("Connection: close");
                out.println("Content-Length: 100");
                out.println();
                out.flush();
                conn.setKeepAlive(true);
                return true;
            }
        });
View Full Code Here


            final String garbage = "garbage!\r\n"
            final long count = 1000000000

            HttpVersion httpversion = request.getRequestLine().getHttpVersion();
            ResponseWriter out = conn.getWriter();
            out.println(httpversion + " 200 OK");
            out.println("Content-Type: text/plain");
            out.println("Content-Length: " + count * garbage.length()) ;
            out.println("Connection: close");
            out.println();
            for (int i = 0; i < count; i++) {
                out.print(garbage);
            }
            return true;
        }
View Full Code Here

    public void testNoContentLength() throws Exception {
        // test with connection header
        this.server.setRequestHandler(new HttpRequestHandler() {
            public boolean processRequest(SimpleHttpServerConnection conn,
                    SimpleRequest request) throws IOException {
                ResponseWriter out = conn.getWriter();
                out.println("HTTP/1.1 200 OK");
                out.println("Connection: keep-alive");
                out.println();
                out.println("12345");
                out.flush();
                return true;
            }
        });

        GetMethod method = new GetMethod("/");
        client.executeMethod(method);
        method.getResponseBodyAsString();
       
        assertFalse(connectionManager.getConection().isOpen());
       
        // test without connection header
        this.server.setRequestHandler(new HttpRequestHandler() {
            public boolean processRequest(SimpleHttpServerConnection conn,
                    SimpleRequest request) throws IOException {
                ResponseWriter out = conn.getWriter();
                out.println("HTTP/1.1 200 OK");
                out.println();
                out.println("12345");
                out.flush();
                return true;
            }
        });

        // test with connection header
View Full Code Here

    public void testProxyNoContentLength() throws Exception {
        // test with proxy-connection header
        this.server.setRequestHandler(new HttpRequestHandler() {
            public boolean processRequest(SimpleHttpServerConnection conn,
                    SimpleRequest request) throws IOException {
                ResponseWriter out = conn.getWriter();
                out.println("HTTP/1.1 200 OK");
                out.println("proxy-connection: keep-alive");
                out.println();
                out.println("12345");
                out.flush();
                return true;
            }
        });

        client.getHostConfiguration().setProxy(server.getLocalAddress(), server.getLocalPort());
        GetMethod method = new GetMethod("/");
        client.executeMethod(method);
        method.getResponseBodyAsString();
       
        assertFalse(connectionManager.getConection().isOpen());

        // test without proxy-connection header
        this.server.setRequestHandler(new HttpRequestHandler() {
            public boolean processRequest(SimpleHttpServerConnection conn,
                    SimpleRequest request) throws IOException {
                ResponseWriter out = conn.getWriter();
                out.println("HTTP/1.1 200 OK");
                out.println();
                out.println("12345");
                out.flush();
                return true;
            }
        });

        method = new GetMethod("/");
View Full Code Here

    public void testFoldedHeaders() throws Exception {
        final String body = "XXX\r\nYYY\r\nZZZ";
        this.server.setRequestHandler(new HttpRequestHandler() {
            public boolean processRequest(SimpleHttpServerConnection conn,
                    SimpleRequest request) throws IOException {
                ResponseWriter out = conn.getWriter();
                out.println("HTTP/1.1 200 OK");
                out.println("Connection: close");
                out.println("Content-Length: " + body.length());
                out.println("Content-Type: text/xml; charset=utf-8");
                out.println("\tboundary=XXXX");
                out.println("Date: Wed, 28 Mar 2001");
                out.println(" 05:05:04 GMT");
                out.println("Server: UserLand Frontier/7.0-WinNT");
                out.println();
                out.println(body);
                out.flush();
                return true;
            }
        });
        HttpMethod method = new GetMethod("/");
        client.executeMethod(method);
View Full Code Here

    public void testForceCloseConnection() throws Exception {
        this.server.setRequestHandler(new HttpRequestHandler() {
            public boolean processRequest(SimpleHttpServerConnection conn,
                    SimpleRequest request) throws IOException {
                ResponseWriter out = conn.getWriter();
                out.println("HTTP/1.1 200 OK");
                out.println("Content-Type: garbage");
                out.println();
                out.println("stuff");
                out.flush();
                return true;
            }
        });
        FakeHttpMethod method = new FakeHttpMethod();
        client.executeMethod(method);
View Full Code Here

   
    public void testForceCloseConnection2() throws Exception {
        this.server.setRequestHandler(new HttpRequestHandler() {
            public boolean processRequest(SimpleHttpServerConnection conn,
                    SimpleRequest request) throws IOException {
                ResponseWriter out = conn.getWriter();
                out.println("HTTP/1.1 200 OK");
                out.println("Content-Type: garbage");
                out.println("Connection: close");
                out.println();
                out.println("stuff");
                out.flush();
                return true;
            }
        });
        FakeHttpMethod method = new FakeHttpMethod();
        client.executeMethod(method);
View Full Code Here

    public void testNoContent() throws Exception {
        // test with connection header
        this.server.setRequestHandler(new HttpRequestHandler() {
            public boolean processRequest(SimpleHttpServerConnection conn,
                    SimpleRequest request) throws IOException {
                ResponseWriter out = conn.getWriter();
                out.println("HTTP/1.1 204 NO CONTENT");
                out.println();
                out.flush();
                return true;
            }
        });

        GetMethod method = new GetMethod("/");
        client.executeMethod(method);
        method.getResponseBodyAsString();

        assertTrue(connectionManager.getConection().isOpen());

        // test without connection header
        this.server.setRequestHandler(new HttpRequestHandler() {
            public boolean processRequest(SimpleHttpServerConnection conn,
                    SimpleRequest request) throws IOException {
                ResponseWriter out = conn.getWriter();
                out.println("HTTP/1.1 204 NO CONTENT");
                out.println("Connection: keep-alive");
                out.println();
                out.flush();
                return true;
            }
        });

        // test with connection header
View Full Code Here

            final String garbage = "garbage!\r\n"
            final long count = 1000000000

            String protocol = request.getRequestLine().getProtocol();
            ResponseWriter out = conn.getWriter();
            out.println(protocol + " 200 OK");
            out.println("Content-Type: text/plain");
            out.println("Content-Length: " + count * garbage.length()) ;
            out.println("Connection: close");
            out.println();
            for (int i = 0; i < count; i++) {
                out.print(garbage);
            }
            return true;
        }
View Full Code Here

        public boolean processRequest(
            final SimpleHttpServerConnection conn,
            final SimpleRequest request) throws IOException
        {
            RequestLine requestLine = request.getRequestLine();
            ResponseWriter out = conn.getWriter();
            if ("GET".equals(requestLine.getMethod())
                && "/".equals(requestLine.getUri())) {

                requestNo++;

                out.println("HTTP/1.1 200 OK");
                out.println("Content-Type: text/html");
                out.println("Content-Length: 5");
                out.println("Connection: keep-alive");
                out.println();
                out.println("12345"); // send exactly 5 bytes

                // and some more garbage!
                out.println("AND SOME MORE\r\nGARBAGE!");
                out.println("HTTP/1.0 404 Not Found");
                out.println("Content-Type: text/plain");
                out.println("");
                out.println("THIS-IS-A-FAKE-RESPONSE!");

                out.flush();
                // process max. 2 subsequents requests per connection
                if (requestNo < 2) {
                    conn.connectionKeepAlive();
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.server.ResponseWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.