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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 16 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 11 additions & 1 deletion
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

Lines changed: 11 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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
}

0 commit comments

Comments
 (0)