Add utility to create a org.xml.sax.XMLReader

Closes gh-1471
This commit is contained in:
Stéphane Nicoll
2025-03-08 12:19:32 +01:00
parent 51964f9040
commit 57e3880ce3
9 changed files with 49 additions and 42 deletions

View File

@@ -26,7 +26,6 @@ import java.nio.charset.StandardCharsets;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLInputFactory;
@@ -188,9 +187,7 @@ public abstract class AbstractWebServiceMessageTest {
}
private void validateMessage() throws Exception {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
XMLReader xmlReader = parserFactory.newSAXParser().getXMLReader();
XMLReader xmlReader = SaxUtils.namespaceAwareXmlReader();
xmlReader.setContentHandler(new DefaultHandler());
ByteArrayOutputStream os = new ByteArrayOutputStream();
this.webServiceMessage.writeTo(os);

View File

@@ -24,7 +24,6 @@ import java.nio.charset.StandardCharsets;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
@@ -41,6 +40,7 @@ import org.xml.sax.XMLReader;
import org.springframework.util.xml.StaxUtils;
import org.springframework.xml.DocumentBuilderFactoryUtils;
import org.springframework.xml.XMLInputFactoryUtils;
import org.springframework.xml.sax.SaxUtils;
@SuppressWarnings("Since15")
public abstract class AbstractEndpointTest {
@@ -67,9 +67,7 @@ public abstract class AbstractEndpointTest {
@Test
public void testSaxSource() throws Exception {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
XMLReader reader = parserFactory.newSAXParser().getXMLReader();
XMLReader reader = SaxUtils.namespaceAwareXmlReader();
InputSource inputSource = new InputSource(new StringReader(REQUEST));
testSource(new SAXSource(reader, inputSource));
}