Search in sources :

Example 1 with SimpleHttpClient

use of org.apache.catalina.startup.SimpleHttpClient in project tomcat by apache.

the class TestCoyoteAdapter method testBug54928.

@Test
public void testBug54928() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    AsyncServlet servlet = new AsyncServlet();
    Wrapper w = Tomcat.addServlet(ctx, "async", servlet);
    w.setAsyncSupported(true);
    ctx.addServletMappingDecoded("/async", "async");
    tomcat.start();
    SimpleHttpClient client = new SimpleHttpClient() {

        @Override
        public boolean isResponseBodyOK() {
            return true;
        }
    };
    String request = "GET /async HTTP/1.1" + SimpleHttpClient.CRLF + "Host: a" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF;
    client.setPort(getPort());
    client.setRequest(new String[] { request });
    client.connect();
    client.sendRequest();
    for (int i = 0; i < 10; i++) {
        String line = client.readLine();
        if (line != null && line.length() > 20) {
            log.info(line.subSequence(0, 20) + "...");
        }
    }
    client.disconnect();
    // Wait for server thread to stop
    Thread t = servlet.getThread();
    long startTime = System.nanoTime();
    t.join(5000);
    long endTime = System.nanoTime();
    log.info("Waited for servlet thread to stop for " + (endTime - startTime) / 1000000 + " ms");
    Assert.assertTrue(servlet.isCompleted());
}
Also used : Context(org.apache.catalina.Context) AsyncContext(javax.servlet.AsyncContext) Wrapper(org.apache.catalina.Wrapper) Tomcat(org.apache.catalina.startup.Tomcat) SimpleHttpClient(org.apache.catalina.startup.SimpleHttpClient) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Aggregations

AsyncContext (javax.servlet.AsyncContext)1 Context (org.apache.catalina.Context)1 Wrapper (org.apache.catalina.Wrapper)1 SimpleHttpClient (org.apache.catalina.startup.SimpleHttpClient)1 Tomcat (org.apache.catalina.startup.Tomcat)1 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)1 Test (org.junit.Test)1