Search in sources :

Example 11 with SimpleRequest

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

the class TestResponseHeaders method testFoldedHeaders.

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);
    assertEquals("close", method.getResponseHeader("Connection").getValue());
    assertEquals(body.length(), Integer.parseInt(method.getResponseHeader("Content-Length").getValue()));
    assertEquals("text/xml; charset=utf-8 boundary=XXXX", method.getResponseHeader("Content-Type").getValue());
    assertEquals("Wed, 28 Mar 2001 05:05:04 GMT", method.getResponseHeader("Date").getValue());
    assertEquals("UserLand Frontier/7.0-WinNT", method.getResponseHeader("Server").getValue());
    assertTrue(method.getResponseHeader("Content-Type").toString().indexOf("boundary") != -1);
}
Also used : HttpRequestHandler(org.apache.commons.httpclient.server.HttpRequestHandler) ResponseWriter(org.apache.commons.httpclient.server.ResponseWriter) SimpleHttpServerConnection(org.apache.commons.httpclient.server.SimpleHttpServerConnection) GetMethod(org.apache.commons.httpclient.methods.GetMethod) SimpleRequest(org.apache.commons.httpclient.server.SimpleRequest) IOException(java.io.IOException)

Example 12 with SimpleRequest

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

the class TestResponseHeaders method testProxyNoContentLength.

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("/");
    client.executeMethod(method);
    method.getResponseBodyAsString();
    assertFalse(connectionManager.getConection().isOpen());
}
Also used : HttpRequestHandler(org.apache.commons.httpclient.server.HttpRequestHandler) ResponseWriter(org.apache.commons.httpclient.server.ResponseWriter) SimpleHttpServerConnection(org.apache.commons.httpclient.server.SimpleHttpServerConnection) GetMethod(org.apache.commons.httpclient.methods.GetMethod) SimpleRequest(org.apache.commons.httpclient.server.SimpleRequest) IOException(java.io.IOException)

Example 13 with SimpleRequest

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

the class TestResponseHeaders method testForceCloseConnection.

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);
    assertTrue("Connection should be closed", method.shouldCloseConnection(connectionManager.getConection()));
    assertTrue("Connection should be force-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 14 with SimpleRequest

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

the class TestResponseHeaders method testNullHeaders.

public void testNullHeaders() 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.setBodyString("XXX\r\nYYY\r\nZZZ");
            return true;
        }
    });
    HttpMethod method = new GetMethod("/");
    client.executeMethod(method);
    assertEquals(null, method.getResponseHeader(null));
    assertEquals(null, method.getResponseHeader("bogus"));
}
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 15 with SimpleRequest

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

the class TestResponseHeaders method testInvalidContentLength2.

public void testInvalidContentLength2() 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("Content-Length", "stuff"));
            response.addHeader(new Header("Content-Length", "5"));
            response.setBodyString("12345");
            return true;
        }
    });
    GetMethod method = new GetMethod("/");
    client.executeMethod(method);
    assertEquals(5, method.getResponseContentLength());
}
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)

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