Search in sources :

Example 56 with Wrapper

use of org.apache.catalina.Wrapper in project tomcat by apache.

the class TestELInJsp method doTestELMisc.

private void doTestELMisc(boolean quoteAttributeEL) throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // Create the context (don't use addWebapp as we want to modify the
    // JSP Servlet settings).
    File appDir = new File("test/webapp");
    StandardContext ctxt = (StandardContext) tomcat.addContext(null, "/test", appDir.getAbsolutePath());
    ctxt.addServletContainerInitializer(new JasperInitializer(), null);
    // Configure the defaults and then tweak the JSP servlet settings
    // Note: Min value for maxLoadedJsps is 2
    Tomcat.initWebappDefaults(ctxt);
    Wrapper w = (Wrapper) ctxt.findChild("jsp");
    String jspName;
    if (quoteAttributeEL) {
        jspName = "/test/el-misc-with-quote-attribute-el.jsp";
        w.addInitParameter("quoteAttributeEL", "true");
    } else {
        jspName = "/test/el-misc-no-quote-attribute-el.jsp";
        w.addInitParameter("quoteAttributeEL", "false");
    }
    tomcat.start();
    ByteChunk res = getUrl("http://localhost:" + getPort() + jspName);
    String result = res.toString();
    assertEcho(result, "00-\\\\\\\"${'hello world'}");
    assertEcho(result, "01-\\\\\\\"\\${'hello world'}");
    assertEcho(result, "02-\\\"${'hello world'}");
    assertEcho(result, "03-\\\"\\hello world");
    assertEcho(result, "2az-04");
    assertEcho(result, "05-a2z");
    assertEcho(result, "06-az2");
    assertEcho(result, "2az-07");
    assertEcho(result, "08-a2z");
    assertEcho(result, "09-az2");
    assertEcho(result, "10-${'foo'}bar");
    assertEcho(result, "11-\\\"}");
    assertEcho(result, "12-foo\\bar\\baz");
    assertEcho(result, "13-foo\\bar\\baz");
    assertEcho(result, "14-foo\\bar\\baz");
    assertEcho(result, "15-foo\\bar\\baz");
    assertEcho(result, "16-foo\\bar\\baz");
    assertEcho(result, "17-foo\\'bar'\\"baz"");
    assertEcho(result, "18-3");
    assertEcho(result, "19-4");
    assertEcho(result, "20-4");
    assertEcho(result, "21-[{value=11}, {value=12}, {value=13}, {value=14}]");
    assertEcho(result, "22-[{value=11}, {value=12}, {value=13}, {value=14}]");
}
Also used : Wrapper(org.apache.catalina.Wrapper) Tomcat(org.apache.catalina.startup.Tomcat) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) StandardContext(org.apache.catalina.core.StandardContext) File(java.io.File) JasperInitializer(org.apache.jasper.servlet.JasperInitializer)

Example 57 with Wrapper

use of org.apache.catalina.Wrapper in project tomcat by apache.

the class TestDefaultServlet method testGzippedFile.

/*
     * Verify serving of gzipped resources from context root.
     */
@Test
public void testGzippedFile() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File appDir = new File("test/webapp");
    File gzipIndex = new File(appDir, "index.html.gz");
    long gzipSize = gzipIndex.length();
    File index = new File(appDir, "index.html");
    long indexSize = index.length();
    // app dir is relative to server home
    Context ctxt = tomcat.addContext("", appDir.getAbsolutePath());
    Wrapper defaultServlet = Tomcat.addServlet(ctxt, "default", "org.apache.catalina.servlets.DefaultServlet");
    defaultServlet.addInitParameter("gzip", "true");
    ctxt.addServletMappingDecoded("/", "default");
    ctxt.addMimeMapping("html", "text/html");
    tomcat.start();
    TestCompressedClient gzipClient = new TestCompressedClient(getPort());
    gzipClient.reset();
    gzipClient.setRequest(new String[] { "GET /index.html HTTP/1.1" + CRLF + "Host: localhost" + CRLF + "Connection: Close" + CRLF + "Accept-Encoding: gzip, br" + CRLF + CRLF });
    gzipClient.connect();
    gzipClient.processRequest();
    assertTrue(gzipClient.isResponse200());
    List<String> responseHeaders = gzipClient.getResponseHeaders();
    assertTrue(responseHeaders.contains("Content-Encoding: gzip"));
    assertTrue(responseHeaders.contains("Content-Length: " + gzipSize));
    assertTrue(responseHeaders.contains("Vary: accept-encoding"));
    gzipClient.reset();
    gzipClient.setRequest(new String[] { "GET /index.html HTTP/1.1" + CRLF + "Host: localhost" + CRLF + "Connection: Close" + CRLF + CRLF });
    gzipClient.connect();
    gzipClient.processRequest();
    assertTrue(gzipClient.isResponse200());
    responseHeaders = gzipClient.getResponseHeaders();
    assertTrue(responseHeaders.contains("Content-Type: text/html"));
    assertFalse(responseHeaders.contains("Content-Encoding: gzip"));
    assertTrue(responseHeaders.contains("Content-Length: " + indexSize));
    assertTrue(responseHeaders.contains("Vary: accept-encoding"));
}
Also used : Context(org.apache.catalina.Context) Wrapper(org.apache.catalina.Wrapper) Tomcat(org.apache.catalina.startup.Tomcat) File(java.io.File) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 58 with Wrapper

use of org.apache.catalina.Wrapper in project tomcat by apache.

the class TestDefaultServlet method testBrotliPreference.

/*
     * Verify preferring of brotli in default configuration for actual Firefox and Chrome requests.
     */
@Test
public void testBrotliPreference() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File appDir = new File("test/webapp");
    long brSize = new File(appDir, "index.html.br").length();
    // app dir is relative to server home
    Context ctxt = tomcat.addContext("", appDir.getAbsolutePath());
    Wrapper defaultServlet = Tomcat.addServlet(ctxt, "default", DefaultServlet.class.getName());
    defaultServlet.addInitParameter("precompressed", "true");
    ctxt.addServletMappingDecoded("/", "default");
    ctxt.addMimeMapping("html", "text/html");
    tomcat.start();
    TestCompressedClient client = new TestCompressedClient(getPort());
    // Firefox 45 Accept-Encoding
    client.reset();
    client.setRequest(new String[] { "GET /index.html HTTP/1.1" + CRLF + "Host: localhost" + CRLF + "Connection: Close" + CRLF + "Accept-Encoding: gzip, deflate, br" + CRLF + CRLF });
    client.connect();
    client.processRequest();
    assertTrue(client.isResponse200());
    List<String> responseHeaders = client.getResponseHeaders();
    assertTrue(responseHeaders.contains("Content-Encoding: br"));
    assertTrue(responseHeaders.contains("Content-Length: " + brSize));
    assertTrue(responseHeaders.contains("Vary: accept-encoding"));
    // Chrome 50 Accept-Encoding
    client.reset();
    client.setRequest(new String[] { "GET /index.html HTTP/1.1" + CRLF + "Host: localhost" + CRLF + "Connection: Close" + CRLF + "Accept-Encoding: gzip, deflate, sdch, br" + CRLF + CRLF });
    client.connect();
    client.processRequest();
    assertTrue(client.isResponse200());
    responseHeaders = client.getResponseHeaders();
    assertTrue(responseHeaders.contains("Content-Encoding: br"));
    assertTrue(responseHeaders.contains("Content-Length: " + brSize));
    assertTrue(responseHeaders.contains("Vary: accept-encoding"));
}
Also used : Context(org.apache.catalina.Context) Wrapper(org.apache.catalina.Wrapper) Tomcat(org.apache.catalina.startup.Tomcat) File(java.io.File) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 59 with Wrapper

use of org.apache.catalina.Wrapper in project tomcat by apache.

the class TestDefaultServlet method testBrotliCompressedFile.

/*
     * Verify serving of brotli compressed resources from context root.
     */
@Test
public void testBrotliCompressedFile() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File appDir = new File("test/webapp");
    long brSize = new File(appDir, "index.html.br").length();
    long indexSize = new File(appDir, "index.html").length();
    // app dir is relative to server home
    Context ctxt = tomcat.addContext("", appDir.getAbsolutePath());
    Wrapper defaultServlet = Tomcat.addServlet(ctxt, "default", "org.apache.catalina.servlets.DefaultServlet");
    defaultServlet.addInitParameter("precompressed", "true");
    ctxt.addServletMappingDecoded("/", "default");
    ctxt.addMimeMapping("html", "text/html");
    tomcat.start();
    TestCompressedClient client = new TestCompressedClient(getPort());
    client.reset();
    client.setRequest(new String[] { "GET /index.html HTTP/1.1" + CRLF + "Host: localhost" + CRLF + "Connection: Close" + CRLF + "Accept-Encoding: br, gzip" + CRLF + CRLF });
    client.connect();
    client.processRequest();
    assertTrue(client.isResponse200());
    List<String> responseHeaders = client.getResponseHeaders();
    assertTrue(responseHeaders.contains("Content-Encoding: br"));
    assertTrue(responseHeaders.contains("Content-Length: " + brSize));
    assertTrue(responseHeaders.contains("Vary: accept-encoding"));
    client.reset();
    client.setRequest(new String[] { "GET /index.html HTTP/1.1" + CRLF + "Host: localhost" + CRLF + "Connection: Close" + CRLF + CRLF });
    client.connect();
    client.processRequest();
    assertTrue(client.isResponse200());
    responseHeaders = client.getResponseHeaders();
    assertTrue(responseHeaders.contains("Content-Type: text/html"));
    assertFalse(responseHeaders.contains("Content-Encoding"));
    assertTrue(responseHeaders.contains("Content-Length: " + indexSize));
    assertTrue(responseHeaders.contains("Vary: accept-encoding"));
}
Also used : Context(org.apache.catalina.Context) Wrapper(org.apache.catalina.Wrapper) Tomcat(org.apache.catalina.startup.Tomcat) File(java.io.File) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 60 with Wrapper

use of org.apache.catalina.Wrapper in project tomcat by apache.

the class TestMapper method createWrapper.

private Wrapper createWrapper(String name) {
    Wrapper wrapper = new StandardWrapper();
    wrapper.setName(name);
    return wrapper;
}
Also used : Wrapper(org.apache.catalina.Wrapper) StandardWrapper(org.apache.catalina.core.StandardWrapper) StandardWrapper(org.apache.catalina.core.StandardWrapper)

Aggregations

Wrapper (org.apache.catalina.Wrapper)87 Context (org.apache.catalina.Context)53 Tomcat (org.apache.catalina.startup.Tomcat)46 AsyncContext (javax.servlet.AsyncContext)33 Test (org.junit.Test)31 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)28 ServletRequestWrapper (javax.servlet.ServletRequestWrapper)24 ServletResponseWrapper (javax.servlet.ServletResponseWrapper)24 TesterContext (org.apache.tomcat.unittest.TesterContext)24 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)22 IOException (java.io.IOException)14 TesterAccessLogValve (org.apache.catalina.valves.TesterAccessLogValve)14 File (java.io.File)11 Container (org.apache.catalina.Container)11 StandardWrapper (org.apache.catalina.core.StandardWrapper)10 StandardContext (org.apache.catalina.core.StandardContext)6 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)6 ServletException (javax.servlet.ServletException)5 ArrayList (java.util.ArrayList)4 ServletContext (javax.servlet.ServletContext)4