Search in sources :

Example 16 with ByteChunk

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());
}
Also used : Context(org.apache.catalina.Context) AsyncContext(javax.servlet.AsyncContext) Tomcat(org.apache.catalina.startup.Tomcat) ByteChunk(org.apache.tomcat.util.buf.ByteChunk)

Example 17 with ByteChunk

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());
}
Also used : Context(org.apache.catalina.Context) AsyncContext(javax.servlet.AsyncContext) Tomcat(org.apache.catalina.startup.Tomcat) ByteChunk(org.apache.tomcat.util.buf.ByteChunk)

Example 18 with ByteChunk

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>"));
}
Also used : ByteChunk(org.apache.tomcat.util.buf.ByteChunk) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 19 with ByteChunk

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);
}
Also used : Context(org.apache.catalina.Context) AsyncContext(javax.servlet.AsyncContext) Wrapper(org.apache.catalina.Wrapper) Tomcat(org.apache.catalina.startup.Tomcat) ByteChunk(org.apache.tomcat.util.buf.ByteChunk)

Example 20 with ByteChunk

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());
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Aggregations

ByteChunk (org.apache.tomcat.util.buf.ByteChunk)274 Test (org.junit.Test)201 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)180 Tomcat (org.apache.catalina.startup.Tomcat)129 Context (org.apache.catalina.Context)98 File (java.io.File)49 List (java.util.List)48 AsyncContext (javax.servlet.AsyncContext)40 HashMap (java.util.HashMap)35 Wrapper (org.apache.catalina.Wrapper)22 StandardContext (org.apache.catalina.core.StandardContext)21 ArrayList (java.util.ArrayList)20 TesterContext (org.apache.tomcat.unittest.TesterContext)18 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)16 ServletRequestWrapper (javax.servlet.ServletRequestWrapper)13 ServletResponseWrapper (javax.servlet.ServletResponseWrapper)13 ServletContext (javax.servlet.ServletContext)10 WsContextListener (org.apache.tomcat.websocket.server.WsContextListener)10 TesterAccessLogValve (org.apache.catalina.valves.TesterAccessLogValve)9 InitialContext (javax.naming.InitialContext)8