Search in sources :

Example 11 with ResponseWriter

use of org.apache.commons.httpclient.server.ResponseWriter in project ecf by eclipse.

the class TestResponseHeaders method testForceCloseConnection2.

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);
    assertTrue("Connection should be closed", method.shouldCloseConnection(connectionManager.getConection()));
    assertFalse("Connection should NOT be closed", method.isConnectionCloseForced());
}
Also used : HttpRequestHandler(org.apache.commons.httpclient.server.HttpRequestHandler) ResponseWriter(org.apache.commons.httpclient.server.ResponseWriter) SimpleHttpServerConnection(org.apache.commons.httpclient.server.SimpleHttpServerConnection) SimpleRequest(org.apache.commons.httpclient.server.SimpleRequest) IOException(java.io.IOException)

Example 12 with ResponseWriter

use of org.apache.commons.httpclient.server.ResponseWriter in project ecf by eclipse.

the class TestNoncompliant method testNoncompliantHeadWithResponseBody.

/**
 * Test if a response to HEAD method from non-compliant server that contains
 * an unexpected body content can be correctly redirected
 */
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(HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, 50);
    client.executeMethod(method);
    assertEquals(200, method.getStatusCode());
    method.releaseConnection();
}
Also used : HttpRequestHandler(org.apache.commons.httpclient.server.HttpRequestHandler) ResponseWriter(org.apache.commons.httpclient.server.ResponseWriter) SimpleHttpServerConnection(org.apache.commons.httpclient.server.SimpleHttpServerConnection) SimpleRequest(org.apache.commons.httpclient.server.SimpleRequest) IOException(java.io.IOException)

Example 13 with ResponseWriter

use of org.apache.commons.httpclient.server.ResponseWriter in project ecf by eclipse.

the class TestNoncompliant method testNoncompliantPostMethodString.

/**
 * Tests if client is able to recover gracefully when HTTP server or
 * proxy fails to send 100 status code when expected. The client should
 * resume sending the request body after a defined timeout without having
 * received "continue" code.
 */
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("/");
    method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
    method.setRequestEntity(new StringRequestEntity("This is data to be sent in the body of an HTTP POST."));
    client.executeMethod(method);
    assertEquals(200, method.getStatusCode());
}
Also used : HttpRequestHandler(org.apache.commons.httpclient.server.HttpRequestHandler) ResponseWriter(org.apache.commons.httpclient.server.ResponseWriter) SimpleHttpServerConnection(org.apache.commons.httpclient.server.SimpleHttpServerConnection) SimpleRequest(org.apache.commons.httpclient.server.SimpleRequest) IOException(java.io.IOException)

Example 14 with ResponseWriter

use of org.apache.commons.httpclient.server.ResponseWriter in project ecf by eclipse.

the class TestNoncompliant method testMalformed204Response.

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;
        }
    });
    GetMethod method = new GetMethod("/");
    method.getParams().setSoTimeout(1000);
    client.executeMethod(method);
    assertEquals(HttpStatus.SC_NO_CONTENT, method.getStatusCode());
    method.getResponseBody();
}
Also used : HttpRequestHandler(org.apache.commons.httpclient.server.HttpRequestHandler) ResponseWriter(org.apache.commons.httpclient.server.ResponseWriter) SimpleHttpServerConnection(org.apache.commons.httpclient.server.SimpleHttpServerConnection) SimpleRequest(org.apache.commons.httpclient.server.SimpleRequest) IOException(java.io.IOException)

Example 15 with ResponseWriter

use of org.apache.commons.httpclient.server.ResponseWriter in project ecf by eclipse.

the class TestNoncompliant method testNoncompliantHeadStrictMode.

/**
 * Test if a response to HEAD method from non-compliant server causes an
 * HttpException to be thrown
 */
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);
    HeadMethod method = new NoncompliantHeadMethod("/");
    method.getParams().setIntParameter(HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, 50);
    try {
        client.executeMethod(method);
        fail("HttpException should have been thrown");
    } catch (HttpException e) {
    // Expected
    }
    method.releaseConnection();
}
Also used : HttpRequestHandler(org.apache.commons.httpclient.server.HttpRequestHandler) ResponseWriter(org.apache.commons.httpclient.server.ResponseWriter) SimpleHttpServerConnection(org.apache.commons.httpclient.server.SimpleHttpServerConnection) SimpleRequest(org.apache.commons.httpclient.server.SimpleRequest) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)15 HttpRequestHandler (org.apache.commons.httpclient.server.HttpRequestHandler)15 ResponseWriter (org.apache.commons.httpclient.server.ResponseWriter)15 SimpleHttpServerConnection (org.apache.commons.httpclient.server.SimpleHttpServerConnection)15 SimpleRequest (org.apache.commons.httpclient.server.SimpleRequest)15 GetMethod (org.apache.commons.httpclient.methods.GetMethod)4 SimpleHttpServer (org.apache.commons.httpclient.server.SimpleHttpServer)3 SimpleServer (org.eclipse.ecf.internal.tests.filetransfer.httpserver.SimpleServer)3 FileTransferJob (org.eclipse.ecf.filetransfer.FileTransferJob)2 IFileTransferListener (org.eclipse.ecf.filetransfer.IFileTransferListener)2 IFileTransferConnectStartEvent (org.eclipse.ecf.filetransfer.events.IFileTransferConnectStartEvent)2 IIncomingFileTransferReceiveStartEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent)2