Java Code Examples for org.apache.tomcat.util.buf.ByteChunk#toString()

The following examples show how to use org.apache.tomcat.util.buf.ByteChunk#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestParserNoStrictWhitespace.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testBug48668b() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug48nnn/bug48668b.jsp");
    String result = res.toString();
    assertEcho(result, "00-Hello world</p>#{foo.bar}");
    assertEcho(result, "01-Hello world</p>#{foo2");
}
 
Example 2
Source File: TestELInJsp.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testBug57142() throws Exception {
    getTomcatInstanceTestWebapp(false, true);

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug57142.jsp");

    String result = res.toString();
    // javax.servlet
    assertEcho(result, "00-" + DispatcherType.ASYNC);
    // No obvious static fields for javax.servlet.http
    // Could hack something with HttpUtils...
    // No obvious static fields for javax.servlet.jsp
    // Wild card (package) import
    assertEcho(result, "01-" + RoundingMode.HALF_UP);
    // Class import
    assertEcho(result, "02-" + Collections.EMPTY_LIST.size());
}
 
Example 3
Source File: TestValidator.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testTldVersions25() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir =
        new File("test/webapp-2.5");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/tld-versions.jsp");

    String result = res.toString();

    assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
    assertTrue(result.indexOf("<p>#{'01-hello world'}</p>") > 0);
    assertTrue(result.indexOf("<p>02-hello world</p>") > 0);
    assertTrue(result.indexOf("<p>#{'03-hello world'}</p>") > 0);
    assertTrue(result.indexOf("<p>04-hello world</p>") > 0);
    assertTrue(result.indexOf("<p>#{'05-hello world'}</p>") > 0);
    assertTrue(result.indexOf("<p>06-hello world</p>") > 0);
}
 
Example 4
Source File: TestValidator.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testTldVersions30() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir =
        new File("test/webapp-3.0");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/tld-versions.jsp");

    String result = res.toString();

    assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
    assertTrue(result.indexOf("<p>#{'01-hello world'}</p>") > 0);
    assertTrue(result.indexOf("<p>02-hello world</p>") > 0);
    assertTrue(result.indexOf("<p>#{'03-hello world'}</p>") > 0);
    assertTrue(result.indexOf("<p>04-hello world</p>") > 0);
    assertTrue(result.indexOf("<p>#{'05-hello world'}</p>") > 0);
    assertTrue(result.indexOf("<p>06-hello world</p>") > 0);
}
 
Example 5
Source File: TestJspConfig.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testServlet23NoEL() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir =
        new File("test/webapp-2.3");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/el-as-literal.jsp");

    String result = res.toString();

    assertTrue(result.indexOf("<p>00-${'hello world'}</p>") > 0);
    assertTrue(result.indexOf("<p>01-#{'hello world'}</p>") > 0);
}
 
Example 6
Source File: TestELInJsp.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBug49555() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug49nnn/bug49555.jsp");

    String result = res.toString();
    assertEcho(result, "00-" + TesterFunctions.Inner$Class.RETVAL);
}
 
Example 7
Source File: TestJspConfig.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testServlet30NoEL() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/el-as-literal.jsp");

    String result = res.toString();

    Assert.assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
}
 
Example 8
Source File: TestErrorReportValve.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Custom error/status codes should not result in a blank response.
 */
@Test
public void testBug54536() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Tomcat.addServlet(ctx, "bug54536", new Bug54536Servlet());
    ctx.addServletMapping("/", "bug54536");

    tomcat.start();

    ByteChunk res = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort(), res, null);

    Assert.assertEquals(Bug54536Servlet.ERROR_STATUS, rc);
    String body = res.toString();
    Assert.assertNotNull(body);
    Assert.assertTrue(body, body.contains(Bug54536Servlet.ERROR_MESSAGE));
}
 
Example 9
Source File: TestApplicationMapping.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
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]"));
}
 
Example 10
Source File: TestELInJsp.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBug51544() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug51544.jsp");

    String result = res.toString();
    assertEcho(result, "Empty list: true");
}
 
Example 11
Source File: TestParserNoStrictWhitespace.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testBug48627() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir =
        new File("test/webapp-3.0");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug48nnn/bug48627.jsp");

    String result = res.toString();
    // Beware of the differences between escaping in JSP attributes and
    // in Java Strings
    assertEcho(result, "00-\\");
    assertEcho(result, "01-\\");
}
 
Example 12
Source File: TestGenerator.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private void testBug48701(String jsp) throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir =
        new File("test/webapp-3.0");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/" + jsp);

    String result = res.toString();
    assertEcho(result, "00-PASS");
}
 
Example 13
Source File: TestELInJsp.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testBug60431() throws Exception {
    getTomcatInstanceTestWebapp(false, true);

    ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/bug6nnnn/bug60431.jsp");
    String result = res.toString();
    assertEcho(result, "01-OK");
    assertEcho(result, "02-OK");
    assertEcho(result, "03-OK");
}
 
Example 14
Source File: TestELInJsp.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testBug56612() throws Exception {
    getTomcatInstanceTestWebapp(false, true);

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug56612.jsp");

    String result = res.toString();
    Assert.assertTrue(result.contains("00-''"));
}
 
Example 15
Source File: TestELInJsp.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testScriptingExpression() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir =
        new File("test/webapp-3.0");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/script-expr.jsp");
    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, "04-hello \\${world");
    assertEcho(result, "05-hello world");
    assertEcho(result, "06-hello \"world");
    assertEcho(result, "07-hello \\\"world");
    assertEcho(result, "08-hello ${world");
    assertEcho(result, "09-hello \\${world");
    assertEcho(result, "10-hello <% world");
    assertEcho(result, "11-hello %> world");
}
 
Example 16
Source File: TestParser.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testBug48627() throws Exception {
    getTomcatInstanceTestWebapp(false, true);

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug48nnn/bug48627.jsp");

    String result = res.toString();
    // Beware of the differences between escaping in JSP attributes and
    // in Java Strings
    assertEcho(result, "00-\\");
    assertEcho(result, "01-\\");
}
 
Example 17
Source File: TestCompiler.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testBug53257f() throws Exception {
    getTomcatInstanceTestWebapp(false, true);

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug53257/foo%20bar.jsp");

    // Check request completed
    String result = res.toString();
    assertEcho(result, "OK");
}
 
Example 18
Source File: TestApplicationContext.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Test
public void testBug57190() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    Context foo1 = new StandardContext();
    foo1.setName("/foo##1");
    foo1.setPath("/foo");
    foo1.setWebappVersion("1");
    foo1.setDocBase(System.getProperty("java.io.tmpdir"));
    foo1.addLifecycleListener(new FixContextListener());
    foo1.addLifecycleListener(new SetIdListener("foo1"));
    tomcat.getHost().addChild(foo1);

    Context foo2 = new StandardContext();
    foo2.setName("/foo##2");
    foo2.setPath("/foo");
    foo2.setWebappVersion("2");
    foo2.setDocBase(System.getProperty("java.io.tmpdir"));
    foo2.addLifecycleListener(new FixContextListener());
    foo2.addLifecycleListener(new SetIdListener("foo2"));
    tomcat.getHost().addChild(foo2);

    // No file system docBase required
    Context bar = tomcat.addContext("/bar", null);
    bar.addLifecycleListener(new SetIdListener("bar"));

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    ctx.addLifecycleListener(new SetIdListener("ROOT"));
    ctx.setCrossContext(true);

    Tomcat.addServlet(ctx, "Bug57190Servlet", new Bug57190Servlet());
    ctx.addServletMapping("/", "Bug57190Servlet");

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
    String body = res.toString();

    Assert.assertTrue(body, body.contains("01-bar"));
    Assert.assertTrue(body, body.contains("02-foo2"));
    Assert.assertTrue(body, body.contains("03-foo1"));
    Assert.assertTrue(body, body.contains("04-foo2"));
    Assert.assertTrue(body, body.contains("05-foo2"));
    Assert.assertTrue(body, body.contains("06-ROOT"));
    Assert.assertTrue(body, body.contains("07-ROOT"));
    Assert.assertTrue(body, body.contains("08-foo2"));
    Assert.assertTrue(body, body.contains("09-ROOT"));
}
 
Example 19
Source File: TestParser.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Test
public void testBug56334And56561() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null,
            "/test", appDir.getAbsolutePath());

    // This test needs the JSTL libraries
    File lib = new File("webapps/examples/WEB-INF/lib");
    ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug56334and56561.jspx");

    String result = res.toString();

    // NOTE: The expected values must themselves be \ escaped below
    Assert.assertTrue(result, result.contains("01a\\?resize01a"));
    Assert.assertTrue(result, result.contains("01b\\\\x\\?resize01b"));
    Assert.assertTrue(result, result.contains("<set data-value=\"02a\\\\?resize02a\"/>"));
    Assert.assertTrue(result, result.contains("<set data-value=\"02b\\\\\\\\x\\\\?resize02b\"/>"));
    Assert.assertTrue(result, result.contains("<set data-value=\"03a\\?resize03a\"/>"));
    Assert.assertTrue(result, result.contains("<set data-value=\"03b\\\\x\\?resize03b\"/>"));
    Assert.assertTrue(result, result.contains("<04a\\?resize04a/>"));
    Assert.assertTrue(result, result.contains("<04b\\\\x\\?resize04b/>"));
    Assert.assertTrue(result, result.contains("<set data-value=\"05a$${&amp;\"/>"));
    Assert.assertTrue(result, result.contains("<set data-value=\"05b$${&amp;2\"/>"));
    Assert.assertTrue(result, result.contains("<set data-value=\"05c##{&gt;hello&lt;\"/>"));
    Assert.assertTrue(result, result.contains("05x:<set data-value=\"\"/>"));
    Assert.assertTrue(result, result.contains("<set xmlns:foo=\"urn:06a\\bar\\baz\"/>"));
    Assert.assertTrue(result, result.contains("07a:<set data-value=\"\\?resize\"/>"));
    Assert.assertTrue(result, result.contains("07b:<set data-content=\"\\?resize=.+\"/>"));
    Assert.assertTrue(result, result.contains("07c:<set data-content=\"\\?resize=.+\"/>"));
    Assert.assertTrue(result, result.contains("07d:<set data-content=\"false\"/>"));
    Assert.assertTrue(result, result.contains("07e:<set data-content=\"false\"/>"));
    Assert.assertTrue(result, result.contains("07f:<set data-content=\"\\\'something\'\"/>"));
    Assert.assertTrue(result, result.contains("07g:<set data-content=\"\\\'something\'\"/>"));
}
 
Example 20
Source File: TestJspContextWrapper.java    From Tomcat8-Source-Read with MIT License 3 votes vote down vote up
@Test
public void testELTagFileELContextListener() throws Exception {
    getTomcatInstanceTestWebapp(false, true);

    ByteChunk out = new ByteChunk();

    int rc = getUrl("http://localhost:" + getPort() + "/test/bug5nnnn/bug58178c.jsp", out, null);

    Assert.assertEquals(HttpServletResponse.SC_OK, rc);

    String result = out.toString();

    Assert.assertTrue(result, result.contains("JSP count: 1"));
    Assert.assertTrue(result, result.contains("Tag count: 1"));
}