@Test(expected = IOException.class) public void testShouldThrowIOExceptionForBrokenXml() throws IOException { final String webXmlContent = "<?xml version=\"1.0\"?>\n" + "<web-app>some stuff and a missing end tag\n"; WebXmlServletRegistrationParser parser = new WebXmlServletRegistrationParser(); parser.parse(new ByteArrayInputStream(webXmlContent.getBytes(Charset.forName("UTF8")))); }
public void parse(InputStream stream) throws IOException { try { XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); XMLEventReader reader = xmlInputFactory.createXMLEventReader(stream); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (event.isEndDocument()) { break; } if (event.isStartElement()) { stack.push(event.asStartElement().getName().getLocalPart()); } handleEvent(event); if (event.isEndElement()) { stack.pop(); } } for (ServletEntry servletEntry : servlets) { ServletRegistration reg = new ServletRegistration(); reg.setClassName(servletEntry.servletClass); ServletMappingEntry mapping = servletMappings.get(servletEntry.servletName); if (mapping != null) { reg.addMappings(mapping.mappings); } registrations.add(reg); } } catch (XMLStreamException e) { throw new IOException(e); } }
WebXmlServletRegistrationParser { public void parse(InputStream stream) throws IOException { try { XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); XMLEventReader reader = xmlInputFactory.createXMLEventReader(stream); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (event.isEndDocument()) { break; } if (event.isStartElement()) { stack.push(event.asStartElement().getName().getLocalPart()); } handleEvent(event); if (event.isEndElement()) { stack.pop(); } } for (ServletEntry servletEntry : servlets) { ServletRegistration reg = new ServletRegistration(); reg.setClassName(servletEntry.servletClass); ServletMappingEntry mapping = servletMappings.get(servletEntry.servletName); if (mapping != null) { reg.addMappings(mapping.mappings); } registrations.add(reg); } } catch (XMLStreamException e) { throw new IOException(e); } } }
WebXmlServletRegistrationParser { public void parse(InputStream stream) throws IOException { try { XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); XMLEventReader reader = xmlInputFactory.createXMLEventReader(stream); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (event.isEndDocument()) { break; } if (event.isStartElement()) { stack.push(event.asStartElement().getName().getLocalPart()); } handleEvent(event); if (event.isEndElement()) { stack.pop(); } } for (ServletEntry servletEntry : servlets) { ServletRegistration reg = new ServletRegistration(); reg.setClassName(servletEntry.servletClass); ServletMappingEntry mapping = servletMappings.get(servletEntry.servletName); if (mapping != null) { reg.addMappings(mapping.mappings); } registrations.add(reg); } } catch (XMLStreamException e) { throw new IOException(e); } }  }
WebXmlServletRegistrationParser { public void parse(InputStream stream) throws IOException { try { XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); XMLEventReader reader = xmlInputFactory.createXMLEventReader(stream); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (event.isEndDocument()) { break; } if (event.isStartElement()) { stack.push(event.asStartElement().getName().getLocalPart()); } handleEvent(event); if (event.isEndElement()) { stack.pop(); } } for (ServletEntry servletEntry : servlets) { ServletRegistration reg = new ServletRegistration(); reg.setClassName(servletEntry.servletClass); ServletMappingEntry mapping = servletMappings.get(servletEntry.servletName); if (mapping != null) { reg.addMappings(mapping.mappings); } registrations.add(reg); } } catch (XMLStreamException e) { throw new IOException(e); } }  void parse(InputStream stream); List<ServletRegistration> getRegistrations(); }
WebXmlServletRegistrationParser { public void parse(InputStream stream) throws IOException { try { XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); XMLEventReader reader = xmlInputFactory.createXMLEventReader(stream); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (event.isEndDocument()) { break; } if (event.isStartElement()) { stack.push(event.asStartElement().getName().getLocalPart()); } handleEvent(event); if (event.isEndElement()) { stack.pop(); } } for (ServletEntry servletEntry : servlets) { ServletRegistration reg = new ServletRegistration(); reg.setClassName(servletEntry.servletClass); ServletMappingEntry mapping = servletMappings.get(servletEntry.servletName); if (mapping != null) { reg.addMappings(mapping.mappings); } registrations.add(reg); } } catch (XMLStreamException e) { throw new IOException(e); } }  void parse(InputStream stream); List<ServletRegistration> getRegistrations();  }