Package org.apache.commons.httpclient.server

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


   
    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

            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 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.setKeepAlive(true);
                }
            }
View Full Code Here

     */
    public void testNoncompliantPostMethodString() 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("Connection: close");
                out.println("Content-Length: 0");
                out.println();
                out.flush();
                return true;
            }
        });

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

     */
    public void testNoncompliantStatusLine() {
        this.server.setRequestHandler(new HttpRequestHandler() {
            public boolean processRequest(SimpleHttpServerConnection conn,
                    SimpleRequest request) throws IOException {
                ResponseWriter out = conn.getWriter();
                out.println("HTTP/1.1 444 This status message contains\n"
                        + " a newline and a\r"
                        + " carrage return but that should be OK.");
                out.println("Connection: close");
                out.println("Content-Length: 0");
                out.println();
                out.flush();
                return true;
            }
        });
        GetMethod method = new GetMethod("/");
        try {
View Full Code Here

    public void testNoncompliantHeadWithResponseBody() throws Exception {
        final String body = "Test body";
        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();
                out.print(body);
                out.flush();
                return true;
            }
        });
        HeadMethod method = new HeadMethod("/");
        method.getParams().setIntParameter(
View Full Code Here

    public void testNoncompliantHeadStrictMode() throws Exception {
        final String body = "Test body";
        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();
                out.print(body);
                out.flush();
                return true;
            }
        });
        client.getParams().setBooleanParameter(
                HttpMethodParams.REJECT_HEAD_BODY, true);
View Full Code Here

    public void testMalformed304Response() 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 304 OK");
                out.println("Connection: keep-alive");
                out.println("Content-Length: 100");
                out.println();
                out.flush();
                conn.setKeepAlive(true);
                return true;
            }
        });
View Full Code Here

    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

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.