Skip to content

Commit e9591c6

Browse files
artembilangaryrussell
authored andcommitted
Make spring-ws-core optional for SI-xml
It turns out that `spring-ws-core` brings too much WS stuff which triggers and auto-configuration to be enabled in Spring Boot app when we don't expect it. * The `UnmarshallingTransformer` is already aware of `MimeMessage` and `MarshallingUtils` being optional, so just remove redundant `public` modifier for `maybeUnmarshalMimeMessage()` method * Load `ServletContextResource` class in the `XsltPayloadTransformer` on demand making such a dependency as optional
1 parent a9a2fcc commit e9591c6

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ project('spring-integration-xml') {
769769
compile project(":spring-integration-core")
770770
compile "org.springframework:spring-oxm:$springVersion"
771771
compile ("org.springframework.ws:spring-xml:$springWsVersion")
772-
compile ("org.springframework.ws:spring-ws-core:$springWsVersion")
772+
compile ("org.springframework.ws:spring-ws-core:$springWsVersion", optional)
773773
}
774774
}
775775

spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/UnmarshallingTransformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private static class MimeMessageUnmarshallerHelper {
147147
this.delegate = unmarshaller;
148148
}
149149

150-
public Object maybeUnmarshalMimeMessage(Object payload) throws IOException {
150+
Object maybeUnmarshalMimeMessage(Object payload) throws IOException {
151151
if (payload instanceof org.springframework.ws.mime.MimeMessage) {
152152
return org.springframework.ws.support.MarshallingUtils.unmarshal(this.delegate,
153153
(org.springframework.ws.mime.MimeMessage) payload);

spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/XsltPayloadTransformer.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import org.springframework.util.ObjectUtils;
5454
import org.springframework.util.PatternMatchUtils;
5555
import org.springframework.util.StringUtils;
56-
import org.springframework.web.context.support.ServletContextResource;
5756
import org.springframework.xml.transform.StringResult;
5857
import org.springframework.xml.transform.StringSource;
5958
import org.springframework.xml.transform.TransformerFactoryUtils;
@@ -110,13 +109,30 @@ public class XsltPayloadTransformer extends AbstractXmlTransformer implements Be
110109

111110
private String[] xsltParamHeaders;
112111

113-
private ClassLoader classLoader;
112+
private static final Class<?> SERVLET_CONTEXT_RESOURCE_CLASS;
114113

114+
static {
115+
Class<?> aClass = null;
116+
try {
117+
aClass =
118+
ClassUtils.forName("org.springframework.web.context.support.ServletContextResource",
119+
ClassUtils.getDefaultClassLoader());
120+
}
121+
122+
catch (ClassNotFoundException e) {
123+
// No 'ServletContextResource' class present - ignoring
124+
}
125+
finally {
126+
SERVLET_CONTEXT_RESOURCE_CLASS = aClass;
127+
}
128+
}
115129

116130
public XsltPayloadTransformer(Templates templates) {
117131
this(templates, null);
118132
}
119133

134+
private ClassLoader classLoader;
135+
120136
public XsltPayloadTransformer(Templates templates, ResultTransformer resultTransformer) {
121137
Assert.notNull(templates, "'templates' must not be null.");
122138
this.templates = templates;
@@ -140,8 +156,11 @@ public XsltPayloadTransformer(Resource xslResource, ResultTransformer resultTran
140156
String transformerFactoryClassName) {
141157

142158
Assert.notNull(xslResource, "'xslResource' must not be null.");
143-
Assert.isTrue(xslResource instanceof ClassPathResource || xslResource instanceof FileSystemResource ||
144-
xslResource instanceof ServletContextResource || xslResource instanceof VfsResource,
159+
Assert.isTrue(xslResource instanceof ClassPathResource || // NOSONAR boolean complexity
160+
xslResource instanceof FileSystemResource ||
161+
xslResource instanceof VfsResource ||
162+
(SERVLET_CONTEXT_RESOURCE_CLASS != null
163+
&& SERVLET_CONTEXT_RESOURCE_CLASS.isInstance(xslResource)),
145164
"Only 'ClassPathResource', 'FileSystemResource', 'ServletContextResource' or 'VfsResource'" +
146165
" are supported directly in this transformer. For any other 'Resource' implementations" +
147166
" consider to use a 'Templates'-based constructor instantiation.");
@@ -227,7 +246,7 @@ protected void onInit() {
227246
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
228247
if (this.templates == null) {
229248
try {
230-
TransformerFactory transformerFactory = createTransformerFactory();
249+
TransformerFactory transformerFactory = createTransformerFactory();
231250
this.templates = transformerFactory.newTemplates(createStreamSourceOnResource(this.xslResource));
232251
}
233252
catch (ClassNotFoundException | TransformerConfigurationException | IOException e) {

0 commit comments

Comments
 (0)