SWS-1049 - Replace direct API usage with better defaults.
This commit is contained in:
@@ -32,6 +32,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.ws.client.WebServiceIOException;
|
||||
import org.springframework.ws.client.WebServiceTransformerException;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
import org.springframework.xml.xpath.XPathExpression;
|
||||
import org.springframework.xml.xpath.XPathExpressionFactory;
|
||||
|
||||
@@ -52,7 +53,7 @@ public class Wsdl11DestinationProvider extends AbstractCachingDestinationProvide
|
||||
public static final String DEFAULT_WSDL_LOCATION_EXPRESSION =
|
||||
"/wsdl:definitions/wsdl:service/wsdl:port/soap:address/@location";
|
||||
|
||||
private static TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
private static TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
|
||||
private Map<String, String> expressionNamespaces = new HashMap<String, String>();
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.xml.sax.SAXException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.xml.transform.TransformerObjectSupport;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
/**
|
||||
* Implementation of the {@link WebServiceMessageFactory} interface that creates a {@link DomPoxMessage}.
|
||||
@@ -42,11 +43,25 @@ public class DomPoxMessageFactory extends TransformerObjectSupport implements We
|
||||
/** The default content type for the POX messages. */
|
||||
public static final String DEFAULT_CONTENT_TYPE = "application/xml";
|
||||
|
||||
private DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
private DocumentBuilderFactory documentBuilderFactory;
|
||||
|
||||
private String contentType = DEFAULT_CONTENT_TYPE;
|
||||
|
||||
/**
|
||||
* Use default {@link DocumentBuilderFactory}.
|
||||
*/
|
||||
public DomPoxMessageFactory() {
|
||||
this(DocumentBuilderFactoryUtils.newInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide your own {@link DocumentBuilderFactory}.
|
||||
*
|
||||
* @param documentBuilderFactory
|
||||
*/
|
||||
public DomPoxMessageFactory(DocumentBuilderFactory documentBuilderFactory) {
|
||||
this.documentBuilderFactory = documentBuilderFactory;
|
||||
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilderFactory.setValidating(false);
|
||||
documentBuilderFactory.setExpandEntityReferences(false);
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import org.springframework.xml.transform.TransformerObjectSupport;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
/**
|
||||
* Abstract base class for endpoints that handle the message payload as DOM elements.
|
||||
@@ -120,7 +121,7 @@ public abstract class AbstractDomPayloadEndpoint extends TransformerObjectSuppor
|
||||
* @throws ParserConfigurationException if thrown by JAXP methods
|
||||
*/
|
||||
protected DocumentBuilderFactory createDocumentBuilderFactory() throws ParserConfigurationException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactoryUtils.newInstance();
|
||||
factory.setValidating(validating);
|
||||
factory.setNamespaceAware(namespaceAware);
|
||||
factory.setExpandEntityReferences(expandEntityReferences);
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.ws.server.endpoint;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
|
||||
import org.springframework.xml.XMLInputFactoryUtils;
|
||||
import org.springframework.xml.transform.TransformerObjectSupport;
|
||||
|
||||
/**
|
||||
@@ -63,7 +64,7 @@ public abstract class AbstractStaxPayloadEndpoint extends TransformerObjectSuppo
|
||||
* @return the created {@code XMLInputFactory}
|
||||
*/
|
||||
protected XMLInputFactory createXmlInputFactory() {
|
||||
return XMLInputFactory.newInstance();
|
||||
return XMLInputFactoryUtils.newInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,13 +29,14 @@ import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stax.StAXSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.xml.JaxpVersion;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.xml.JaxpVersion;
|
||||
import org.springframework.xml.XMLInputFactoryUtils;
|
||||
|
||||
/**
|
||||
* Implementation of {@link MethodArgumentResolver} and {@link MethodReturnValueHandler} that supports {@link Source}
|
||||
* objects.
|
||||
@@ -125,7 +126,7 @@ public class SourcePayloadMethodProcessor extends AbstractPayloadSourceMethodPro
|
||||
* @return the created factory
|
||||
*/
|
||||
protected XMLInputFactory createXmlInputFactory() {
|
||||
return XMLInputFactory.newInstance();
|
||||
return XMLInputFactoryUtils.newInstance();
|
||||
}
|
||||
|
||||
/** Inner class to avoid a static JAXP 1.4 dependency. */
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.core.MethodParameter;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
|
||||
import org.springframework.xml.XMLInputFactoryUtils;
|
||||
import org.springframework.xml.transform.TransformerObjectSupport;
|
||||
|
||||
/**
|
||||
@@ -152,7 +153,7 @@ public class StaxPayloadMethodArgumentResolver extends TransformerObjectSupport
|
||||
* @return the created factory
|
||||
*/
|
||||
protected XMLInputFactory createXmlInputFactory() {
|
||||
return XMLInputFactory.newInstance();
|
||||
return XMLInputFactoryUtils.newInstance();
|
||||
}
|
||||
|
||||
private ByteArrayInputStream convertToByteArrayInputStream(Source source) throws TransformerException {
|
||||
|
||||
@@ -25,9 +25,6 @@ import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.ws.server.endpoint.adapter.method.AbstractPayloadSourceMethodProcessor;
|
||||
|
||||
import nu.xom.Builder;
|
||||
import nu.xom.Document;
|
||||
import nu.xom.Element;
|
||||
@@ -35,6 +32,10 @@ import nu.xom.ParsingException;
|
||||
import nu.xom.converters.DOMConverter;
|
||||
import org.w3c.dom.DOMImplementation;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.ws.server.endpoint.adapter.method.AbstractPayloadSourceMethodProcessor;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
/**
|
||||
* Implementation of {@link org.springframework.ws.server.endpoint.adapter.method.MethodArgumentResolver
|
||||
* MethodArgumentResolver} and {@link org.springframework.ws.server.endpoint.adapter.method.MethodReturnValueHandler
|
||||
@@ -104,7 +105,7 @@ public class XomPayloadMethodProcessor extends AbstractPayloadSourceMethodProces
|
||||
* @return the created factory
|
||||
*/
|
||||
protected DocumentBuilderFactory createDocumentBuilderFactory() {
|
||||
return DocumentBuilderFactory.newInstance();
|
||||
return DocumentBuilderFactoryUtils.newInstance();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.ws.server.EndpointMapping;
|
||||
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
|
||||
import org.springframework.ws.server.endpoint.annotation.PayloadRoots;
|
||||
import org.springframework.ws.server.endpoint.support.PayloadRootUtils;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
/**
|
||||
* Implementation of the {@link EndpointMapping} interface that uses the {@link PayloadRoot} annotation to map methods
|
||||
@@ -54,7 +55,16 @@ public class PayloadRootAnnotationMethodEndpointMapping extends AbstractAnnotati
|
||||
private static TransformerFactory transformerFactory;
|
||||
|
||||
static {
|
||||
transformerFactory = TransformerFactory.newInstance();
|
||||
setTransformerFactory(TransformerFactoryUtils.newInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the default {@link TransformerFactory}.
|
||||
*
|
||||
* @param transformerFactory
|
||||
*/
|
||||
public static void setTransformerFactory(TransformerFactory transformerFactory) {
|
||||
PayloadRootAnnotationMethodEndpointMapping.transformerFactory = transformerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,6 +22,7 @@ import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.endpoint.support.PayloadRootUtils;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
/**
|
||||
* Implementation of the {@code EndpointMapping} interface to map from the qualified name of the request payload
|
||||
@@ -49,12 +50,20 @@ public class PayloadRootQNameEndpointMapping extends AbstractQNameEndpointMappin
|
||||
private static TransformerFactory transformerFactory;
|
||||
|
||||
static {
|
||||
transformerFactory = TransformerFactory.newInstance();
|
||||
setTransformerFactory(TransformerFactoryUtils.newInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the default {@link TransformerFactory}.
|
||||
*
|
||||
* @param transformerFactory
|
||||
*/
|
||||
public static void setTransformerFactory(TransformerFactory transformerFactory) {
|
||||
PayloadRootQNameEndpointMapping.transformerFactory = transformerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected QName resolveQName(MessageContext messageContext) throws TransformerException {
|
||||
return PayloadRootUtils.getPayloadRootQName(messageContext.getRequest().getPayloadSource(), transformerFactory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.endpoint.support.PayloadRootUtils;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
/**
|
||||
* Simple subclass of {@link AbstractMethodEndpointMapping} that maps from the local name of the request payload to
|
||||
@@ -108,7 +109,7 @@ public class SimpleMethodEndpointMapping extends AbstractMethodEndpointMapping<S
|
||||
@Override
|
||||
public final void afterPropertiesSet() throws Exception {
|
||||
Assert.notEmpty(getEndpoints(), "'endpoints' is required");
|
||||
transformerFactory = TransformerFactory.newInstance();
|
||||
transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
for (int i = 0; i < getEndpoints().length; i++) {
|
||||
registerMethods(getEndpoints()[i]);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
import org.springframework.xml.xpath.XPathExpression;
|
||||
import org.springframework.xml.xpath.XPathExpressionFactory;
|
||||
|
||||
@@ -86,7 +87,7 @@ public class XPathPayloadEndpointMapping extends AbstractMapBasedEndpointMapping
|
||||
else {
|
||||
expression = XPathExpressionFactory.createXPathExpression(expressionString, namespaces);
|
||||
}
|
||||
transformerFactory = TransformerFactory.newInstance();
|
||||
transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.springframework.xml.namespace.QNameUtils;
|
||||
import org.springframework.xml.transform.TransformerObjectSupport;
|
||||
import org.springframework.xml.xpath.XPathExpression;
|
||||
import org.springframework.xml.xpath.XPathExpressionFactory;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link AddressingVersion} implementations. Uses {@link XPathExpression}s to retrieve
|
||||
@@ -62,7 +63,7 @@ import org.springframework.xml.xpath.XPathExpressionFactory;
|
||||
*/
|
||||
public abstract class AbstractAddressingVersion extends TransformerObjectSupport implements AddressingVersion {
|
||||
|
||||
private static DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
private static DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
|
||||
private final XPathExpression toExpression;
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.springframework.ws.soap.server.endpoint.mapping.SoapActionAnnotationM
|
||||
import org.springframework.ws.soap.support.SoapUtils;
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
import org.springframework.xml.XMLInputFactoryUtils;
|
||||
|
||||
/**
|
||||
* Axiom-specific implementation of the {@link org.springframework.ws.WebServiceMessageFactory WebServiceMessageFactory}
|
||||
@@ -364,7 +365,7 @@ public class AxiomSoapMessageFactory implements SoapMessageFactory, Initializing
|
||||
* @return the created factory
|
||||
*/
|
||||
protected XMLInputFactory createXmlInputFactory() {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance();
|
||||
inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, replacingEntityReferences);
|
||||
inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, supportingExternalEntities);
|
||||
return inputFactory;
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
/**
|
||||
* Collection of generic utility methods to work with Axiom. Includes conversion from {@code OMNamespace}s to
|
||||
@@ -119,7 +120,7 @@ public abstract class AxiomUtils {
|
||||
envelope.serialize(bos);
|
||||
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
return documentBuilderFactory.newDocumentBuilder().parse(bis);
|
||||
}
|
||||
|
||||
@@ -40,13 +40,6 @@ import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -56,7 +49,17 @@ import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
import org.springframework.xml.XMLInputFactoryUtils;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
public abstract class AbstractWebServiceMessageTestCase {
|
||||
|
||||
@@ -74,7 +77,7 @@ public abstract class AbstractWebServiceMessageTestCase {
|
||||
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
webServiceMessage = createWebServiceMessage();
|
||||
payload = new ClassPathResource("payload.xml", AbstractWebServiceMessageTestCase.class);
|
||||
@@ -83,7 +86,7 @@ public abstract class AbstractWebServiceMessageTestCase {
|
||||
|
||||
@Test
|
||||
public void testDomPayload() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document payloadDocument = documentBuilder.parse(SaxUtils.createInputSource(payload));
|
||||
@@ -98,7 +101,7 @@ public abstract class AbstractWebServiceMessageTestCase {
|
||||
|
||||
@Test
|
||||
public void testEventReaderPayload() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance();
|
||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(payload.getInputStream());
|
||||
Source staxSource = StaxUtils.createCustomStaxSource(eventReader);
|
||||
transformer.transform(staxSource, webServiceMessage.getPayloadResult());
|
||||
@@ -148,7 +151,7 @@ public abstract class AbstractWebServiceMessageTestCase {
|
||||
|
||||
@Test
|
||||
public void testStreamReaderPayload() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance();
|
||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(payload.getInputStream());
|
||||
Source staxSource = StaxUtils.createCustomStaxSource(streamReader);
|
||||
transformer.transform(staxSource, webServiceMessage.getPayloadResult());
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
/**
|
||||
* Mock implementation of the {@code WebServiceMessage} interface.
|
||||
@@ -58,7 +59,7 @@ public class MockWebServiceMessage implements FaultAwareWebServiceMessage {
|
||||
}
|
||||
|
||||
public MockWebServiceMessage(Source source) throws TransformerException {
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
content = new StringBuilder();
|
||||
transformer.transform(source, getPayloadResult());
|
||||
|
||||
@@ -39,12 +39,9 @@ import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -66,6 +63,10 @@ import org.springframework.ws.transport.http.HttpComponentsMessageSender;
|
||||
import org.springframework.ws.transport.support.FreePortScanner;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public abstract class AbstractSoap11WebServiceTemplateIntegrationTestCase {
|
||||
|
||||
@@ -130,7 +131,7 @@ public abstract class AbstractSoap11WebServiceTemplateIntegrationTestCase {
|
||||
|
||||
@Test
|
||||
public void marshalSendAndReceiveResponse() throws TransformerConfigurationException {
|
||||
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
final Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
final Object requestObject = new Object();
|
||||
Marshaller marshaller = new Marshaller() {
|
||||
|
||||
@@ -173,7 +174,7 @@ public abstract class AbstractSoap11WebServiceTemplateIntegrationTestCase {
|
||||
|
||||
@Test
|
||||
public void marshalSendAndReceiveNoResponse() throws TransformerConfigurationException {
|
||||
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
final Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
final Object requestObject = new Object();
|
||||
Marshaller marshaller = new Marshaller() {
|
||||
|
||||
|
||||
@@ -41,12 +41,9 @@ import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -67,6 +64,10 @@ import org.springframework.ws.transport.http.HttpComponentsMessageSender;
|
||||
import org.springframework.ws.transport.support.FreePortScanner;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public abstract class AbstractSoap12WebServiceTemplateIntegrationTestCase {
|
||||
|
||||
@@ -141,7 +142,7 @@ public abstract class AbstractSoap12WebServiceTemplateIntegrationTestCase {
|
||||
|
||||
@Test
|
||||
public void marshalSendAndReceiveResponse() throws TransformerConfigurationException {
|
||||
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
final Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
final Object requestObject = new Object();
|
||||
Marshaller marshaller = new Marshaller() {
|
||||
|
||||
@@ -184,7 +185,7 @@ public abstract class AbstractSoap12WebServiceTemplateIntegrationTestCase {
|
||||
|
||||
@Test
|
||||
public void marshalSendAndReceiveNoResponse() throws TransformerConfigurationException {
|
||||
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
final Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
final Object requestObject = new Object();
|
||||
Marshaller marshaller = new Marshaller() {
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -45,6 +44,10 @@ import org.springframework.ws.transport.http.HttpComponentsMessageSender;
|
||||
import org.springframework.ws.transport.support.FreePortScanner;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
public class DomPoxWebServiceTemplateIntegrationTest {
|
||||
|
||||
@@ -125,9 +128,9 @@ public class DomPoxWebServiceTemplateIntegrationTest {
|
||||
@Override
|
||||
public void init(ServletConfig servletConfig) throws ServletException {
|
||||
super.init(servletConfig);
|
||||
documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
transformerFactory = TransformerFactory.newInstance();
|
||||
transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,6 @@ import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.junit.Assert;
|
||||
@@ -39,6 +38,7 @@ import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.soap.saaj.support.SaajUtils;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
import org.springframework.xml.xsd.SimpleXsdSchema;
|
||||
|
||||
public class PayloadValidatingInterceptorTest {
|
||||
@@ -75,7 +75,7 @@ public class PayloadValidatingInterceptorTest {
|
||||
|
||||
soap11Factory = new SaajSoapMessageFactory(MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL));
|
||||
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,14 +22,16 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
public class DomPoxMessageTest {
|
||||
|
||||
@@ -39,10 +41,10 @@ public class DomPoxMessageTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
message = new DomPoxMessage(document, transformer, DomPoxMessageFactory.DEFAULT_CONTENT_TYPE);
|
||||
}
|
||||
|
||||
@@ -30,14 +30,16 @@ import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
import org.springframework.xml.XMLInputFactoryUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
@SuppressWarnings("Since15")
|
||||
public abstract class AbstractEndpointTestCase {
|
||||
|
||||
@@ -53,7 +55,7 @@ public abstract class AbstractEndpointTestCase {
|
||||
|
||||
@Test
|
||||
public void testDomSource() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document requestDocument = documentBuilder.parse(new InputSource(new StringReader(REQUEST)));
|
||||
@@ -69,14 +71,14 @@ public abstract class AbstractEndpointTestCase {
|
||||
|
||||
@Test
|
||||
public void testStaxSourceEventReader() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance();
|
||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(REQUEST));
|
||||
testSource(new SAXSource(StaxUtils.createXMLReader(eventReader), new InputSource()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaxSourceStreamReader() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance();
|
||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(REQUEST));
|
||||
testSource(new SAXSource(StaxUtils.createXMLReader(streamReader), new InputSource()));
|
||||
}
|
||||
|
||||
@@ -18,15 +18,15 @@ package org.springframework.ws.server.endpoint;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
@@ -39,7 +39,7 @@ public abstract class AbstractPayloadEndpointTestCase extends AbstractEndpointTe
|
||||
@Before
|
||||
public void createEndpoint() throws Exception {
|
||||
endpoint = createResponseEndpoint();
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,14 +23,10 @@ import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import org.junit.Assert;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -47,6 +43,11 @@ import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.mime.MimeMessage;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class MarshallingPayloadEndpointTest {
|
||||
|
||||
@@ -59,7 +60,7 @@ public class MarshallingPayloadEndpointTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockWebServiceMessage request = new MockWebServiceMessage("<request/>");
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
factoryMock = createMock(WebServiceMessageFactory.class);
|
||||
|
||||
context = new DefaultMessageContext(request, factoryMock);
|
||||
|
||||
@@ -22,7 +22,10 @@ import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.soap.SOAPFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
@@ -32,13 +35,14 @@ import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.soap.SOAPFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test case for AbstractStaxStreamPayloadEndpoint.
|
||||
@@ -101,7 +105,7 @@ public class StaxStreamPayloadEndpointTest extends AbstractMessageEndpointTestCa
|
||||
|
||||
@Test
|
||||
public void testSaajResponse() throws Exception {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
SaajSoapMessage request = new SaajSoapMessage(messageFactory.createMessage());
|
||||
transformer.transform(new StringSource(REQUEST), request.getPayloadResult());
|
||||
@@ -119,7 +123,7 @@ public class StaxStreamPayloadEndpointTest extends AbstractMessageEndpointTestCa
|
||||
|
||||
@Test
|
||||
public void testAxiomResponse() throws Exception {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
SOAPFactory axiomFactory = OMAbstractFactory.getSOAP11Factory();
|
||||
AxiomSoapMessage request = new AxiomSoapMessage(axiomFactory);
|
||||
transformer.transform(new StringSource(REQUEST), request.getPayloadResult());
|
||||
@@ -137,7 +141,7 @@ public class StaxStreamPayloadEndpointTest extends AbstractMessageEndpointTestCa
|
||||
|
||||
@Test
|
||||
public void testAxiomNoResponse() throws Exception {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
SOAPFactory axiomFactory = OMAbstractFactory.getSOAP11Factory();
|
||||
AxiomSoapMessage request = new AxiomSoapMessage(axiomFactory);
|
||||
transformer.transform(new StringSource(REQUEST), request.getPayloadResult());
|
||||
@@ -152,7 +156,7 @@ public class StaxStreamPayloadEndpointTest extends AbstractMessageEndpointTestCa
|
||||
|
||||
@Test
|
||||
public void testAxiomResponseNoPayloadCaching() throws Exception {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
SOAPFactory axiomFactory = OMAbstractFactory.getSOAP11Factory();
|
||||
AxiomSoapMessage request = new AxiomSoapMessage(axiomFactory);
|
||||
transformer.transform(new StringSource(REQUEST), request.getPayloadResult());
|
||||
@@ -172,7 +176,7 @@ public class StaxStreamPayloadEndpointTest extends AbstractMessageEndpointTestCa
|
||||
|
||||
@Test
|
||||
public void testAxiomNoResponseNoPayloadCaching() throws Exception {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
SOAPFactory axiomFactory = OMAbstractFactory.getSOAP11Factory();
|
||||
AxiomSoapMessage request = new AxiomSoapMessage(axiomFactory);
|
||||
transformer.transform(new StringSource(REQUEST), request.getPayloadResult());
|
||||
|
||||
@@ -20,21 +20,21 @@ import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.endpoint.PayloadEndpoint;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class PayloadEndpointAdapterTest {
|
||||
@@ -57,7 +57,7 @@ public class PayloadEndpointAdapterTest {
|
||||
@Test
|
||||
public void testInvoke() throws Exception {
|
||||
MockWebServiceMessage request = new MockWebServiceMessage("<request/>");
|
||||
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
final Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
PayloadEndpoint endpoint = new PayloadEndpoint() {
|
||||
public Source invoke(Source request) throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.ws.server.endpoint.MethodEndpoint;
|
||||
import org.springframework.ws.server.endpoint.annotation.XPathParam;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
@@ -141,7 +142,7 @@ public class XPathParamAnnotationMethodEndpointAdapterTest {
|
||||
|
||||
@Test
|
||||
public void testInvokeVoidDom() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
String rootNamespace = "http://rootnamespace";
|
||||
|
||||
@@ -20,17 +20,17 @@ import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.ws.server.endpoint.adapter.method.AbstractPayloadMethodProcessorTestCase;
|
||||
import org.springframework.ws.server.endpoint.adapter.method.AbstractPayloadSourceMethodProcessor;
|
||||
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
|
||||
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DomPayloadMethodProcessorTest extends AbstractPayloadMethodProcessorTestCase {
|
||||
|
||||
@@ -60,7 +60,7 @@ public class DomPayloadMethodProcessorTest extends AbstractPayloadMethodProcesso
|
||||
|
||||
@Override
|
||||
protected Element getReturnValue(MethodParameter returnType) throws ParserConfigurationException {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
return document.createElementNS(NAMESPACE_URI, LOCAL_NAME);
|
||||
|
||||
@@ -23,7 +23,6 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -39,6 +38,7 @@ import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
|
||||
import org.springframework.ws.soap.axiom.AxiomSoapMessage;
|
||||
import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -133,7 +133,7 @@ public class JaxbElementPayloadMethodProcessorTest {
|
||||
assertTrue("context has no response", messageContext.hasResponse());
|
||||
AxiomSoapMessage response = (AxiomSoapMessage) messageContext.getResponse();
|
||||
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
StringResult payloadResult = new StringResult();
|
||||
transformer.transform(response.getPayloadSource(), payloadResult);
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -49,6 +48,7 @@ import org.springframework.ws.soap.axiom.AxiomSoapMessage;
|
||||
import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory;
|
||||
import org.springframework.xml.sax.AbstractXmlReader;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -199,7 +199,7 @@ public class XmlRootElementPayloadMethodProcessorTest {
|
||||
assertTrue("context has no response", messageContext.hasResponse());
|
||||
AxiomSoapMessage response = (AxiomSoapMessage) messageContext.getResponse();
|
||||
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
StringResult payloadResult = new StringResult();
|
||||
transformer.transform(response.getPayloadSource(), payloadResult);
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
@@ -41,6 +40,9 @@ import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
public class PayloadTransformingInterceptorTest {
|
||||
|
||||
@@ -57,7 +59,7 @@ public class PayloadTransformingInterceptorTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
interceptor = new PayloadTransformingInterceptor();
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
input = new ClassPathResource("transformInput.xml", getClass());
|
||||
output = new ClassPathResource("transformOutput.xml", getClass());
|
||||
|
||||
@@ -24,30 +24,32 @@ import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
import org.springframework.xml.XMLInputFactoryUtils;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
public class PayloadRootUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetQNameForDomSource() throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactoryUtils.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.newDocument();
|
||||
Element element = document.createElementNS("namespace", "prefix:localname");
|
||||
document.appendChild(element);
|
||||
Source source = new DOMSource(document);
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactory.newInstance());
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactoryUtils.newInstance());
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
@@ -57,10 +59,10 @@ public class PayloadRootUtilsTest {
|
||||
@Test
|
||||
public void testGetQNameForStaxSourceStreamReader() throws Exception {
|
||||
String contents = "<prefix:localname xmlns:prefix='namespace'/>";
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance();
|
||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(contents));
|
||||
Source source = StaxUtils.createStaxSource(streamReader);
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactory.newInstance());
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactoryUtils.newInstance());
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
@@ -70,10 +72,10 @@ public class PayloadRootUtilsTest {
|
||||
@Test
|
||||
public void testGetQNameForStaxSourceEventReader() throws Exception {
|
||||
String contents = "<prefix:localname xmlns:prefix='namespace'/>";
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance();
|
||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(contents));
|
||||
Source source = StaxUtils.createStaxSource(eventReader);
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactory.newInstance());
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactoryUtils.newInstance());
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
@@ -84,7 +86,7 @@ public class PayloadRootUtilsTest {
|
||||
public void testGetQNameForStreamSource() throws Exception {
|
||||
String contents = "<prefix:localname xmlns:prefix='namespace'/>";
|
||||
Source source = new StreamSource(new StringReader(contents));
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactory.newInstance());
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactoryUtils.newInstance());
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
@@ -95,7 +97,7 @@ public class PayloadRootUtilsTest {
|
||||
public void testGetQNameForSaxSource() throws Exception {
|
||||
String contents = "<prefix:localname xmlns:prefix='namespace'/>";
|
||||
Source source = new SAXSource(new InputSource(new StringReader(contents)));
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactory.newInstance());
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactoryUtils.newInstance());
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
@@ -104,7 +106,7 @@ public class PayloadRootUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetQNameForNullSource() throws Exception {
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(null, TransformerFactory.newInstance());
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(null, TransformerFactoryUtils.newInstance());
|
||||
Assert.assertNull("Qname returned", qName);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,8 @@ import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
public abstract class AbstractSoapElementTestCase {
|
||||
|
||||
private SoapElement soapElement;
|
||||
@@ -33,7 +35,7 @@ public abstract class AbstractSoapElementTestCase {
|
||||
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
soapElement = createSoapElement();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,10 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLAssert;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.ws.InvalidXmlException;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
@@ -29,13 +32,9 @@ import org.springframework.ws.soap.soap11.AbstractSoap11MessageFactoryTestCase;
|
||||
import org.springframework.ws.transport.MockTransportInputStream;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLAssert;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class AxiomSoap11MessageFactoryTest extends AbstractSoap11MessageFactoryTestCase {
|
||||
|
||||
@@ -43,7 +42,7 @@ public class AxiomSoap11MessageFactoryTest extends AbstractSoap11MessageFactoryT
|
||||
|
||||
@Override
|
||||
protected WebServiceMessageFactory createMessageFactory() throws Exception {
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
|
||||
AxiomSoapMessageFactory factory = new AxiomSoapMessageFactory();
|
||||
factory.afterPropertiesSet();
|
||||
|
||||
@@ -24,11 +24,6 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.om.OMElement;
|
||||
import org.apache.axiom.om.OMFactory;
|
||||
@@ -43,7 +38,14 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.xml.XMLInputFactoryUtils;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
public class AxiomUtilsTest {
|
||||
|
||||
@@ -109,12 +111,12 @@ public class AxiomUtilsTest {
|
||||
public void testToDocument() throws Exception {
|
||||
Resource resource = new ClassPathResource("org/springframework/ws/soap/soap11/soap11.xml");
|
||||
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(resource));
|
||||
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance();
|
||||
XMLStreamReader reader = inputFactory.createXMLStreamReader(resource.getInputStream());
|
||||
StAXSOAPModelBuilder builder =
|
||||
new StAXSOAPModelBuilder(reader, OMAbstractFactory.getSOAP11Factory(), SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
|
||||
@@ -132,7 +134,7 @@ public class AxiomUtilsTest {
|
||||
byte[] buf = FileCopyUtils.copyToByteArray(resource.getFile());
|
||||
String expected = new String(buf, "UTF-8");
|
||||
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(SaxUtils.createInputSource(resource));
|
||||
|
||||
@@ -26,15 +26,15 @@ import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
public class SaajContentHandlerTest {
|
||||
|
||||
private SaajContentHandler handler;
|
||||
@@ -49,7 +49,7 @@ public class SaajContentHandlerTest {
|
||||
SOAPMessage message = messageFactory.createMessage();
|
||||
envelope = message.getSOAPPart().getEnvelope();
|
||||
handler = new SaajContentHandler(envelope.getBody());
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,16 +27,17 @@ import javax.xml.soap.SOAPEnvelope;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
public class SaajUtilsTest {
|
||||
|
||||
@@ -119,7 +120,7 @@ public class SaajUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testLoadMessage() throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactoryUtils.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.parse(getClass().getResourceAsStream("soapMessage.xml"));
|
||||
|
||||
@@ -21,7 +21,6 @@ import javax.xml.soap.SOAPEnvelope;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
@@ -31,7 +30,9 @@ import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
public class SaajXmlReaderTest {
|
||||
|
||||
@@ -47,7 +48,7 @@ public class SaajXmlReaderTest {
|
||||
message = messageFactory.createMessage();
|
||||
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
|
||||
saajReader = new SaajXmlReader(envelope);
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -51,6 +51,7 @@ import org.springframework.ws.soap.soap11.Soap11Fault;
|
||||
import org.springframework.ws.soap.soap12.Soap12Fault;
|
||||
import org.springframework.ws.transport.MockTransportInputStream;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
import org.springframework.xml.validation.ValidationErrorHandler;
|
||||
import org.springframework.xml.xsd.SimpleXsdSchema;
|
||||
|
||||
@@ -92,7 +93,7 @@ public class PayloadValidatingInterceptorTest {
|
||||
|
||||
soap11Factory = new SaajSoapMessageFactory(MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL));
|
||||
soap12Factory = new SaajSoapMessageFactory(MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL));
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.transport.MockTransportOutputStream;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -96,7 +97,7 @@ public abstract class AbstractSoap11MessageTestCase extends AbstractSoapMessageT
|
||||
transformer.transform(new StringSource("<payload xmlns='http://www.springframework.org' />"),
|
||||
soapMessage.getSoapBody().getPayloadResult());
|
||||
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document expected = documentBuilder.newDocument();
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.transport.MockTransportOutputStream;
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -100,7 +101,7 @@ public abstract class AbstractSoap12MessageTestCase extends AbstractSoapMessageT
|
||||
transformer.transform(new StringSource("<payload xmlns='http://www.springframework.org' />"),
|
||||
soapMessage.getSoapBody().getPayloadResult());
|
||||
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document expected = documentBuilder.newDocument();
|
||||
|
||||
@@ -56,6 +56,7 @@ import org.springframework.ws.transport.WebServiceConnection;
|
||||
import org.springframework.ws.transport.support.FreePortScanner;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -109,7 +110,7 @@ public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase {
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
saajMessageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
messageFactory = new SaajSoapMessageFactory(saajMessageFactory);
|
||||
transformerFactory = TransformerFactory.newInstance();
|
||||
transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
}
|
||||
|
||||
protected abstract AbstractHttpWebServiceMessageSender createMessageSender();
|
||||
|
||||
@@ -24,9 +24,7 @@ import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.junit.Assert;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -37,6 +35,10 @@ import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class HttpServletConnectionTest {
|
||||
|
||||
@@ -67,7 +69,7 @@ public class HttpServletConnectionTest {
|
||||
connection = new HttpServletConnection(httpServletRequest, httpServletResponse);
|
||||
MessageFactory saajMessageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
messageFactory = new SaajSoapMessageFactory(saajMessageFactory);
|
||||
transformerFactory = TransformerFactory.newInstance();
|
||||
transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,15 +21,16 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
public class LastModifiedHelperTest {
|
||||
|
||||
private Resource resource;
|
||||
@@ -50,7 +51,7 @@ public class LastModifiedHelperTest {
|
||||
|
||||
@Test
|
||||
public void testDomSource() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(resource.getFile());
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.ws.server.endpoint.adapter.PayloadEndpointAdapter;
|
||||
import org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping;
|
||||
import org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver;
|
||||
import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Assert;
|
||||
@@ -90,7 +91,7 @@ public class MessageDispatcherServletTest {
|
||||
new MockHttpServletRequest(HttpTransportConstants.METHOD_GET, "/definition.wsdl");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
servlet.service(request, response);
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document result = documentBuilder.parse(new ByteArrayInputStream(response.getContentAsByteArray()));
|
||||
|
||||
@@ -23,19 +23,20 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.ws.wsdl.WsdlDefinition;
|
||||
import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class WsdlDefinitionHandlerAdapterTest {
|
||||
@@ -98,7 +99,7 @@ public class WsdlDefinitionHandlerAdapterTest {
|
||||
|
||||
replay(definitionMock);
|
||||
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document result = documentBuilder.parse(getClass().getResourceAsStream("wsdl11-input.wsdl"));
|
||||
@@ -185,7 +186,7 @@ public class WsdlDefinitionHandlerAdapterTest {
|
||||
adapter.handle(request, response, definition);
|
||||
|
||||
InputStream inputStream = new ByteArrayInputStream(response.getContentAsByteArray());
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document resultingDocument = documentBuilder.parse(inputStream);
|
||||
@@ -215,7 +216,7 @@ public class WsdlDefinitionHandlerAdapterTest {
|
||||
adapter.handle(request, response, definition);
|
||||
|
||||
InputStream inputStream = new ByteArrayInputStream(response.getContentAsByteArray());
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document resultingDocument = documentBuilder.parse(inputStream);
|
||||
|
||||
@@ -22,18 +22,19 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
import org.springframework.xml.xsd.SimpleXsdSchema;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class XsdSchemaHandlerAdapterTest {
|
||||
@@ -99,7 +100,7 @@ public class XsdSchemaHandlerAdapterTest {
|
||||
adapter.handle(request, response, schema);
|
||||
|
||||
InputStream inputStream = new ByteArrayInputStream(response.getContentAsByteArray());
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document resultingDocument = documentBuilder.parse(inputStream);
|
||||
|
||||
@@ -22,17 +22,19 @@ import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.xsd.SimpleXsdSchema;
|
||||
import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
import org.springframework.xml.xsd.SimpleXsdSchema;
|
||||
import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
public class DefaultWsdl11DefinitionTest {
|
||||
|
||||
@@ -45,9 +47,9 @@ public class DefaultWsdl11DefinitionTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
definition = new DefaultWsdl11Definition();
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
|
||||
@@ -24,7 +24,6 @@ import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
@@ -34,7 +33,10 @@ import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
public class Wsdl4jDefinitionTest {
|
||||
|
||||
@@ -55,7 +57,7 @@ public class Wsdl4jDefinitionTest {
|
||||
finally {
|
||||
is.close();
|
||||
}
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,7 +66,7 @@ public class Wsdl4jDefinitionTest {
|
||||
Assert.assertNotNull("Source is null", source);
|
||||
DOMResult result = new DOMResult();
|
||||
transformer.transform(source, result);
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document expected = documentBuilder.parse(getClass().getResourceAsStream("complete.wsdl"));
|
||||
|
||||
@@ -26,15 +26,16 @@ import javax.xml.namespace.QName;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
public class DefaultMessagesProviderTest {
|
||||
|
||||
private DefaultMessagesProvider provider;
|
||||
@@ -48,7 +49,7 @@ public class DefaultMessagesProviderTest {
|
||||
provider = new DefaultMessagesProvider();
|
||||
WSDLFactory factory = WSDLFactory.newInstance();
|
||||
definition = factory.newDefinition();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
}
|
||||
|
||||
@@ -26,15 +26,16 @@ import javax.xml.namespace.QName;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
public class SuffixBasedMessagesProviderTest {
|
||||
|
||||
private SuffixBasedMessagesProvider provider;
|
||||
@@ -49,7 +50,7 @@ public class SuffixBasedMessagesProviderTest {
|
||||
provider.setFaultSuffix("Foo");
|
||||
WSDLFactory factory = WSDLFactory.newInstance();
|
||||
definition = factory.newDefinition();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
}
|
||||
|
||||
@@ -25,19 +25,19 @@ import javax.xml.soap.SOAPHeader;
|
||||
import javax.xml.soap.SOAPHeaderElement;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SaajWss4jMessageInterceptorSignTest extends Wss4jMessageInterceptorSignTestCase {
|
||||
|
||||
@@ -46,7 +46,7 @@ public class SaajWss4jMessageInterceptorSignTest extends Wss4jMessageInterceptor
|
||||
|
||||
@Test
|
||||
public void testSignAndValidate() throws Exception {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
interceptor.setSecurementActions("Signature");
|
||||
interceptor.setEnableSignatureConfirmation(false);
|
||||
interceptor.setSecurementPassword("123456");
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.xml;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* @author Greg Turnquist
|
||||
* @since 3.0.5
|
||||
*/
|
||||
public class DocumentBuilderFactoryUtils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DocumentBuilderFactoryUtils.class);
|
||||
|
||||
/**
|
||||
* Build a {@link DocumentBuilderFactory} then set properties to prevent external entity access.
|
||||
*
|
||||
* @see DocumentBuilderFactory#newInstance()
|
||||
*/
|
||||
public static DocumentBuilderFactory newInstance() {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
try {
|
||||
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by " + factory.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by " + factory.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
} catch (ParserConfigurationException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("FEATURE 'http://apache.org/xml/features/disallow-doctype-decl' is probably not supported by " + factory.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||
} catch (ParserConfigurationException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("FEATURE 'http://xml.org/sax/features/external-general-entities' is probably not supported by " + factory.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||
} catch (ParserConfigurationException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("FEATURE 'http://xml.org/sax/features/external-parameter-entities' is probably not supported by " + factory.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
} catch (ParserConfigurationException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("FEATURE 'http://apache.org/xml/features/nonvalidating/load-external-dtd' is probably not supported by " + factory.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
factory.setXIncludeAware(false);
|
||||
factory.setExpandEntityReferences(false);
|
||||
} catch (Exception e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("Caught " + e.getMessage() + " attempting to configure your XML parser.");
|
||||
}
|
||||
}
|
||||
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,11 @@ import org.springframework.util.ClassUtils;
|
||||
* Helper class used to find the current version of JAXP. We cannot depend on the Java version, since JAXP can be
|
||||
* upgraded independently of the Java version.
|
||||
*
|
||||
* <p>Only distinguishes between JAXP 1.0, 1.1, 1.3, and 1.4, since JAXP 1.2 was a maintenance release with no new
|
||||
* <p>Only distinguishes between JAXP 1.0, 1.1, 1.3, 1.4, and 1.5, since JAXP 1.2 was a maintenance release with no new
|
||||
* classes.
|
||||
*
|
||||
* <p>Note that Spring-WS requires JDK 1.5 as of Spring-WS 2.0, and therefore has at least JAXP 1.3 available.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Greg Turnquist
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public abstract class JaxpVersion {
|
||||
@@ -52,19 +51,31 @@ public abstract class JaxpVersion {
|
||||
*/
|
||||
public static final int JAXP_14 = 4;
|
||||
|
||||
/**
|
||||
* Constant identifying JAXP 1.5.
|
||||
*/
|
||||
public static final int JAXP_15 = 5;
|
||||
|
||||
private static final String JAXP_14_CLASS_NAME = "javax.xml.transform.stax.StAXSource";
|
||||
|
||||
private static final String JAXP_15_CLASS_NAME = "javax.xml.validation.SchemaFactoryConfigurationError";
|
||||
|
||||
private static int jaxpVersion;
|
||||
|
||||
static {
|
||||
ClassLoader classLoader = JaxpVersion.class.getClassLoader();
|
||||
|
||||
try {
|
||||
ClassUtils.forName(JAXP_14_CLASS_NAME, classLoader);
|
||||
jaxpVersion = JAXP_14;
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// leave 1.3 as default (it's either 1.3 or unknown)
|
||||
jaxpVersion = JAXP_13;
|
||||
ClassUtils.forName(JAXP_15_CLASS_NAME, classLoader);
|
||||
jaxpVersion = JAXP_15;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
try {
|
||||
ClassUtils.forName(JAXP_14_CLASS_NAME, classLoader);
|
||||
jaxpVersion = JAXP_14;
|
||||
} catch (ClassNotFoundException e) {
|
||||
// leave 1.3 as default (it's either 1.3 or unknown)
|
||||
jaxpVersion = JAXP_13;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +87,7 @@ public abstract class JaxpVersion {
|
||||
* @see #JAXP_11
|
||||
* @see #JAXP_13
|
||||
* @see #JAXP_14
|
||||
* @see #JAXP_15
|
||||
*/
|
||||
public static int getJaxpVersion() {
|
||||
return jaxpVersion;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.xml;
|
||||
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
|
||||
/**
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
public class XMLInputFactoryUtils {
|
||||
|
||||
/**
|
||||
* Build an {@link XMLInputFactory} and set properties to prevent external entities from accessing.
|
||||
*
|
||||
* @see XMLInputFactory#newInstance()
|
||||
*/
|
||||
public static XMLInputFactory newInstance() {
|
||||
XMLInputFactory factory = XMLInputFactory.newInstance();
|
||||
|
||||
factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
|
||||
factory.setProperty("javax.xml.stream.isSupportingExternalEntities", false);
|
||||
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.xml.transform;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.TransformerFactoryConfigurationError;
|
||||
|
||||
/**
|
||||
* @author Greg Turnquist
|
||||
* @since 3.0.5
|
||||
*/
|
||||
public class TransformerFactoryUtils {
|
||||
|
||||
/**
|
||||
* Build a new {@link TransformerFactory} using the default constructor.
|
||||
*/
|
||||
public static TransformerFactory newInstance() {
|
||||
return defaultSettings(TransformerFactory.newInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an {@link TransformerFactory} and prevent external entities from accessing.
|
||||
*
|
||||
* @see TransformerFactory#newInstance()
|
||||
*/
|
||||
public static TransformerFactory newInstance(Class<? extends TransformerFactory> transformerFactoryClass) {
|
||||
try {
|
||||
return defaultSettings(transformerFactoryClass.newInstance());
|
||||
} catch (InstantiationException e) {
|
||||
throw new TransformerFactoryConfigurationError(e,
|
||||
"Could not instantiate TransformerFactory [" + transformerFactoryClass + "]");
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new TransformerFactoryConfigurationError(e,
|
||||
"Could not instantiate TransformerFactory [" + transformerFactoryClass + "]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent external entities from accessing.
|
||||
*/
|
||||
private static TransformerFactory defaultSettings(TransformerFactory factory) {
|
||||
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
|
||||
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.TransformerFactoryConfigurationError;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -83,16 +82,11 @@ public class TransformerHelper {
|
||||
*/
|
||||
protected TransformerFactory newTransformerFactory(Class<? extends TransformerFactory> transformerFactoryClass) {
|
||||
if (transformerFactoryClass != null) {
|
||||
try {
|
||||
return transformerFactoryClass.newInstance();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new TransformerFactoryConfigurationError(ex,
|
||||
"Could not instantiate TransformerFactory [" + transformerFactoryClass + "]");
|
||||
}
|
||||
}
|
||||
else {
|
||||
return TransformerFactory.newInstance();
|
||||
TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance(transformerFactoryClass);
|
||||
return transformerFactory;
|
||||
} else {
|
||||
TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
return transformerFactory;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.core.io.Resource;
|
||||
* Internal class that uses JAXP 1.0 features to create {@code XmlValidator} instances.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Greg Turnquist
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class Jaxp13ValidatorFactory {
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright 2005-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.xml.validation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.Validator;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXNotRecognizedException;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Internal class that uses JAXP 1.5 features to create an {@code XmlValidator} with settings to prevent
|
||||
* external entity access.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Greg Turnquist
|
||||
* @since 3.0.5
|
||||
*/
|
||||
abstract class Jaxp15ValidatorFactory {
|
||||
|
||||
private static final Log log = LogFactory.getLog(Jaxp15ValidatorFactory.class);
|
||||
|
||||
|
||||
static XmlValidator createValidator(Resource[] resources, String schemaLanguage) throws IOException {
|
||||
try {
|
||||
Schema schema = SchemaLoaderUtils.loadSchema(resources, schemaLanguage);
|
||||
return new Jaxp15Validator(schema);
|
||||
}
|
||||
catch (SAXException ex) {
|
||||
throw new XmlValidationException("Could not create Schema: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Jaxp15Validator implements XmlValidator {
|
||||
|
||||
private Schema schema;
|
||||
|
||||
public Jaxp15Validator(Schema schema) {
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SAXParseException[] validate(Source source) throws IOException {
|
||||
return validate(source, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SAXParseException[] validate(Source source, ValidationErrorHandler errorHandler) throws IOException {
|
||||
if (errorHandler == null) {
|
||||
errorHandler = new DefaultValidationErrorHandler();
|
||||
}
|
||||
Validator validator = schema.newValidator();
|
||||
|
||||
try {
|
||||
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
|
||||
} catch (SAXNotRecognizedException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by " + validator.getClass().getCanonicalName());
|
||||
}
|
||||
} catch (SAXNotSupportedException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by " + validator.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
|
||||
} catch (SAXNotRecognizedException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by " + validator.getClass().getCanonicalName());
|
||||
}
|
||||
} catch (SAXNotSupportedException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by " + validator.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
validator.setErrorHandler(errorHandler);
|
||||
try {
|
||||
validator.validate(source);
|
||||
return errorHandler.getErrors();
|
||||
}
|
||||
catch (SAXException ex) {
|
||||
throw new XmlValidationException("Could not validate source: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** {@code ErrorHandler} implementation that stores errors and fatal errors in a list. */
|
||||
private static class DefaultValidationErrorHandler implements ValidationErrorHandler {
|
||||
|
||||
private List<SAXParseException> errors = new ArrayList<SAXParseException>();
|
||||
|
||||
@Override
|
||||
public SAXParseException[] getErrors() {
|
||||
return errors.toArray(new SAXParseException[errors.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(SAXParseException ex) throws SAXException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(SAXParseException ex) throws SAXException {
|
||||
errors.add(ex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatalError(SAXParseException ex) throws SAXException {
|
||||
errors.add(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.xml.validation;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.xml.sax.SAXNotRecognizedException;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
|
||||
/**
|
||||
* @author Greg Turnquist
|
||||
* @since 3.0.5
|
||||
*/
|
||||
public class SchemaFactoryUtils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SchemaFactoryUtils.class);
|
||||
|
||||
/**
|
||||
* Build a {@link SchemaFactory} and set properties to prevent external entities from accessing.
|
||||
*
|
||||
* @see SchemaFactory#newInstance(String)
|
||||
*/
|
||||
public static SchemaFactory newInstance(String schemaLanguage) {
|
||||
SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
|
||||
|
||||
try {
|
||||
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
|
||||
} catch (SAXNotRecognizedException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by " + schemaFactory.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
} catch (SAXNotSupportedException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by " + schemaFactory.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "file,jar:file");
|
||||
} catch (SAXNotRecognizedException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by " + schemaFactory.getClass().getCanonicalName());
|
||||
}
|
||||
} catch (SAXNotSupportedException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by " + schemaFactory.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
return schemaFactory;
|
||||
}
|
||||
}
|
||||
@@ -21,14 +21,13 @@ import javax.xml.transform.Source;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
/**
|
||||
* Convenient utility methods for loading of {@link Schema} objects, performing standard handling of input streams.
|
||||
*
|
||||
@@ -67,14 +66,14 @@ public abstract class SchemaLoaderUtils {
|
||||
Assert.notEmpty(resources, "No resources given");
|
||||
Assert.hasLength(schemaLanguage, "No schema language provided");
|
||||
Source[] schemaSources = new Source[resources.length];
|
||||
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
|
||||
XMLReader xmlReader = XMLReaderFactoryUtils.createXMLReader();
|
||||
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
|
||||
for (int i = 0; i < resources.length; i++) {
|
||||
Assert.notNull(resources[i], "Resource is null");
|
||||
Assert.isTrue(resources[i].exists(), "Resource " + resources[i] + " does not exist");
|
||||
schemaSources[i] = new ResourceSource(xmlReader, resources[i]);
|
||||
}
|
||||
SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
|
||||
SchemaFactory schemaFactory = SchemaFactoryUtils.newInstance(schemaLanguage);
|
||||
return schemaFactory.newSchema(schemaSources);
|
||||
}
|
||||
|
||||
@@ -87,4 +86,5 @@ public abstract class SchemaLoaderUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.xml.validation;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
/**
|
||||
* @author Greg Turnquist
|
||||
* @since 3.0.5
|
||||
*/
|
||||
public class XMLReaderFactoryUtils {
|
||||
|
||||
/**
|
||||
* Build a {@link XMLReader} and set properties to prevent external entity access.
|
||||
*
|
||||
* @see XMLReaderFactory#createXMLReader()
|
||||
*/
|
||||
public static XMLReader createXMLReader() throws SAXException {
|
||||
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
|
||||
|
||||
xmlReader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
xmlReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
xmlReader.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||
xmlReader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||
|
||||
return xmlReader;
|
||||
}
|
||||
}
|
||||
@@ -19,13 +19,13 @@ package org.springframework.xml.validation;
|
||||
import java.io.IOException;
|
||||
import javax.xml.validation.Validator;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.xml.JaxpVersion;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Factory for {@link XmlValidator} objects, being aware of JAXP 1.3 {@link Validator}s, and JAXP 1.0 parsing
|
||||
* capabilities. Mainly for internal use within the framework.
|
||||
@@ -84,10 +84,15 @@ public abstract class XmlValidatorFactory {
|
||||
Assert.hasLength(schemaLanguage, "No schema language provided");
|
||||
Assert.isTrue(SCHEMA_W3C_XML.equals(schemaLanguage) || SCHEMA_RELAX_NG.equals(schemaLanguage),
|
||||
"Invalid schema language: " + schemaLanguage);
|
||||
Assert.noNullElements(schemaResources, "No null schemaResources allowed");
|
||||
for (Resource schemaResource : schemaResources) {
|
||||
Assert.isTrue(schemaResource.exists(), "schema [" + schemaResource + "] does not exist");
|
||||
}
|
||||
if (JaxpVersion.getJaxpVersion() >= JaxpVersion.JAXP_13) {
|
||||
if (JaxpVersion.getJaxpVersion() >= JaxpVersion.JAXP_15) {
|
||||
logger.trace("Creating JAXP 1.5 XmlValidator");
|
||||
return Jaxp15ValidatorFactory.createValidator(schemaResources, schemaLanguage);
|
||||
}
|
||||
else if (JaxpVersion.getJaxpVersion() >= JaxpVersion.JAXP_13) {
|
||||
logger.trace("Creating JAXP 1.3 XmlValidator");
|
||||
return Jaxp13ValidatorFactory.createValidator(schemaResources, schemaLanguage);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.xml.xsd;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* @author Greg Turnquist
|
||||
* @see 3.0.5
|
||||
*/
|
||||
public class DocumentBuilderFactoryUtils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DocumentBuilderFactoryUtils.class);
|
||||
|
||||
/**
|
||||
* Build a {@link DocumentBuilderFactory} then set properties to prevent external entity access.
|
||||
*
|
||||
* @see DocumentBuilderFactory#newInstance()
|
||||
*/
|
||||
public static DocumentBuilderFactory newInstance() {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
try {
|
||||
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by " + factory.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by " + factory.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
} catch (ParserConfigurationException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("FEATURE 'http://apache.org/xml/features/disallow-doctype-decl' is probably not supported by " + factory.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||
} catch (ParserConfigurationException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("FEATURE 'http://xml.org/sax/features/external-general-entities' is probably not supported by " + factory.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||
} catch (ParserConfigurationException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("FEATURE 'http://xml.org/sax/features/external-parameter-entities' is probably not supported by " + factory.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
} catch (ParserConfigurationException e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("FEATURE 'http://apache.org/xml/features/nonvalidating/load-external-dtd' is probably not supported by " + factory.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
factory.setXIncludeAware(false);
|
||||
factory.setExpandEntityReferences(false);
|
||||
} catch (Exception e) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("Caught " + e.getMessage() + " attempting to configure your XML parser.");
|
||||
}
|
||||
}
|
||||
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import org.xml.sax.SAXException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.validation.XmlValidator;
|
||||
import org.springframework.xml.validation.XmlValidatorFactory;
|
||||
@@ -47,7 +48,7 @@ import org.springframework.xml.validation.XmlValidatorFactory;
|
||||
*/
|
||||
public class SimpleXsdSchema implements XsdSchema, InitializingBean {
|
||||
|
||||
private static DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
private static DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
|
||||
private static final String SCHEMA_NAMESPACE = "http://www.w3.org/2001/XMLSchema";
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class DomContentHandlerTest {
|
||||
@@ -55,7 +57,7 @@ public class DomContentHandlerTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
result = documentBuilder.newDocument();
|
||||
|
||||
@@ -20,13 +20,14 @@ import javax.xml.namespace.QName;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
public class QNameUtilsTest {
|
||||
|
||||
@Test
|
||||
@@ -45,7 +46,7 @@ public class QNameUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetQNameForNodeNoNamespace() throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactoryUtils.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.newDocument();
|
||||
Element element = document.createElement("localname");
|
||||
@@ -59,7 +60,7 @@ public class QNameUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetQNameForNodeNoPrefix() throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactoryUtils.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.newDocument();
|
||||
Element element = document.createElementNS("namespace", "localname");
|
||||
@@ -72,7 +73,7 @@ public class QNameUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetQNameForNode() throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactoryUtils.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.newDocument();
|
||||
Element element = document.createElementNS("namespace", "prefix:localname");
|
||||
|
||||
@@ -17,20 +17,19 @@
|
||||
package org.springframework.xml.transform;
|
||||
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
public class ResourceSourceTest {
|
||||
|
||||
@Test
|
||||
public void testStringSource() throws Exception {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
DOMResult result = new DOMResult();
|
||||
ResourceSource source = new ResourceSource(new ClassPathResource("resourceSource.xml", getClass()));
|
||||
transformer.transform(source, result);
|
||||
|
||||
@@ -16,25 +16,25 @@
|
||||
|
||||
package org.springframework.xml.transform;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
public class StringResultTest {
|
||||
|
||||
@Test
|
||||
public void testStringResult() throws Exception {
|
||||
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
|
||||
Document document = DocumentBuilderFactoryUtils.newInstance().newDocumentBuilder().newDocument();
|
||||
Element element = document.createElementNS("namespace", "prefix:localName");
|
||||
document.appendChild(element);
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(new DOMSource(document), result);
|
||||
assertXMLEqual("Invalid result", "<prefix:localName xmlns:prefix='namespace'/>", result.toString());
|
||||
|
||||
@@ -29,7 +29,7 @@ public class StringSourceTest {
|
||||
|
||||
@Test
|
||||
public void testStringSource() throws TransformerException {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer();
|
||||
String content = "<prefix:content xmlns:prefix='namespace'/>";
|
||||
DOMResult result = new DOMResult();
|
||||
transformer.transform(new StringSource(content), result);
|
||||
|
||||
@@ -41,8 +41,6 @@ import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
@@ -55,13 +53,17 @@ import org.xml.sax.ext.LexicalHandler;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
import org.springframework.xml.XMLInputFactoryUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class TraxUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetDocument() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
@@ -73,7 +75,7 @@ public class TraxUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testDoWithDomSource() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
|
||||
@@ -89,7 +91,7 @@ public class TraxUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testDoWithDomResult() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
|
||||
@@ -137,7 +139,7 @@ public class TraxUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testDoWithStaxSourceEventReader() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance();
|
||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader("<element/>"));
|
||||
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
@@ -167,7 +169,7 @@ public class TraxUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testDoWithStaxSourceStreamReader() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance();
|
||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader("<element/>"));
|
||||
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
|
||||
@@ -23,10 +23,6 @@ import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
@@ -36,6 +32,11 @@ import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
public abstract class AbstractValidatorFactoryTestCase {
|
||||
|
||||
private XmlValidator validator;
|
||||
@@ -98,7 +99,7 @@ public abstract class AbstractValidatorFactoryTestCase {
|
||||
|
||||
@Test
|
||||
public void testHandleValidMessageDom() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
Document document = documentBuilderFactory.newDocumentBuilder()
|
||||
.parse(new InputSource(validInputStream));
|
||||
@@ -109,7 +110,7 @@ public abstract class AbstractValidatorFactoryTestCase {
|
||||
|
||||
@Test
|
||||
public void testHandleInvalidMessageDom() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
Document document = documentBuilderFactory.newDocumentBuilder()
|
||||
.parse(new InputSource(invalidInputStream));
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.xml.validation;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
public class Jaxp15ValidatorFactoryTest extends AbstractValidatorFactoryTestCase {
|
||||
|
||||
@Override
|
||||
protected XmlValidator createValidator(Resource[] schemaResources, String schemaLanguage) throws IOException {
|
||||
return Jaxp15ValidatorFactory.createValidator(schemaResources, schemaLanguage);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import org.w3c.dom.Node;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
public abstract class AbstractXPathExpressionFactoryTestCase {
|
||||
|
||||
@@ -46,7 +47,7 @@ public abstract class AbstractXPathExpressionFactoryTestCase {
|
||||
public void setUp() throws Exception {
|
||||
namespaces.put("prefix1", "namespace1");
|
||||
namespaces.put("prefix2", "namespace2");
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
InputStream inputStream = getClass().getResourceAsStream("nonamespaces.xml");
|
||||
|
||||
@@ -34,6 +34,7 @@ import javax.xml.transform.stream.StreamSource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
@@ -128,7 +129,7 @@ public abstract class AbstractXPathTemplateTestCase {
|
||||
|
||||
@Test
|
||||
public void testEvaluateDomSource() throws IOException, SAXException, ParserConfigurationException {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(SaxUtils.createInputSource(
|
||||
|
||||
@@ -22,18 +22,20 @@ import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.validation.XmlValidator;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
import org.springframework.xml.validation.XmlValidator;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
public abstract class AbstractXsdSchemaTestCase {
|
||||
|
||||
@@ -43,10 +45,10 @@ public abstract class AbstractXsdSchemaTestCase {
|
||||
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
}
|
||||
|
||||
@@ -22,20 +22,22 @@ import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.validation.XmlValidator;
|
||||
import org.springframework.xml.xsd.AbstractXsdSchemaTestCase;
|
||||
import org.springframework.xml.xsd.XsdSchema;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.transform.TransformerFactoryUtils;
|
||||
import org.springframework.xml.validation.XmlValidator;
|
||||
import org.springframework.xml.xsd.AbstractXsdSchemaTestCase;
|
||||
import org.springframework.xml.DocumentBuilderFactoryUtils;
|
||||
import org.springframework.xml.xsd.XsdSchema;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
public class CommonsXsdSchemaCollectionTest {
|
||||
|
||||
@@ -48,9 +50,9 @@ public class CommonsXsdSchemaCollectionTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
collection = new CommonsXsdSchemaCollection();
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
|
||||
Reference in New Issue
Block a user