use of org.apache.catalina.Wrapper in project tomcat by apache.
the class TestAsyncContextImpl method prepareApplicationWithGenericServlet.
private void prepareApplicationWithGenericServlet(String contextPath) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext(contextPath, null);
DispatchingGenericServlet dispatch = new DispatchingGenericServlet();
Wrapper wrapper = Tomcat.addServlet(ctx, "dispatch", dispatch);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/dispatch", "dispatch");
CustomGenericServlet customGeneric = new CustomGenericServlet();
Wrapper wrapper2 = Tomcat.addServlet(ctx, "customGeneric", customGeneric);
wrapper2.setAsyncSupported(true);
ctx.addServletMappingDecoded("/target", "customGeneric");
tomcat.start();
}
use of org.apache.catalina.Wrapper in project tomcat by apache.
the class TestAsyncContextImpl method testBug54178.
@Test
public void testBug54178() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Bug54178ServletA bug54178ServletA = new Bug54178ServletA();
Wrapper wrapper = Tomcat.addServlet(ctx, "bug54178ServletA", bug54178ServletA);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/bug54178ServletA", "bug54178ServletA");
Bug54178ServletB bug54178ServletB = new Bug54178ServletB();
Tomcat.addServlet(ctx, "bug54178ServletB", bug54178ServletB);
ctx.addServletMappingDecoded("/bug54178ServletB", "bug54178ServletB");
tomcat.start();
ByteChunk body = new ByteChunk();
int rc = -1;
try {
rc = getUrl("http://localhost:" + getPort() + "/bug54178ServletA?" + Bug54178ServletA.PARAM_NAME + "=bar", body, null);
} catch (IOException ioe) {
// This may happen if test fails. Output the exception in case it is
// useful and let asserts handle the failure
ioe.printStackTrace();
}
assertEquals(HttpServletResponse.SC_OK, rc);
body.recycle();
rc = getUrl("http://localhost:" + getPort() + "/bug54178ServletB", 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 testForbiddenDispatching.
@Test
public void testForbiddenDispatching() throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
NonAsyncServlet nonAsyncServlet = new NonAsyncServlet();
Wrapper wrapper = Tomcat.addServlet(ctx, "nonAsyncServlet", nonAsyncServlet);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/target", "nonAsyncServlet");
DispatchingGenericServlet forbiddenDispatchingServlet = new DispatchingGenericServlet();
Wrapper wrapper1 = Tomcat.addServlet(ctx, "forbiddenDispatchingServlet", forbiddenDispatchingServlet);
wrapper1.setAsyncSupported(true);
ctx.addServletMappingDecoded("/forbiddenDispatchingServlet", "forbiddenDispatchingServlet");
tomcat.start();
try {
getUrl("http://localhost:" + getPort() + "/forbiddenDispatchingServlet");
} catch (IOException ioe) {
// This may happen if test fails. Output the exception in case it is
// useful and let asserts handle the failure
ioe.printStackTrace();
}
// Request may complete before listener has finished processing so wait
// up to 5 seconds for the right response
String expectedTrack = "OKNonAsyncServletGet-";
int count = 0;
while (!expectedTrack.equals(getTrack()) && count < 100) {
Thread.sleep(50);
count++;
}
Assert.assertEquals(expectedTrack, getTrack());
}
use of org.apache.catalina.Wrapper in project tomcat by apache.
the class TestCoyoteOutputStream method doNonBlockingTest.
private void doNonBlockingTest(int asyncWriteTarget, int syncWriteTarget, boolean useContainerThreadToSetListener) throws Exception {
Tomcat tomcat = getTomcatInstance();
Context root = tomcat.addContext("", TEMP_DIR);
Wrapper w = Tomcat.addServlet(root, "nbWrite", new NonBlockingWriteServlet(asyncWriteTarget, useContainerThreadToSetListener));
w.setAsyncSupported(true);
root.addServletMappingDecoded("/nbWrite", "nbWrite");
Tomcat.addServlet(root, "write", new BlockingWriteServlet(asyncWriteTarget, syncWriteTarget));
w.setAsyncSupported(true);
root.addServletMappingDecoded("/write", "write");
tomcat.start();
ByteChunk bc = new ByteChunk();
// Extend timeout to 5 mins for debugging
int rc = getUrl("http://localhost:" + getPort() + "/nbWrite", bc, 300000, null, null);
int totalCount = asyncWriteTarget + syncWriteTarget;
StringBuilder sb = new StringBuilder(totalCount * 16);
for (int i = 0; i < totalCount; i++) {
sb.append("OK - " + i + System.lineSeparator());
}
String expected = null;
if (sb.length() > 0) {
expected = sb.toString();
}
Assert.assertEquals(200, rc);
Assert.assertEquals(expected, bc.toString());
}
use of org.apache.catalina.Wrapper in project tomcat by apache.
the class TestHttp11Processor method testRequestBodySwallowing.
/*
* Tests what happens if a request is completed during a dispatch but the
* request body has not been fully read.
*/
@Test
public void testRequestBodySwallowing() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
DispatchingServlet servlet = new DispatchingServlet();
Wrapper w = Tomcat.addServlet(ctx, "Test", servlet);
w.setAsyncSupported(true);
ctx.addServletMappingDecoded("/test", "Test");
tomcat.start();
// Hand-craft the client so we have complete control over the timing
SocketAddress addr = new InetSocketAddress("localhost", getPort());
Socket socket = new Socket();
socket.setSoTimeout(300000);
socket.connect(addr, 300000);
OutputStream os = socket.getOutputStream();
Writer writer = new OutputStreamWriter(os, "ISO-8859-1");
InputStream is = socket.getInputStream();
Reader r = new InputStreamReader(is, "ISO-8859-1");
BufferedReader reader = new BufferedReader(r);
// Write the headers
writer.write("POST /test HTTP/1.1\r\n");
writer.write("Host: localhost:8080\r\n");
writer.write("Transfer-Encoding: chunked\r\n");
writer.write("\r\n");
writer.flush();
validateResponse(reader);
// Write the request body
writer.write("2\r\n");
writer.write("AB\r\n");
writer.write("0\r\n");
writer.write("\r\n");
writer.flush();
// Write the 2nd request
writer.write("POST /test HTTP/1.1\r\n");
writer.write("Host: localhost:8080\r\n");
writer.write("Transfer-Encoding: chunked\r\n");
writer.write("\r\n");
writer.flush();
// Read the 2nd response
validateResponse(reader);
// Write the 2nd request body
writer.write("2\r\n");
writer.write("AB\r\n");
writer.write("0\r\n");
writer.write("\r\n");
writer.flush();
// Done
socket.close();
}
Aggregations