use of org.apache.catalina.Wrapper in project tomcat by apache.
the class TestAsyncContextImpl method doTestDispatchError.
private void doTestDispatchError(int iter, boolean useThread, boolean completeOnError) throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
DispatchingServlet dispatch = new DispatchingServlet(true, completeOnError);
Wrapper wrapper = Tomcat.addServlet(ctx, "dispatch", dispatch);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/stage1", "dispatch");
ErrorServlet error = new ErrorServlet();
Tomcat.addServlet(ctx, "error", error);
ctx.addServletMappingDecoded("/stage2", "error");
ctx.addApplicationListener(TrackingRequestListener.class.getName());
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
StringBuilder url = new StringBuilder(48);
url.append("http://localhost:");
url.append(getPort());
url.append("/stage1?iter=");
url.append(iter);
if (useThread) {
url.append("&useThread=y");
}
getUrl(url.toString());
StringBuilder expected = new StringBuilder("requestInitialized-");
int loop = iter;
while (loop > 0) {
expected.append("DispatchingServletGet-");
if (loop != iter) {
expected.append("onStartAsync-");
}
loop--;
}
expected.append("ErrorServletGet-onError-onComplete-requestDestroyed");
// Request may complete before listener has finished processing so wait
// up to 5 seconds for the right response
String expectedTrack = expected.toString();
int count = 0;
while (!expectedTrack.equals(getTrack()) && count < 100) {
Thread.sleep(50);
count++;
}
assertEquals(expectedTrack, getTrack());
// Check the access log
alv.validateAccessLog(1, 500, 0, REQUEST_TIME);
}
use of org.apache.catalina.Wrapper in project tomcat by apache.
the class TestAsyncContextImpl method doTestAsyncISE.
private void doTestAsyncISE(boolean useGetRequest) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncISEServlet servlet = new AsyncISEServlet();
Wrapper w = Tomcat.addServlet(ctx, "AsyncISEServlet", servlet);
w.setAsyncSupported(true);
ctx.addServletMappingDecoded("/test", "AsyncISEServlet");
tomcat.start();
ByteChunk response = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() + "/test", response, null);
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
boolean hasIse = false;
try {
if (useGetRequest) {
servlet.getAsyncContext().getRequest();
} else {
servlet.getAsyncContext().getResponse();
}
} catch (IllegalStateException ise) {
hasIse = true;
}
Assert.assertTrue(hasIse);
}
use of org.apache.catalina.Wrapper in project tomcat by apache.
the class TestAsyncContextImpl method testBug53337.
@Test
public void testBug53337() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Wrapper a = Tomcat.addServlet(ctx, "ServletA", new Bug53337ServletA());
a.setAsyncSupported(true);
Wrapper b = Tomcat.addServlet(ctx, "ServletB", new Bug53337ServletB());
b.setAsyncSupported(true);
Tomcat.addServlet(ctx, "ServletC", new Bug53337ServletC());
ctx.addServletMappingDecoded("/ServletA", "ServletA");
ctx.addServletMappingDecoded("/ServletB", "ServletB");
ctx.addServletMappingDecoded("/ServletC", "ServletC");
tomcat.start();
StringBuilder url = new StringBuilder(48);
url.append("http://localhost:");
url.append(getPort());
url.append("/ServletA");
ByteChunk body = new ByteChunk();
int rc = getUrl(url.toString(), body, null);
assertEquals(HttpServletResponse.SC_OK, rc);
assertEquals("OK", body.toString());
}
use of org.apache.catalina.Wrapper in project tomcat by apache.
the class TestAsyncContextImpl method doTestDispatch.
private void doTestDispatch(int iter, boolean useThread) throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
DispatchingServlet dispatch = new DispatchingServlet(false, false);
Wrapper wrapper = Tomcat.addServlet(ctx, "dispatch", dispatch);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/stage1", "dispatch");
NonAsyncServlet nonasync = new NonAsyncServlet();
Wrapper wrapper2 = Tomcat.addServlet(ctx, "nonasync", nonasync);
wrapper2.setAsyncSupported(true);
ctx.addServletMappingDecoded("/stage2", "nonasync");
ctx.addApplicationListener(TrackingRequestListener.class.getName());
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
StringBuilder url = new StringBuilder(48);
url.append("http://localhost:");
url.append(getPort());
url.append("/stage1?iter=");
url.append(iter);
if (useThread) {
url.append("&useThread=y");
}
getUrl(url.toString());
StringBuilder expected = new StringBuilder("requestInitialized-");
int loop = iter;
while (loop > 0) {
expected.append("DispatchingServletGet-");
loop--;
}
expected.append("NonAsyncServletGet-");
expected.append("requestDestroyed");
// Request may complete before listener has finished processing so wait
// up to 5 seconds for the right response
String expectedTrack = expected.toString();
int count = 0;
while (!expectedTrack.equals(getTrack()) && count < 100) {
Thread.sleep(50);
count++;
}
assertEquals(expectedTrack, getTrack());
// Check the access log
alv.validateAccessLog(1, 200, 0, REQUEST_TIME);
}
use of org.apache.catalina.Wrapper in project tomcat by apache.
the class TestAsyncContextImpl method testBug50352.
@Test
public void testBug50352() throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncStartRunnable servlet = new AsyncStartRunnable();
Wrapper wrapper = Tomcat.addServlet(ctx, "servlet", servlet);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/", "servlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
getUrl("http://localhost:" + getPort() + "/");
// Request may complete before listener has finished processing so wait
// up to 5 seconds for the right response
String expectedTrack = "Runnable-onComplete-";
int count = 0;
while (!expectedTrack.equals(getTrack()) && count < 100) {
Thread.sleep(50);
count++;
}
assertEquals(expectedTrack, getTrack());
// Check the access log
alv.validateAccessLog(1, 200, AsyncStartRunnable.THREAD_SLEEP_TIME, AsyncStartRunnable.THREAD_SLEEP_TIME + REQUEST_TIME);
}
Aggregations