Java Code Examples for org.apache.catalina.core.StandardContext#setReplaceWelcomeFiles()

The following examples show how to use org.apache.catalina.core.StandardContext#setReplaceWelcomeFiles() . 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: TestMapperWebapps.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testWelcomeFileNotStrict() throws Exception {

    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp");

    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test",
            appDir.getAbsolutePath());
    ctxt.setReplaceWelcomeFiles(true);
    ctxt.addWelcomeFile("index.jsp");
    // Mapping for *.do is defined in web.xml
    ctxt.addWelcomeFile("index.do");

    tomcat.start();
    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() + "/test/welcome-files", bc, null);
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("JSP"));

    rc = getUrl("http://localhost:" + getPort() + "/test/welcome-files/sub", bc, null);
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("Servlet"));
}
 
Example 2
Source File: TestMapperWebapps.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testWelcomeFileStrict() throws Exception {

    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp");

    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test",
            appDir.getAbsolutePath());
    ctxt.setReplaceWelcomeFiles(true);
    ctxt.addWelcomeFile("index.jsp");
    // Mapping for *.do is defined in web.xml
    ctxt.addWelcomeFile("index.do");

    // Simulate STRICT_SERVLET_COMPLIANCE
    ctxt.setResourceOnlyServlets("");

    tomcat.start();
    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() + "/test/welcome-files", bc, null);
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("JSP"));

    rc = getUrl("http://localhost:" + getPort() + "/test/welcome-files/sub", bc, null);
    Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
}
 
Example 3
Source File: TestMapperWebapps.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWelcomeFileNotStrict() throws Exception {

    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");

    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test",
            appDir.getAbsolutePath());
    ctxt.setReplaceWelcomeFiles(true);
    ctxt.addWelcomeFile("index.jsp");
    // Mapping for *.do is defined in web.xml
    ctxt.addWelcomeFile("index.do");

    tomcat.start();
    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() +
            "/test/welcome-files", bc, new HashMap<String,List<String>>());
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("JSP"));

    rc = getUrl("http://localhost:" + getPort() +
            "/test/welcome-files/sub", bc,
            new HashMap<String,List<String>>());
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("Servlet"));
}
 
Example 4
Source File: TestMapperWebapps.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWelcomeFileStrict() throws Exception {

    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");

    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test",
            appDir.getAbsolutePath());
    ctxt.setReplaceWelcomeFiles(true);
    ctxt.addWelcomeFile("index.jsp");
    // Mapping for *.do is defined in web.xml
    ctxt.addWelcomeFile("index.do");

    // Simulate STRICT_SERVLET_COMPLIANCE
    ctxt.setResourceOnlyServlets("");

    tomcat.start();
    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() +
            "/test/welcome-files", bc, new HashMap<String,List<String>>());
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("JSP"));

    rc = getUrl("http://localhost:" + getPort() +
            "/test/welcome-files/sub", bc,
            new HashMap<String,List<String>>());
    Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
}
 
Example 5
Source File: TestMapperWebapps.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testWelcomeFileNotStrict() throws Exception {

    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");

    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test",
            appDir.getAbsolutePath());
    ctxt.setReplaceWelcomeFiles(true);
    ctxt.addWelcomeFile("index.jsp");
    // Mapping for *.do is defined in web.xml
    ctxt.addWelcomeFile("index.do");

    tomcat.start();
    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() +
            "/test/welcome-files", bc, new HashMap<String,List<String>>());
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("JSP"));

    rc = getUrl("http://localhost:" + getPort() +
            "/test/welcome-files/sub", bc,
            new HashMap<String,List<String>>());
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("Servlet"));
}
 
Example 6
Source File: TestMapperWebapps.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testWelcomeFileStrict() throws Exception {

    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");

    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test",
            appDir.getAbsolutePath());
    ctxt.setReplaceWelcomeFiles(true);
    ctxt.addWelcomeFile("index.jsp");
    // Mapping for *.do is defined in web.xml
    ctxt.addWelcomeFile("index.do");

    // Simulate STRICT_SERVLET_COMPLIANCE
    ctxt.setResourceOnlyServlets("");

    tomcat.start();
    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() +
            "/test/welcome-files", bc, new HashMap<String,List<String>>());
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("JSP"));

    rc = getUrl("http://localhost:" + getPort() +
            "/test/welcome-files/sub", bc,
            new HashMap<String,List<String>>());
    Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
}