Search in sources :

Example 16 with SimpleRequest

use of org.apache.commons.httpclient.server.SimpleRequest 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 17 with SimpleRequest

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

the class TestResponseHeaders method testDuplicateConnection.

public void testDuplicateConnection() throws Exception {
    this.server.setHttpService(new HttpService() {

        public boolean process(SimpleRequest request, SimpleResponse response) throws IOException {
            response.setStatusLine(request.getRequestLine().getHttpVersion(), 200);
            response.addHeader(new Header("Connection", "close"));
            response.addHeader(new Header("Connection", "close"));
            return true;
        }
    });
    GetMethod method = new GetMethod("/");
    client.executeMethod(method);
    method.getResponseBodyAsString();
    assertFalse(connectionManager.getConection().isOpen());
    this.server.setHttpService(new HttpService() {

        public boolean process(SimpleRequest request, SimpleResponse response) throws IOException {
            response.setStatusLine(HttpVersion.HTTP_1_0, 200);
            response.addHeader(new Header("Connection", "keep-alive"));
            response.addHeader(new Header("Connection", "keep-alive"));
            response.setBodyString("aa");
            return true;
        }
    });
    method = new GetMethod("/");
    client.executeMethod(method);
    method.getResponseBodyAsString();
    assertTrue(connectionManager.getConection().isOpen());
}
Also used : HttpService(org.apache.commons.httpclient.server.HttpService) SimpleResponse(org.apache.commons.httpclient.server.SimpleResponse) GetMethod(org.apache.commons.httpclient.methods.GetMethod) SimpleRequest(org.apache.commons.httpclient.server.SimpleRequest) IOException(java.io.IOException)

Example 18 with SimpleRequest

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

the class TestResponseHeaders method testDuplicateContentLength.

/**
 * Tests that having a duplicate content length causes no problems.
 */
public void testDuplicateContentLength() throws Exception {
    final String body = "XXX\r\nYYY\r\nZZZ";
    this.server.setHttpService(new HttpService() {

        public boolean process(SimpleRequest request, SimpleResponse response) throws IOException {
            response.setStatusLine(request.getRequestLine().getHttpVersion(), 200);
            response.addHeader(new Header("Content-Length", Integer.toString(body.length())));
            response.addHeader(new Header("Content-Length", Integer.toString(body.length())));
            response.setBodyString(body);
            return true;
        }
    });
    HttpMethod method = new GetMethod();
    client.executeMethod(method);
    assertNotNull("Response body is null.", method.getResponseBodyAsStream());
}
Also used : HttpService(org.apache.commons.httpclient.server.HttpService) SimpleResponse(org.apache.commons.httpclient.server.SimpleResponse) GetMethod(org.apache.commons.httpclient.methods.GetMethod) SimpleRequest(org.apache.commons.httpclient.server.SimpleRequest) IOException(java.io.IOException)

Example 19 with SimpleRequest

use of org.apache.commons.httpclient.server.SimpleRequest 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 20 with SimpleRequest

use of org.apache.commons.httpclient.server.SimpleRequest 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)

Aggregations

IOException (java.io.IOException)23 SimpleRequest (org.apache.commons.httpclient.server.SimpleRequest)23 HttpRequestHandler (org.apache.commons.httpclient.server.HttpRequestHandler)17 SimpleHttpServerConnection (org.apache.commons.httpclient.server.SimpleHttpServerConnection)17 ResponseWriter (org.apache.commons.httpclient.server.ResponseWriter)15 GetMethod (org.apache.commons.httpclient.methods.GetMethod)10 SimpleResponse (org.apache.commons.httpclient.server.SimpleResponse)7 HttpService (org.apache.commons.httpclient.server.HttpService)6 SimpleHttpServer (org.apache.commons.httpclient.server.SimpleHttpServer)4 SimpleServer (org.eclipse.ecf.internal.tests.filetransfer.httpserver.SimpleServer)4 FileTransferJob (org.eclipse.ecf.filetransfer.FileTransferJob)3 IFileTransferListener (org.eclipse.ecf.filetransfer.IFileTransferListener)3 IFileTransferConnectStartEvent (org.eclipse.ecf.filetransfer.events.IFileTransferConnectStartEvent)3 IIncomingFileTransferReceiveStartEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)1 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 UserCancelledException (org.eclipse.ecf.filetransfer.UserCancelledException)1 IIncomingFileTransferReceiveDoneEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent)1