@Test public void testXmlInputFactory() throws XMLStreamException, IOException { thrown.expect(XMLStreamException.class); thrown.expectMessage(containsString("The entity \"xxe\" was referenced, but not declared.")); try (Reader reader = Files.newBufferedReader(xmlDocument.toPath())) { XMLEventReader xmlEventReader = SafeXml.newXmlInputFactory().createXMLEventReader(reader); String content = ""; boolean track = false; while (xmlEventReader.hasNext()) { XMLEvent xmlEvent = xmlEventReader.nextEvent(); if (xmlEvent.isStartElement() && xmlEvent.asStartElement().getName().getLocalPart().equals("foo")) { track = true; } else if (xmlEvent.isEndElement() && xmlEvent.asEndElement().getName().getLocalPart().equals("foo")) { assertThat(content, not(containsString("bar"))); return; } else if (track && xmlEvent.isCharacters()) { content += xmlEvent.asCharacters().getData(); } } fail("Did not find element foo"); } }
public static XMLInputFactory newXmlInputFactory() { final XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(SUPPORT_DTD, false); xmlInputFactory.setProperty(IS_SUPPORTING_EXTERNAL_ENTITIES, false); return xmlInputFactory; }
SafeXml { public static XMLInputFactory newXmlInputFactory() { final XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(SUPPORT_DTD, false); xmlInputFactory.setProperty(IS_SUPPORTING_EXTERNAL_ENTITIES, false); return xmlInputFactory; } }
SafeXml { public static XMLInputFactory newXmlInputFactory() { final XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(SUPPORT_DTD, false); xmlInputFactory.setProperty(IS_SUPPORTING_EXTERNAL_ENTITIES, false); return xmlInputFactory; } private  SafeXml(); }
SafeXml { public static XMLInputFactory newXmlInputFactory() { final XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(SUPPORT_DTD, false); xmlInputFactory.setProperty(IS_SUPPORTING_EXTERNAL_ENTITIES, false); return xmlInputFactory; } private  SafeXml(); static XMLInputFactory newXmlInputFactory(); static DocumentBuilderFactory newdocumentBuilderFactory(); static DocumentBuilderFactory newStrictDocumentBuilderFactory(); static TransformerFactory newTransformerFactory(); static SAXTransformerFactory newSaxTransformerFactory(); static SAXParserFactory newSaxParserFactory(); static SAXParserFactory newStrictSaxParserFactory(); }
SafeXml { public static XMLInputFactory newXmlInputFactory() { final XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(SUPPORT_DTD, false); xmlInputFactory.setProperty(IS_SUPPORTING_EXTERNAL_ENTITIES, false); return xmlInputFactory; } private  SafeXml(); static XMLInputFactory newXmlInputFactory(); static DocumentBuilderFactory newdocumentBuilderFactory(); static DocumentBuilderFactory newStrictDocumentBuilderFactory(); static TransformerFactory newTransformerFactory(); static SAXTransformerFactory newSaxTransformerFactory(); static SAXParserFactory newSaxParserFactory(); static SAXParserFactory newStrictSaxParserFactory();  }