Search in sources :

Example 21 with SimpleRequest

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

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

Example 23 with SimpleRequest

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

the class TestConnectionPersistence method testRequestConnClose.

public void testRequestConnClose() throws Exception {
    this.server.setRequestHandler(new HttpRequestHandler() {

        public boolean processRequest(final SimpleHttpServerConnection conn, final SimpleRequest request) throws IOException {
            // Make sure the request if fully consumed
            request.getBodyBytes();
            SimpleResponse response = new SimpleResponse();
            response.setStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK);
            response.setBodyString("stuff back");
            conn.setKeepAlive(true);
            conn.writeResponse(response);
            return true;
        }
    });
    AccessibleHttpConnectionManager connman = new AccessibleHttpConnectionManager();
    this.client.getParams().setVersion(HttpVersion.HTTP_1_0);
    this.client.setHttpConnectionManager(connman);
    PostMethod httppost = new PostMethod("/test/");
    httppost.setRequestHeader("Connection", "close");
    httppost.setRequestEntity(new StringRequestEntity("stuff"));
    try {
        this.client.executeMethod(httppost);
    } finally {
        httppost.releaseConnection();
    }
    assertFalse(connman.getConection().isOpen());
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) HttpRequestHandler(org.apache.commons.httpclient.server.HttpRequestHandler) PostMethod(org.apache.commons.httpclient.methods.PostMethod) SimpleResponse(org.apache.commons.httpclient.server.SimpleResponse) 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