Search in sources :

Example 16 with WebXml

use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.

the class TestSchemaValidation method testWebapp_2_3.

@Test
public void testWebapp_2_3() throws Exception {
    XmlErrorHandler handler = new XmlErrorHandler();
    Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(false), true);
    digester.setErrorHandler(handler);
    digester.push(new WebXml());
    WebXml desc = (WebXml) digester.parse(new File("test/webapp-2.3/WEB-INF/web.xml"));
    Assert.assertEquals("2.3", desc.getVersion());
    Assert.assertEquals(XmlIdentifiers.WEB_23_PUBLIC, desc.getPublicId());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}
Also used : WebXml(org.apache.tomcat.util.descriptor.web.WebXml) Digester(org.apache.tomcat.util.digester.Digester) XmlErrorHandler(org.apache.tomcat.util.descriptor.XmlErrorHandler) WebRuleSet(org.apache.tomcat.util.descriptor.web.WebRuleSet) File(java.io.File) Test(org.junit.Test)

Example 17 with WebXml

use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.

the class TestSchemaValidation method testWebapp_2_4.

@Test
public void testWebapp_2_4() throws Exception {
    XmlErrorHandler handler = new XmlErrorHandler();
    Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(false), true);
    digester.setErrorHandler(handler);
    digester.push(new WebXml());
    WebXml desc = (WebXml) digester.parse(new File("test/webapp-2.4/WEB-INF/web.xml"));
    Assert.assertEquals("2.4", desc.getVersion());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}
Also used : WebXml(org.apache.tomcat.util.descriptor.web.WebXml) Digester(org.apache.tomcat.util.digester.Digester) XmlErrorHandler(org.apache.tomcat.util.descriptor.XmlErrorHandler) WebRuleSet(org.apache.tomcat.util.descriptor.web.WebRuleSet) File(java.io.File) Test(org.junit.Test)

Example 18 with WebXml

use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.

the class TestContextConfigAnnotation method testOverwriteAnnotation.

@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");
    assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false, javaClassCache);
    assertEquals(servletDef, webxml.getServlets().get("param"));
    assertEquals("tomcat", servletDef.getParameterMap().get("foo"));
    assertEquals("param", webxml.getServletMappings().get("/param"));
    // annotation mapping not added s. Servlet Spec 3.0 (Nov 2009)
    // 8.2.3.3.iv page 81
    assertNull(webxml.getServletMappings().get("/annotation/overwrite"));
    assertEquals("Description", servletDef.getDescription());
    assertEquals("DisplayName", servletDef.getDisplayName());
    assertEquals("LargeIcon", servletDef.getLargeIcon());
    assertEquals("SmallIcon", servletDef.getSmallIcon());
    assertEquals(Boolean.TRUE, servletDef.getAsyncSupported());
    assertEquals(Integer.valueOf(1), servletDef.getLoadOnStartup());
    assertNull(servletDef.getEnabled());
    assertNull(servletDef.getJspFile());
}
Also used : WebXml(org.apache.tomcat.util.descriptor.web.WebXml) HashMap(java.util.HashMap) ServletDef(org.apache.tomcat.util.descriptor.web.ServletDef) JavaClassCacheEntry(org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry) File(java.io.File) Test(org.junit.Test)

Example 19 with WebXml

use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.

the class TestContextConfigAnnotation method testFilterMapping.

@Test
public void testFilterMapping() throws Exception {
    WebXml webxml = new WebXml();
    Map<String, JavaClassCacheEntry> javaClassCache = new HashMap<>();
    ContextConfig config = new ContextConfig();
    File sFile = paramClassResource("org/apache/catalina/startup/ParamServlet");
    config.processAnnotationsFile(sFile, webxml, false, javaClassCache);
    File fFile = paramClassResource("org/apache/catalina/startup/ParamFilter");
    config.processAnnotationsFile(fFile, webxml, false, javaClassCache);
    FilterDef fdef = webxml.getFilters().get("paramFilter");
    assertNotNull(fdef);
    assertEquals("Servlet says: ", fdef.getParameterMap().get("message"));
}
Also used : WebXml(org.apache.tomcat.util.descriptor.web.WebXml) FilterDef(org.apache.tomcat.util.descriptor.web.FilterDef) HashMap(java.util.HashMap) JavaClassCacheEntry(org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry) File(java.io.File) Test(org.junit.Test)

Example 20 with WebXml

use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.

the class TestContextConfigAnnotation method testSetupWebXMLNoMapping.

@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");
    assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false, javaClassCache);
    assertEquals("tomcat", servletDef.getParameterMap().get("foo"));
    assertEquals("World!", servletDef.getParameterMap().get("bar"));
    ServletDef servletDef1 = webxml.getServlets().get("param1");
    assertNotNull(servletDef1);
    assertEquals(servletDef, servletDef1);
}
Also used : WebXml(org.apache.tomcat.util.descriptor.web.WebXml) HashMap(java.util.HashMap) ServletDef(org.apache.tomcat.util.descriptor.web.ServletDef) JavaClassCacheEntry(org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry) File(java.io.File) Test(org.junit.Test)

Aggregations

WebXml (org.apache.tomcat.util.descriptor.web.WebXml)22 File (java.io.File)18 Test (org.junit.Test)17 HashMap (java.util.HashMap)10 JavaClassCacheEntry (org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry)9 XmlErrorHandler (org.apache.tomcat.util.descriptor.XmlErrorHandler)8 WebRuleSet (org.apache.tomcat.util.descriptor.web.WebRuleSet)8 Digester (org.apache.tomcat.util.digester.Digester)8 ServletDef (org.apache.tomcat.util.descriptor.web.ServletDef)5 URL (java.net.URL)4 IOException (java.io.IOException)3 FilterDef (org.apache.tomcat.util.descriptor.web.FilterDef)3 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 ServletContainerInitializer (javax.servlet.ServletContainerInitializer)2 FilterMap (org.apache.tomcat.util.descriptor.web.FilterMap)2 WebXmlParser (org.apache.tomcat.util.descriptor.web.WebXmlParser)2 InputSource (org.xml.sax.InputSource)2 URISyntaxException (java.net.URISyntaxException)1 URLConnection (java.net.URLConnection)1