WebXmlParser { public WebXml parse(InputStream inputStream) { WebXml webXml = new WebXml(); try { DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = documentBuilder.parse(inputStream); XPath xPath = XPathFactory.newInstance().newXPath(); parseAbsoluteOrdering(webXml, xPath, document); parseOrdering(webXml, xPath, document); parseContextParameters(webXml, xPath, document); parseDefaultContextPath(webXml, xPath, document); parseDenyUncoveredHttpMethods(webXml, xPath, document); parseDisplayName(webXml, xPath, document); parseFragmentName(webXml, xPath, document); parseDistributable(webXml, xPath, document); parseErrorPages(webXml, xPath, document); parseFilterMappings(webXml, xPath, document); parseFilters(webXml, xPath, document); parseListeners(webXml, xPath, document); parseLoginConfig(webXml, xPath, document); parseMimeMappings(webXml, xPath, document); parseRequestCharacterEncoding(webXml, xPath, document); parseResponseCharacterEncoding(webXml, xPath, document); parseLocaleEncodingMapping(webXml, xPath, document); processSecurityConstraints(webXml, xPath, document); processSecurityRoles(webXml, xPath, document); parseServletMappings(webXml, xPath, document); parseServlets(webXml, xPath, document); parseSessionConfig(webXml, xPath, document); parseWebApp(webXml, xPath, document); parseWelcomeFiles(webXml, xPath, document); } catch (Throwable t) { LOGGER.log(WARNING, "Unable to parse web.xml", t); } return webXml; }  WebXml parse(InputStream inputStream); static Iterable<Node> toIterable(NodeList nodes);  }
@Test void testParseWebXml() throws Exception { DefaultWebApplication webApplication = new DefaultWebApplication(); webApplication.addResource(new DirectoryResource(new File("src/test/webxml/parse"))); InputStream inputStream = webApplication.getResourceAsStream("WEB-INF/web.xml"); WebXmlParser parser = new WebXmlParser(); WebXml webXml = parser.parse(inputStream); assertFalse(webXml.getServlets().isEmpty()); assertEquals(2, webXml.getServlets().size()); assertNotEquals(webXml.getServlets().get(0).getServletName(), webXml.getServlets().get(1).getServletName()); assertTrue(webXml.getServlets().get(0).isAsyncSupported()); assertFalse(webXml.getServlets().get(1).isAsyncSupported()); assertFalse(webXml.getFilters().isEmpty()); assertEquals(1, webXml.getFilters().size()); assertEquals("/defaultContextPath", webXml.getDefaultContextPath()); assertTrue(webXml.getDenyUncoveredHttpMethods()); assertEquals("myServletContextName", webXml.getDisplayName()); assertTrue(webXml.isDistributable()); assertEquals("UTF-8", webXml.getResponseCharacterEncoding()); }
@Test void testParseWebXml2() throws Exception { DefaultWebApplication webApplication = new DefaultWebApplication(); webApplication.addResource(new DirectoryResource(new File("src/test/webxml/parse2"))); InputStream inputStream = webApplication.getResourceAsStream("WEB-INF/web.xml"); WebXmlParser parser = new WebXmlParser(); WebXml webXml = parser.parse(inputStream); assertNotEquals("/defaultContextPath", webXml.getDefaultContextPath()); assertFalse(webXml.getDenyUncoveredHttpMethods()); assertNotEquals("myServletContextName", webXml.getDisplayName()); assertFalse(webXml.isDistributable()); assertNotEquals("UTF-8", webXml.getResponseCharacterEncoding()); }
@Test void testParseWebXml3() throws Exception { DefaultWebApplication webApplication = new DefaultWebApplication(); webApplication.addResource(new DirectoryResource(new File("src/test/webxml/parse3"))); InputStream inputStream = webApplication.getResourceAsStream("WEB-INF/web.xml"); WebXmlParser parser = new WebXmlParser(); WebXml webXml = parser.parse(inputStream); assertEquals(2, webXml.getWelcomeFiles().size()); assertEquals("index.html", webXml.getWelcomeFiles().get(0)); assertEquals("default.jsp", webXml.getWelcomeFiles().get(1)); }
@Test void testParseWebXml4() throws Exception { DefaultWebApplication webApplication = new DefaultWebApplication(); webApplication.addResource(new DirectoryResource(new File("src/test/webxml/parse4"))); InputStream inputStream = webApplication.getResourceAsStream("WEB-INF/web.xml"); WebXmlParser parser = new WebXmlParser(); WebXml webXml = parser.parse(inputStream); assertEquals(1, webXml.getServlets().size()); String servletName = webXml.getServlets().get(0).getServletName(); assertEquals("Test Servlet", servletName); List<WebXmlServletMapping> servletMappings = webXml.getServletMappings(); assertEquals(2, servletMappings.size()); assertEquals(servletName, servletMappings.get(0).getServletName()); assertEquals("/foo", servletMappings.get(0).getUrlPattern()); assertEquals(servletName, servletMappings.get(1).getServletName()); assertEquals("/bar", servletMappings.get(1).getUrlPattern()); }