Skip to content

Commit 1f05307

Browse files
committed
SWS-1049 - Replace direct API usage with better defaults.
1 parent cd27d47 commit 1f05307

File tree

76 files changed

+850
-279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+850
-279
lines changed

spring-ws-core/src/main/java/org/springframework/ws/client/support/destination/Wsdl11DestinationProvider.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.ws.client.WebServiceIOException;
3333
import org.springframework.ws.client.WebServiceTransformerException;
3434
import org.springframework.xml.transform.ResourceSource;
35+
import org.springframework.xml.transform.TransformerFactoryUtils;
3536
import org.springframework.xml.xpath.XPathExpression;
3637
import org.springframework.xml.xpath.XPathExpressionFactory;
3738

@@ -52,7 +53,7 @@ public class Wsdl11DestinationProvider extends AbstractCachingDestinationProvide
5253
public static final String DEFAULT_WSDL_LOCATION_EXPRESSION =
5354
"/wsdl:definitions/wsdl:service/wsdl:port/soap:address/@location";
5455

55-
private static TransformerFactory transformerFactory = TransformerFactory.newInstance();
56+
private static TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance();
5657

5758
private Map<String, String> expressionNamespaces = new HashMap<String, String>();
5859

spring-ws-core/src/main/java/org/springframework/ws/pox/dom/DomPoxMessageFactory.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.util.Assert;
3030
import org.springframework.ws.WebServiceMessageFactory;
3131
import org.springframework.xml.transform.TransformerObjectSupport;
32+
import org.springframework.xml.DocumentBuilderFactoryUtils;
3233

3334
/**
3435
* Implementation of the {@link WebServiceMessageFactory} interface that creates a {@link DomPoxMessage}.
@@ -42,11 +43,25 @@ public class DomPoxMessageFactory extends TransformerObjectSupport implements We
4243
/** The default content type for the POX messages. */
4344
public static final String DEFAULT_CONTENT_TYPE = "application/xml";
4445

45-
private DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
46+
private DocumentBuilderFactory documentBuilderFactory;
4647

4748
private String contentType = DEFAULT_CONTENT_TYPE;
4849

50+
/**
51+
* Use default {@link DocumentBuilderFactory}.
52+
*/
4953
public DomPoxMessageFactory() {
54+
this(DocumentBuilderFactoryUtils.newInstance());
55+
}
56+
57+
/**
58+
* Provide your own {@link DocumentBuilderFactory}.
59+
*
60+
* @param documentBuilderFactory
61+
*/
62+
public DomPoxMessageFactory(DocumentBuilderFactory documentBuilderFactory) {
63+
this.documentBuilderFactory = documentBuilderFactory;
64+
5065
documentBuilderFactory.setNamespaceAware(true);
5166
documentBuilderFactory.setValidating(false);
5267
documentBuilderFactory.setExpandEntityReferences(false);

spring-ws-core/src/main/java/org/springframework/ws/server/endpoint/AbstractDomPayloadEndpoint.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.w3c.dom.Node;
3030

3131
import org.springframework.xml.transform.TransformerObjectSupport;
32+
import org.springframework.xml.DocumentBuilderFactoryUtils;
3233

3334
/**
3435
* Abstract base class for endpoints that handle the message payload as DOM elements.
@@ -120,7 +121,7 @@ protected DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory)
120121
* @throws ParserConfigurationException if thrown by JAXP methods
121122
*/
122123
protected DocumentBuilderFactory createDocumentBuilderFactory() throws ParserConfigurationException {
123-
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
124+
DocumentBuilderFactory factory = DocumentBuilderFactoryUtils.newInstance();
124125
factory.setValidating(validating);
125126
factory.setNamespaceAware(namespaceAware);
126127
factory.setExpandEntityReferences(expandEntityReferences);

spring-ws-core/src/main/java/org/springframework/ws/server/endpoint/AbstractStaxPayloadEndpoint.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import javax.xml.stream.XMLInputFactory;
2020
import javax.xml.stream.XMLOutputFactory;
2121

22+
import org.springframework.xml.XMLInputFactoryUtils;
2223
import org.springframework.xml.transform.TransformerObjectSupport;
2324

2425
/**
@@ -63,7 +64,7 @@ protected final XMLOutputFactory getOutputFactory() {
6364
* @return the created {@code XMLInputFactory}
6465
*/
6566
protected XMLInputFactory createXmlInputFactory() {
66-
return XMLInputFactory.newInstance();
67+
return XMLInputFactoryUtils.newInstance();
6768
}
6869

6970
/**

spring-ws-core/src/main/java/org/springframework/ws/server/endpoint/adapter/method/SourcePayloadMethodProcessor.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
import javax.xml.transform.stax.StAXSource;
3030
import javax.xml.transform.stream.StreamSource;
3131

32-
import org.springframework.core.MethodParameter;
33-
import org.springframework.xml.JaxpVersion;
34-
3532
import org.w3c.dom.Document;
3633
import org.w3c.dom.Node;
3734
import org.xml.sax.InputSource;
3835

36+
import org.springframework.core.MethodParameter;
37+
import org.springframework.xml.JaxpVersion;
38+
import org.springframework.xml.XMLInputFactoryUtils;
39+
3940
/**
4041
* Implementation of {@link MethodArgumentResolver} and {@link MethodReturnValueHandler} that supports {@link Source}
4142
* objects.
@@ -125,7 +126,7 @@ private boolean supports(MethodParameter parameter) {
125126
* @return the created factory
126127
*/
127128
protected XMLInputFactory createXmlInputFactory() {
128-
return XMLInputFactory.newInstance();
129+
return XMLInputFactoryUtils.newInstance();
129130
}
130131

131132
/** Inner class to avoid a static JAXP 1.4 dependency. */

spring-ws-core/src/main/java/org/springframework/ws/server/endpoint/adapter/method/StaxPayloadMethodArgumentResolver.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.util.xml.StaxUtils;
3131
import org.springframework.ws.context.MessageContext;
3232
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
33+
import org.springframework.xml.XMLInputFactoryUtils;
3334
import org.springframework.xml.transform.TransformerObjectSupport;
3435

3536
/**
@@ -152,7 +153,7 @@ private XMLEventReader resolveEventReader(Source requestSource) throws Transform
152153
* @return the created factory
153154
*/
154155
protected XMLInputFactory createXmlInputFactory() {
155-
return XMLInputFactory.newInstance();
156+
return XMLInputFactoryUtils.newInstance();
156157
}
157158

158159
private ByteArrayInputStream convertToByteArrayInputStream(Source source) throws TransformerException {

spring-ws-core/src/main/java/org/springframework/ws/server/endpoint/adapter/method/dom/XomPayloadMethodProcessor.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@
2525
import javax.xml.transform.TransformerException;
2626
import javax.xml.transform.dom.DOMSource;
2727

28-
import org.springframework.core.MethodParameter;
29-
import org.springframework.ws.server.endpoint.adapter.method.AbstractPayloadSourceMethodProcessor;
30-
3128
import nu.xom.Builder;
3229
import nu.xom.Document;
3330
import nu.xom.Element;
3431
import nu.xom.ParsingException;
3532
import nu.xom.converters.DOMConverter;
3633
import org.w3c.dom.DOMImplementation;
3734

35+
import org.springframework.core.MethodParameter;
36+
import org.springframework.ws.server.endpoint.adapter.method.AbstractPayloadSourceMethodProcessor;
37+
import org.springframework.xml.DocumentBuilderFactoryUtils;
38+
3839
/**
3940
* Implementation of {@link org.springframework.ws.server.endpoint.adapter.method.MethodArgumentResolver
4041
* MethodArgumentResolver} and {@link org.springframework.ws.server.endpoint.adapter.method.MethodReturnValueHandler
@@ -104,7 +105,7 @@ private boolean supports(MethodParameter parameter) {
104105
* @return the created factory
105106
*/
106107
protected DocumentBuilderFactory createDocumentBuilderFactory() {
107-
return DocumentBuilderFactory.newInstance();
108+
return DocumentBuilderFactoryUtils.newInstance();
108109
}
109110

110111
}

spring-ws-core/src/main/java/org/springframework/ws/server/endpoint/mapping/PayloadRootAnnotationMethodEndpointMapping.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
3030
import org.springframework.ws.server.endpoint.annotation.PayloadRoots;
3131
import org.springframework.ws.server.endpoint.support.PayloadRootUtils;
32+
import org.springframework.xml.transform.TransformerFactoryUtils;
3233

3334
/**
3435
* Implementation of the {@link EndpointMapping} interface that uses the {@link PayloadRoot} annotation to map methods
@@ -54,7 +55,16 @@ public class PayloadRootAnnotationMethodEndpointMapping extends AbstractAnnotati
5455
private static TransformerFactory transformerFactory;
5556

5657
static {
57-
transformerFactory = TransformerFactory.newInstance();
58+
setTransformerFactory(TransformerFactoryUtils.newInstance());
59+
}
60+
61+
/**
62+
* Override the default {@link TransformerFactory}.
63+
*
64+
* @param transformerFactory
65+
*/
66+
public static void setTransformerFactory(TransformerFactory transformerFactory) {
67+
PayloadRootAnnotationMethodEndpointMapping.transformerFactory = transformerFactory;
5868
}
5969

6070
@Override

spring-ws-core/src/main/java/org/springframework/ws/server/endpoint/mapping/PayloadRootQNameEndpointMapping.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.springframework.ws.context.MessageContext;
2424
import org.springframework.ws.server.endpoint.support.PayloadRootUtils;
25+
import org.springframework.xml.transform.TransformerFactoryUtils;
2526

2627
/**
2728
* 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
4950
private static TransformerFactory transformerFactory;
5051

5152
static {
52-
transformerFactory = TransformerFactory.newInstance();
53+
setTransformerFactory(TransformerFactoryUtils.newInstance());
5354
}
5455

56+
/**
57+
* Override the default {@link TransformerFactory}.
58+
*
59+
* @param transformerFactory
60+
*/
61+
public static void setTransformerFactory(TransformerFactory transformerFactory) {
62+
PayloadRootQNameEndpointMapping.transformerFactory = transformerFactory;
63+
}
64+
5565
@Override
5666
protected QName resolveQName(MessageContext messageContext) throws TransformerException {
5767
return PayloadRootUtils.getPayloadRootQName(messageContext.getRequest().getPayloadSource(), transformerFactory);
5868
}
59-
6069
}

spring-ws-core/src/main/java/org/springframework/ws/server/endpoint/mapping/SimpleMethodEndpointMapping.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.ws.WebServiceMessage;
2727
import org.springframework.ws.context.MessageContext;
2828
import org.springframework.ws.server.endpoint.support.PayloadRootUtils;
29+
import org.springframework.xml.transform.TransformerFactoryUtils;
2930

3031
/**
3132
* Simple subclass of {@link AbstractMethodEndpointMapping} that maps from the local name of the request payload to
@@ -108,7 +109,7 @@ public void setMethodSuffix(String methodSuffix) {
108109
@Override
109110
public final void afterPropertiesSet() throws Exception {
110111
Assert.notEmpty(getEndpoints(), "'endpoints' is required");
111-
transformerFactory = TransformerFactory.newInstance();
112+
transformerFactory = TransformerFactoryUtils.newInstance();
112113
for (int i = 0; i < getEndpoints().length; i++) {
113114
registerMethods(getEndpoints()[i]);
114115
}

spring-ws-core/src/main/java/org/springframework/ws/server/endpoint/mapping/XPathPayloadEndpointMapping.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.util.StringUtils;
3030
import org.springframework.ws.WebServiceMessage;
3131
import org.springframework.ws.context.MessageContext;
32+
import org.springframework.xml.transform.TransformerFactoryUtils;
3233
import org.springframework.xml.xpath.XPathExpression;
3334
import org.springframework.xml.xpath.XPathExpressionFactory;
3435

@@ -86,7 +87,7 @@ public void afterPropertiesSet() throws Exception {
8687
else {
8788
expression = XPathExpressionFactory.createXPathExpression(expressionString, namespaces);
8889
}
89-
transformerFactory = TransformerFactory.newInstance();
90+
transformerFactory = TransformerFactoryUtils.newInstance();
9091
}
9192

9293
@Override

spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/AbstractAddressingVersion.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.springframework.xml.transform.TransformerObjectSupport;
5353
import org.springframework.xml.xpath.XPathExpression;
5454
import org.springframework.xml.xpath.XPathExpressionFactory;
55+
import org.springframework.xml.DocumentBuilderFactoryUtils;
5556

5657
/**
5758
* Abstract base class for {@link AddressingVersion} implementations. Uses {@link XPathExpression}s to retrieve
@@ -62,7 +63,7 @@
6263
*/
6364
public abstract class AbstractAddressingVersion extends TransformerObjectSupport implements AddressingVersion {
6465

65-
private static DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
66+
private static DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
6667

6768
private final XPathExpression toExpression;
6869

spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapMessageFactory.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.springframework.ws.soap.support.SoapUtils;
5454
import org.springframework.ws.transport.TransportConstants;
5555
import org.springframework.ws.transport.TransportInputStream;
56+
import org.springframework.xml.XMLInputFactoryUtils;
5657

5758
/**
5859
* Axiom-specific implementation of the {@link org.springframework.ws.WebServiceMessageFactory WebServiceMessageFactory}
@@ -366,7 +367,7 @@ protected String getCharSetEncoding(String contentType) {
366367
* @return the created factory
367368
*/
368369
protected XMLInputFactory createXmlInputFactory() {
369-
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
370+
XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance();
370371
inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, replacingEntityReferences);
371372
inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, supportingExternalEntities);
372373
return inputFactory;

spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/support/AxiomUtils.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.w3c.dom.Element;
3535

3636
import org.springframework.util.StringUtils;
37+
import org.springframework.xml.DocumentBuilderFactoryUtils;
3738

3839
/**
3940
* Collection of generic utility methods to work with Axiom. Includes conversion from {@code OMNamespace}s to
@@ -119,7 +120,7 @@ public static Document toDocument(SOAPEnvelope envelope) {
119120
envelope.serialize(bos);
120121

121122
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
122-
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
123+
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
123124
documentBuilderFactory.setNamespaceAware(true);
124125
return documentBuilderFactory.newDocumentBuilder().parse(bis);
125126
}

spring-ws-core/src/test/java/org/springframework/ws/AbstractWebServiceMessageTestCase.java

+15-12
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@
4040
import javax.xml.transform.stream.StreamResult;
4141
import javax.xml.transform.stream.StreamSource;
4242

43-
import org.springframework.core.io.ClassPathResource;
44-
import org.springframework.core.io.Resource;
45-
import org.springframework.util.FileCopyUtils;
46-
import org.springframework.util.xml.StaxUtils;
47-
import org.springframework.xml.sax.SaxUtils;
48-
import org.springframework.xml.transform.StringResult;
49-
5043
import org.custommonkey.xmlunit.XMLUnit;
5144
import org.junit.Before;
5245
import org.junit.Test;
@@ -56,7 +49,17 @@
5649
import org.xml.sax.helpers.DefaultHandler;
5750
import org.xml.sax.helpers.XMLReaderFactory;
5851

59-
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
52+
import org.springframework.core.io.ClassPathResource;
53+
import org.springframework.core.io.Resource;
54+
import org.springframework.util.FileCopyUtils;
55+
import org.springframework.util.xml.StaxUtils;
56+
import org.springframework.xml.XMLInputFactoryUtils;
57+
import org.springframework.xml.sax.SaxUtils;
58+
import org.springframework.xml.transform.StringResult;
59+
import org.springframework.xml.transform.TransformerFactoryUtils;
60+
import org.springframework.xml.DocumentBuilderFactoryUtils;
61+
62+
import static org.custommonkey.xmlunit.XMLAssert.*;
6063

6164
public abstract class AbstractWebServiceMessageTestCase {
6265

@@ -74,7 +77,7 @@ private String getExpectedString() throws IOException {
7477

7578
@Before
7679
public final void setUp() throws Exception {
77-
TransformerFactory transformerFactory = TransformerFactory.newInstance();
80+
TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance();
7881
transformer = transformerFactory.newTransformer();
7982
webServiceMessage = createWebServiceMessage();
8083
payload = new ClassPathResource("payload.xml", AbstractWebServiceMessageTestCase.class);
@@ -83,7 +86,7 @@ public final void setUp() throws Exception {
8386

8487
@Test
8588
public void testDomPayload() throws Exception {
86-
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
89+
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance();
8790
documentBuilderFactory.setNamespaceAware(true);
8891
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
8992
Document payloadDocument = documentBuilder.parse(SaxUtils.createInputSource(payload));
@@ -98,7 +101,7 @@ public void testDomPayload() throws Exception {
98101

99102
@Test
100103
public void testEventReaderPayload() throws Exception {
101-
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
104+
XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance();
102105
XMLEventReader eventReader = inputFactory.createXMLEventReader(payload.getInputStream());
103106
Source staxSource = StaxUtils.createCustomStaxSource(eventReader);
104107
transformer.transform(staxSource, webServiceMessage.getPayloadResult());
@@ -148,7 +151,7 @@ public void testStreamPayload() throws Exception {
148151

149152
@Test
150153
public void testStreamReaderPayload() throws Exception {
151-
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
154+
XMLInputFactory inputFactory = XMLInputFactoryUtils.newInstance();
152155
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(payload.getInputStream());
153156
Source staxSource = StaxUtils.createCustomStaxSource(streamReader);
154157
transformer.transform(staxSource, webServiceMessage.getPayloadResult());

spring-ws-core/src/test/java/org/springframework/ws/MockWebServiceMessage.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.springframework.util.FileCopyUtils;
3838
import org.springframework.xml.sax.SaxUtils;
3939
import org.springframework.xml.transform.StringSource;
40+
import org.springframework.xml.transform.TransformerFactoryUtils;
4041

4142
/**
4243
* Mock implementation of the {@code WebServiceMessage} interface.
@@ -58,7 +59,7 @@ public MockWebServiceMessage() {
5859
}
5960

6061
public MockWebServiceMessage(Source source) throws TransformerException {
61-
TransformerFactory transformerFactory = TransformerFactory.newInstance();
62+
TransformerFactory transformerFactory = TransformerFactoryUtils.newInstance();
6263
Transformer transformer = transformerFactory.newTransformer();
6364
content = new StringBuilder();
6465
transformer.transform(source, getPayloadResult());

0 commit comments

Comments
 (0)