Search in sources :

Example 16 with TesterAccessLogValve

use of org.apache.catalina.valves.TesterAccessLogValve in project tomcat by apache.

the class TestAsyncContextImpl method testBug50753.

@Test
public void testBug50753() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    Bug50753Servlet servlet = new Bug50753Servlet();
    Wrapper wrapper = Tomcat.addServlet(ctx, "servlet", servlet);
    wrapper.setAsyncSupported(true);
    ctx.addServletMappingDecoded("/", "servlet");
    TesterAccessLogValve alv = new TesterAccessLogValve();
    ctx.getPipeline().addValve(alv);
    tomcat.start();
    // Call the servlet once
    Map<String, List<String>> headers = new LinkedHashMap<>();
    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() + "/", bc, headers);
    assertEquals(200, rc);
    assertEquals("OK", bc.toString());
    List<String> testHeader = headers.get("A");
    assertNotNull(testHeader);
    assertEquals(1, testHeader.size());
    assertEquals("xyz", testHeader.get(0));
    // Check the access log
    alv.validateAccessLog(1, 200, Bug50753Servlet.THREAD_SLEEP_TIME, Bug50753Servlet.THREAD_SLEEP_TIME + REQUEST_TIME);
}
Also used : AsyncContext(javax.servlet.AsyncContext) Context(org.apache.catalina.Context) TesterContext(org.apache.tomcat.unittest.TesterContext) Wrapper(org.apache.catalina.Wrapper) ServletResponseWrapper(javax.servlet.ServletResponseWrapper) ServletRequestWrapper(javax.servlet.ServletRequestWrapper) Tomcat(org.apache.catalina.startup.Tomcat) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) List(java.util.List) TesterAccessLogValve(org.apache.catalina.valves.TesterAccessLogValve) LinkedHashMap(java.util.LinkedHashMap) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Aggregations

AsyncContext (javax.servlet.AsyncContext)16 Context (org.apache.catalina.Context)16 Tomcat (org.apache.catalina.startup.Tomcat)16 TesterAccessLogValve (org.apache.catalina.valves.TesterAccessLogValve)16 TesterContext (org.apache.tomcat.unittest.TesterContext)15 ServletRequestWrapper (javax.servlet.ServletRequestWrapper)14 ServletResponseWrapper (javax.servlet.ServletResponseWrapper)14 Wrapper (org.apache.catalina.Wrapper)14 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)11 Test (org.junit.Test)11 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)9 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 ErrorPage (org.apache.tomcat.util.descriptor.web.ErrorPage)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Socket (java.net.Socket)1 HashMap (java.util.HashMap)1 SocketFactory (javax.net.SocketFactory)1