diff --git a/build.gradle b/build.gradle index 4d570153a9..f5f3c9012f 100644 --- a/build.gradle +++ b/build.gradle @@ -769,7 +769,7 @@ project('spring-integration-xml') { compile project(":spring-integration-core") compile "org.springframework:spring-oxm:$springVersion" compile ("org.springframework.ws:spring-xml:$springWsVersion") - compile ("org.springframework.ws:spring-ws-core:$springWsVersion") + compile ("org.springframework.ws:spring-ws-core:$springWsVersion", optional) } } diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/UnmarshallingTransformer.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/UnmarshallingTransformer.java index b94c0a0f8c..82902df003 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/UnmarshallingTransformer.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/UnmarshallingTransformer.java @@ -147,7 +147,7 @@ public class UnmarshallingTransformer extends AbstractPayloadTransformer SERVLET_CONTEXT_RESOURCE_CLASS; + static { + Class aClass = null; + try { + aClass = + ClassUtils.forName("org.springframework.web.context.support.ServletContextResource", + ClassUtils.getDefaultClassLoader()); + } + + catch (ClassNotFoundException e) { + // No 'ServletContextResource' class present - ignoring + } + finally { + SERVLET_CONTEXT_RESOURCE_CLASS = aClass; + } + } public XsltPayloadTransformer(Templates templates) { this(templates, null); } + private ClassLoader classLoader; + public XsltPayloadTransformer(Templates templates, ResultTransformer resultTransformer) { Assert.notNull(templates, "'templates' must not be null."); this.templates = templates; @@ -140,8 +156,11 @@ public class XsltPayloadTransformer extends AbstractXmlTransformer implements Be String transformerFactoryClassName) { Assert.notNull(xslResource, "'xslResource' must not be null."); - Assert.isTrue(xslResource instanceof ClassPathResource || xslResource instanceof FileSystemResource || - xslResource instanceof ServletContextResource || xslResource instanceof VfsResource, + Assert.isTrue(xslResource instanceof ClassPathResource || // NOSONAR boolean complexity + xslResource instanceof FileSystemResource || + xslResource instanceof VfsResource || + (SERVLET_CONTEXT_RESOURCE_CLASS != null + && SERVLET_CONTEXT_RESOURCE_CLASS.isInstance(xslResource)), "Only 'ClassPathResource', 'FileSystemResource', 'ServletContextResource' or 'VfsResource'" + " are supported directly in this transformer. For any other 'Resource' implementations" + " consider to use a 'Templates'-based constructor instantiation."); @@ -227,7 +246,7 @@ public class XsltPayloadTransformer extends AbstractXmlTransformer implements Be this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); if (this.templates == null) { try { - TransformerFactory transformerFactory = createTransformerFactory(); + TransformerFactory transformerFactory = createTransformerFactory(); this.templates = transformerFactory.newTemplates(createStreamSourceOnResource(this.xslResource)); } catch (ClassNotFoundException | TransformerConfigurationException | IOException e) {