Java Code Examples for org.apache.tomcat.util.descriptor.web.WebXml#addServletMapping()

The following examples show how to use org.apache.tomcat.util.descriptor.web.WebXml#addServletMapping() . 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: TestContextConfigAnnotation.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testNoMapping() throws Exception {
    WebXml webxml = new WebXml();
    Map<String,JavaClassCacheEntry> javaClassCache = new HashMap<>();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/NoMappingParamServlet");
    Assert.assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false, javaClassCache);
    ServletDef servletDef = webxml.getServlets().get("param1");
    Assert.assertNull(servletDef);

    webxml.addServletMapping("/param", "param1");
    config.processAnnotationsFile(pFile, webxml, false, javaClassCache);
    servletDef = webxml.getServlets().get("param1");
    Assert.assertNull(servletDef);

}
 
Example 2
Source File: TestContextConfigAnnotation.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testSetupWebXMLNoMapping() throws Exception {
    WebXml webxml = new WebXml();
    Map<String,JavaClassCacheEntry> javaClassCache = new HashMap<>();
    ServletDef servletDef = new ServletDef();
    servletDef.setServletName("param1");
    servletDef.setServletClass(
            "org.apache.catalina.startup.NoMappingParamServlet");
    servletDef.addInitParameter("foo", "tomcat");

    webxml.addServlet(servletDef);
    webxml.addServletMapping("/param", "param1");
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/NoMappingParamServlet");
    Assert.assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false, javaClassCache);
    Assert.assertEquals("tomcat", servletDef.getParameterMap().get("foo"));
    Assert.assertEquals("World!", servletDef.getParameterMap().get("bar"));
    ServletDef servletDef1 = webxml.getServlets().get("param1");
    Assert.assertNotNull(servletDef1);
    Assert.assertEquals(servletDef, servletDef1);
}
 
Example 3
Source File: TestContextConfigAnnotation.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testOverwriteAnnotation() throws Exception {
    WebXml webxml = new WebXml();
    Map<String,JavaClassCacheEntry> javaClassCache = new HashMap<>();
    ServletDef servletDef = new ServletDef();
    servletDef.setServletName("param");
    servletDef.setServletClass("org.apache.catalina.startup.ParamServlet");
    servletDef.addInitParameter("foo", "tomcat");
    servletDef.setDescription("Description");
    servletDef.setDisplayName("DisplayName");
    servletDef.setLargeIcon("LargeIcon");
    servletDef.setSmallIcon("SmallIcon");
    servletDef.setAsyncSupported("true");
    servletDef.setLoadOnStartup("1");

    webxml.addServlet(servletDef);
    webxml.addServletMapping("/param", "param");
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/ParamServlet");
    Assert.assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false, javaClassCache);

    Assert.assertEquals(servletDef, webxml.getServlets().get("param"));

    Assert.assertEquals("tomcat", servletDef.getParameterMap().get("foo"));
    Assert.assertEquals("param", webxml.getServletMappings().get("/param"));
    // annotation mapping not added s. Servlet Spec 3.0 (Nov 2009)
    // 8.2.3.3.iv page 81
    Assert.assertNull(webxml.getServletMappings().get("/annotation/overwrite"));

    Assert.assertEquals("Description", servletDef.getDescription());
    Assert.assertEquals("DisplayName", servletDef.getDisplayName());
    Assert.assertEquals("LargeIcon", servletDef.getLargeIcon());
    Assert.assertEquals("SmallIcon", servletDef.getSmallIcon());
    Assert.assertEquals(Boolean.TRUE, servletDef.getAsyncSupported());
    Assert.assertEquals(Integer.valueOf(1), servletDef.getLoadOnStartup());
    Assert.assertNull(servletDef.getEnabled());
    Assert.assertNull(servletDef.getJspFile());
}