use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestCoyoteAdapter method pathParamExtensionTest.
private void pathParamExtensionTest(String path, String expected) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("/testapp", null);
Tomcat.addServlet(ctx, "servlet", new PathParamServlet());
ctx.addServletMappingDecoded("*.txt", "servlet");
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + path);
Assert.assertEquals(expected, res.toString());
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestCoyoteAdapter method doTestUriDecoding.
private void doTestUriDecoding(String path, String encoding, String expectedPathInfo) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
tomcat.getConnector().setURIEncoding(encoding);
// No file system docBase required
Context ctx = tomcat.addContext("", null);
PathInfoServlet servlet = new PathInfoServlet();
Tomcat.addServlet(ctx, "servlet", servlet);
ctx.addServletMappingDecoded("/*", "servlet");
tomcat.start();
int rc = getUrl("http://localhost:" + getPort() + path, new ByteChunk(), null);
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
Assert.assertEquals(expectedPathInfo, servlet.getPathInfo());
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestApplicationContext method testBug53467.
@Test
public void testBug53467() throws Exception {
getTomcatInstanceTestWebapp(false, true);
ByteChunk res = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() + "/test/bug5nnnn/bug53467].jsp", res, null);
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
Assert.assertTrue(res.toString().contains("<p>OK</p>"));
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestApplicationContextGetRequestDispatcher method doTestGetRequestDispatcher.
private void doTestGetRequestDispatcher(boolean useEncodedDispatchPaths, String startPath, String startQueryString, String dispatchPath, String targetPath, String expectedBody) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("/test", null);
ctx.setDispatchersUseEncodedPaths(useEncodedDispatchPaths);
// Add a default servlet to return 404 for not found resources
Tomcat.addServlet(ctx, "Default", new Default404Servlet());
ctx.addServletMappingDecoded("/*", "Default");
// Add a target servlet to dispatch to
Tomcat.addServlet(ctx, "target", new TargetServlet());
ctx.addServletMappingDecoded(UDecoder.URLDecode(targetPath, "UTF-8"), "target");
if (useAsync) {
Wrapper w = Tomcat.addServlet(ctx, "rd", new AsyncDispatcherServlet(dispatchPath, useEncodedDispatchPaths));
w.setAsyncSupported(true);
} else {
Tomcat.addServlet(ctx, "rd", new DispatcherServlet(dispatchPath));
}
ctx.addServletMappingDecoded(UDecoder.URLDecode(startPath, "UTF-8"), "rd");
tomcat.start();
StringBuilder url = new StringBuilder("http://localhost:");
url.append(getPort());
url.append("/test");
url.append(startPath);
if (startQueryString != null) {
url.append('?');
url.append(startQueryString);
}
ByteChunk bc = getUrl(url.toString());
String body = bc.toString();
Assert.assertEquals(expectedBody, body);
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestApplicationHttpRequest method testParameterImmutability.
@Test
public void testParameterImmutability() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Tomcat.addServlet(ctx, "forward", new ForwardServlet("/modify"));
ctx.addServletMappingDecoded("/forward", "forward");
Tomcat.addServlet(ctx, "modify", new ModifyParameterServlet());
ctx.addServletMappingDecoded("/modify", "modify");
tomcat.start();
ByteChunk response = new ByteChunk();
StringBuilder target = new StringBuilder("http://localhost:");
target.append(getPort());
target.append("/forward");
int rc = getUrl(target.toString(), response, null);
Assert.assertEquals(200, rc);
Assert.assertEquals("OK", response.toString());
}
Aggregations