use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestApplicationHttpRequest method doQueryStringTest.
private void doQueryStringTest(String originalQueryString, String forwardQueryString, Map<String, String[]> expected) throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
if (forwardQueryString == null) {
Tomcat.addServlet(ctx, "forward", new ForwardServlet("/display"));
} else {
Tomcat.addServlet(ctx, "forward", new ForwardServlet("/display?" + forwardQueryString));
}
ctx.addServletMappingDecoded("/forward", "forward");
Tomcat.addServlet(ctx, "display", new DisplayParameterServlet(expected));
ctx.addServletMappingDecoded("/display", "display");
tomcat.start();
ByteChunk response = new ByteChunk();
StringBuilder target = new StringBuilder("http://localhost:");
target.append(getPort());
target.append("/forward");
if (originalQueryString != null) {
target.append('?');
target.append(originalQueryString);
}
int rc = getUrl(target.toString(), response, null);
Assert.assertEquals(200, rc);
Assert.assertEquals("OK", response.toString());
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestApplicationMapping method doTestMappingNamedInclude.
private void doTestMappingNamedInclude(String contextPath, String mapping, String requestPath, String matchValue, String matchType) throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext(contextPath, null);
Tomcat.addServlet(ctx, "Include", new NamedIncludeServlet());
ctx.addServletMappingDecoded(mapping, "Include");
Tomcat.addServlet(ctx, "Mapping", new MappingServlet());
ctx.addServletMappingDecoded("/mapping", "Mapping");
tomcat.start();
ByteChunk bc = getUrl("http://localhost:" + getPort() + contextPath + requestPath);
String body = bc.toString();
Assert.assertTrue(body, body.contains("MatchValue=[" + matchValue + "]"));
Assert.assertTrue(body, body.contains("Pattern=[" + mapping + "]"));
Assert.assertTrue(body, body.contains("MatchType=[" + matchType + "]"));
Assert.assertTrue(body, body.contains("ServletName=[Include]"));
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestApplicationMapping method doTestMappingInclude.
private void doTestMappingInclude(String contextPath, String mapping, String requestPath, String matchValue, String matchType) throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext(contextPath, null);
Tomcat.addServlet(ctx, "Include", new IncludeServlet());
ctx.addServletMappingDecoded(mapping, "Include");
Tomcat.addServlet(ctx, "Mapping", new MappingServlet());
ctx.addServletMappingDecoded("/mapping", "Mapping");
tomcat.start();
ByteChunk bc = getUrl("http://localhost:" + getPort() + contextPath + requestPath);
String body = bc.toString();
Assert.assertTrue(body, body.contains("MatchValue=[" + matchValue + "]"));
Assert.assertTrue(body, body.contains("Pattern=[" + mapping + "]"));
Assert.assertTrue(body, body.contains("MatchType=[" + matchType + "]"));
Assert.assertTrue(body, body.contains("ServletName=[Include]"));
Assert.assertTrue(body, body.contains("IncludeMatchValue=[mapping]"));
Assert.assertTrue(body, body.contains("IncludePattern=[/mapping]"));
Assert.assertTrue(body, body.contains("IncludeMatchType=[EXACT]"));
Assert.assertTrue(body, body.contains("IncludeServletName=[Mapping]"));
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestApplicationMapping method doTestMappingNamedForward.
private void doTestMappingNamedForward(String contextPath, String mapping, String requestPath, String matchValue, String matchType) throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext(contextPath, null);
Tomcat.addServlet(ctx, "Forward", new NamedForwardServlet());
ctx.addServletMappingDecoded(mapping, "Forward");
Tomcat.addServlet(ctx, "Mapping", new MappingServlet());
ctx.addServletMappingDecoded("/mapping", "Mapping");
tomcat.start();
ByteChunk bc = getUrl("http://localhost:" + getPort() + contextPath + requestPath);
String body = bc.toString();
Assert.assertTrue(body, body.contains("MatchValue=[" + matchValue + "]"));
Assert.assertTrue(body, body.contains("Pattern=[" + mapping + "]"));
Assert.assertTrue(body, body.contains("MatchType=[" + matchType + "]"));
Assert.assertTrue(body, body.contains("ServletName=[Forward]"));
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestAsyncContextImpl method testBug49567.
@Test
public void testBug49567() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Bug49567Servlet servlet = new Bug49567Servlet();
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
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
assertEquals("OK", bc.toString());
// Give the async thread a chance to finish (but not too long)
int counter = 0;
while (!servlet.isDone() && counter < 10) {
Thread.sleep(1000);
counter++;
}
assertEquals("1false2true3true4true5false", servlet.getResult());
// Check the access log
alv.validateAccessLog(1, 200, Bug49567Servlet.THREAD_SLEEP_TIME, Bug49567Servlet.THREAD_SLEEP_TIME + REQUEST_TIME);
}
Aggregations