org.apache.catalina.startup.SimpleHttpClient Java Examples

The following examples show how to use org.apache.catalina.startup.SimpleHttpClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestHttp11Processor.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testWithUnknownExpectation() throws Exception {
    getTomcatInstanceTestWebapp(false, true);

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Expect: unknown" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF;

    Client client = new Client(getPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    Assert.assertTrue(client.isResponse417());
}
 
Example #2
Source File: TestHttp11Processor.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testWithTEVoid() throws Exception {
    getTomcatInstanceTestWebapp(false, true);

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: void" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
                SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(getPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    Assert.assertTrue(client.isResponse501());
}
 
Example #3
Source File: TestHttp11Processor.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testWithTEBuffered() throws Exception {
    getTomcatInstanceTestWebapp(false, true);

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: buffered" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
                SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(getPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    Assert.assertTrue(client.isResponse501());
}
 
Example #4
Source File: TestHttp11Processor.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void doTestWithTEChunked(boolean withCL) throws Exception {

        getTomcatInstanceTestWebapp(false, true);

        String request =
            "POST /test/echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
            "Host: any" + SimpleHttpClient.CRLF +
            (withCL ? "Content-length: 1" + SimpleHttpClient.CRLF : "") +
            "Transfer-encoding: chunked" + SimpleHttpClient.CRLF +
            "Content-Type: application/x-www-form-urlencoded" +
                    SimpleHttpClient.CRLF +
            "Connection: close" + SimpleHttpClient.CRLF +
            SimpleHttpClient.CRLF +
            "9" + SimpleHttpClient.CRLF +
            "test=data" + SimpleHttpClient.CRLF +
            "0" + SimpleHttpClient.CRLF +
            SimpleHttpClient.CRLF;

        Client client = new Client(getPort());
        client.setRequest(new String[] {request});

        client.connect();
        client.processRequest();
        Assert.assertTrue(client.isResponse200());
        Assert.assertTrue(client.getResponseBody().contains("test - data"));
    }
 
Example #5
Source File: TestHttp11Processor.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testWithTEIdentity() throws Exception {
    getTomcatInstanceTestWebapp(false, true);

    String request =
        "POST /test/echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: identity" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        "Connection: close" + SimpleHttpClient.CRLF +
            SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(getPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    Assert.assertTrue(client.isResponse200());
    Assert.assertTrue(client.getResponseBody().contains("test - data"));
}
 
Example #6
Source File: TestHttp11Processor.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testWithTESavedRequest() throws Exception {
    getTomcatInstanceTestWebapp(false, true);

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: savedrequest" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
                SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(getPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    Assert.assertTrue(client.isResponse501());
}
 
Example #7
Source File: TestHttp11Processor.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testWithTEUnsupported() throws Exception {
    getTomcatInstanceTestWebapp(false, true);

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: unsupported" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
                SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(getPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    Assert.assertTrue(client.isResponse501());
}
 
Example #8
Source File: TestAbstractHttp11Processor.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithUnknownExpectation() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Expect: unknoen" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF;

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse417());
}
 
Example #9
Source File: TestAbstractHttp11Processor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTEIdentity() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: identity" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        "Connection: close" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse200());
    assertTrue(client.getResponseBody().contains("test - data"));
}
 
Example #10
Source File: TestAbstractHttp11Processor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testResponseWithErrorChunked() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctxt = tomcat.addContext("", null);

    // Add protected servlet
    Tomcat.addServlet(ctxt, "ChunkedResponseWithErrorServlet",
            new ResponseWithErrorServlet(true));
    ctxt.addServletMapping("/*", "ChunkedResponseWithErrorServlet");

    tomcat.start();

    String request =
            "GET /anything HTTP/1.1" + SimpleHttpClient.CRLF +
            "Host: any" + SimpleHttpClient.CRLF +
             SimpleHttpClient.CRLF;

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();

    // Expected response is a 200 response followed by an incomplete chunked
    // body.
    assertTrue(client.isResponse200());
    // There should not be an end chunk
    assertFalse(client.getResponseBody().endsWith("0"));
    // The last portion of text should be there
    assertTrue(client.getResponseBody().endsWith("line03"));
}
 
Example #11
Source File: TestAbstractHttp11Processor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTESavedRequest() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: savedrequest" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse501());
}
 
Example #12
Source File: TestAbstractHttp11Processor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTEUnsupported() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: unsupported" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse501());
}
 
Example #13
Source File: TestChunkedInputFilter.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testNoTrailingHeaders() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Tomcat.addServlet(ctx, "servlet", new EchoHeaderServlet(true));
    ctx.addServletMappingDecoded("/", "servlet");

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: chunked" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        "Connection: close" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "3" + SimpleHttpClient.CRLF +
        "a=0" + SimpleHttpClient.CRLF +
        "4" + SimpleHttpClient.CRLF +
        "&b=1" + SimpleHttpClient.CRLF +
        "0" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF;

    TrailerClient client =
            new TrailerClient(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    Assert.assertEquals("nullnull7nullnull", client.getResponseBody());
}
 
Example #14
Source File: TestInternalInputBuffer.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testBug51557Continuation() {

    Bug51557Client client = new Bug51557Client("X-Bug=51557NoColon",
            "foo" + SimpleHttpClient.CRLF + " bar");

    client.doRequest();
    assertTrue(client.isResponse200());
    assertEquals("abcd", client.getResponseBody());
    assertTrue(client.isResponseBodyOK());
}
 
Example #15
Source File: TestChunkedInputFilter.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoTrailingHeaders() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Tomcat.addServlet(ctx, "servlet", new EchoHeaderServlet(true));
    ctx.addServletMapping("/", "servlet");

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: chunked" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        "Connection: close" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "3" + SimpleHttpClient.CRLF +
        "a=0" + SimpleHttpClient.CRLF +
        "4" + SimpleHttpClient.CRLF +
        "&b=1" + SimpleHttpClient.CRLF +
        "0" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF;

    TrailerClient client =
            new TrailerClient(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertEquals("nullnull7nullnull", client.getResponseBody());
}
 
Example #16
Source File: TestChunkedInputFilter.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoTrailingHeaders() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Tomcat.addServlet(ctx, "servlet", new EchoHeaderServlet(true));
    ctx.addServletMapping("/", "servlet");

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: chunked" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        "Connection: close" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "3" + SimpleHttpClient.CRLF +
        "a=0" + SimpleHttpClient.CRLF +
        "4" + SimpleHttpClient.CRLF +
        "&b=1" + SimpleHttpClient.CRLF +
        "0" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF;

    TrailerClient client =
            new TrailerClient(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertEquals("nullnull7nullnull", client.getResponseBody());
}
 
Example #17
Source File: TestHttp11Processor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testBlankHostHeader02() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // This setting means the connection will be closed at the end of the
    // request
    tomcat.getConnector().setAttribute("maxKeepAliveRequests", "1");

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    // Add servlet
    Tomcat.addServlet(ctx, "TesterServlet", new ServerNameTesterServlet());
    ctx.addServletMappingDecoded("/foo", "TesterServlet");

    tomcat.start();

    String request =
            "GET /foo HTTP/1.1" + SimpleHttpClient.CRLF +
            "Host:      " + SimpleHttpClient.CRLF +
             SimpleHttpClient.CRLF;

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();

    // Expected response is a 200 response.
    Assert.assertTrue(client.isResponse200());
    Assert.assertEquals("request.getServerName() is [] and request.getServerPort() is " + getPort(), client.getResponseBody());
}
 
Example #18
Source File: TestHttp11Processor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testMissingHostHeader() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // This setting means the connection will be closed at the end of the
    // request
    tomcat.getConnector().setAttribute("maxKeepAliveRequests", "1");

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    // Add servlet
    Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
    ctx.addServletMappingDecoded("/foo", "TesterServlet");

    tomcat.start();

    String request =
            "GET /foo HTTP/1.1" + SimpleHttpClient.CRLF +
             SimpleHttpClient.CRLF;

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();

    // Expected response is a 400 response.
    Assert.assertTrue(client.isResponse400());
}
 
Example #19
Source File: TestHttp11Processor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testInconsistentHostHeader01() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // This setting means the connection will be closed at the end of the
    // request
    tomcat.getConnector().setAttribute("maxKeepAliveRequests", "1");

    tomcat.getConnector().setAttribute("allowHostHeaderMismatch", "false");

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    // Add servlet
    Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
    ctx.addServletMappingDecoded("/foo", "TesterServlet");

    tomcat.start();

    String request =
            "GET http://a/foo HTTP/1.1" + SimpleHttpClient.CRLF +
            "Host: b" + SimpleHttpClient.CRLF +
             SimpleHttpClient.CRLF;

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();

    // Expected response is a 400 response.
    Assert.assertTrue(client.isResponse400());
}
 
Example #20
Source File: TestAbstractHttp11Processor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private void doTestWithTEChunked(boolean withCL)
        throws Exception {

    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        (withCL ? "Content-length: 1" + SimpleHttpClient.CRLF : "") +
        "Transfer-encoding: chunked" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        "Connection: close" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "9" + SimpleHttpClient.CRLF +
        "test=data" + SimpleHttpClient.CRLF +
        "0" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF;

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse200());
    assertTrue(client.getResponseBody().contains("test - data"));
}
 
Example #21
Source File: TestAbstractHttp11Processor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTEBuffered() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: buffered" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse501());
}
 
Example #22
Source File: TestAbstractHttp11Processor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTEVoid() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: void" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse501());
}
 
Example #23
Source File: TestAbstractHttp11Processor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTEUnsupported() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: unsupported" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse501());
}
 
Example #24
Source File: TestHttp11Processor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testConsistentHostHeader02() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // This setting means the connection will be closed at the end of the
    // request
    tomcat.getConnector().setAttribute("maxKeepAliveRequests", "1");

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    // Add servlet
    Tomcat.addServlet(ctx, "TesterServlet", new ServerNameTesterServlet());
    ctx.addServletMappingDecoded("/foo", "TesterServlet");

    tomcat.start();

    String request =
            "GET http://a:8080/foo HTTP/1.1" + SimpleHttpClient.CRLF +
            "Host: a:8080" + SimpleHttpClient.CRLF +
             SimpleHttpClient.CRLF;

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();

    // Expected response is a 200 response.
    Assert.assertTrue(client.isResponse200());
    Assert.assertEquals("request.getServerName() is [a] and request.getServerPort() is 8080", client.getResponseBody());

}
 
Example #25
Source File: TestAbstractHttp11Processor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testResponseWithErrorChunked() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctxt = tomcat.addContext("", null);

    // Add protected servlet
    Tomcat.addServlet(ctxt, "ChunkedResponseWithErrorServlet",
            new ResponseWithErrorServlet(true));
    ctxt.addServletMapping("/*", "ChunkedResponseWithErrorServlet");

    tomcat.start();

    String request =
            "GET /anything HTTP/1.1" + SimpleHttpClient.CRLF +
            "Host: any" + SimpleHttpClient.CRLF +
             SimpleHttpClient.CRLF;

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();

    // Expected response is a 200 response followed by an incomplete chunked
    // body.
    assertTrue(client.isResponse200());
    // There should not be an end chunk
    assertFalse(client.getResponseBody().endsWith("0"));
    // The last portion of text should be there
    assertTrue(client.getResponseBody().endsWith("line03"));
}
 
Example #26
Source File: TestAbstractHttp11Processor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTEVoid() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: void" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse501());
}
 
Example #27
Source File: TestAbstractHttp11Processor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTEBuffered() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: buffered" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse501());
}
 
Example #28
Source File: TestAbstractHttp11Processor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private void doTestWithTEChunked(boolean withCL)
        throws Exception {

    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        (withCL ? "Content-length: 1" + SimpleHttpClient.CRLF : "") +
        "Transfer-encoding: chunked" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        "Connection: close" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "9" + SimpleHttpClient.CRLF +
        "test=data" + SimpleHttpClient.CRLF +
        "0" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF;

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse200());
    assertTrue(client.getResponseBody().contains("test - data"));
}
 
Example #29
Source File: TestAbstractHttp11Processor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTEIdentity() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: identity" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        "Connection: close" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse200());
    assertTrue(client.getResponseBody().contains("test - data"));
}
 
Example #30
Source File: TestAbstractHttp11Processor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTESavedRequest() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: savedrequest" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse501());
}