INT-3384: Rework JMS/XML Module XSD Enumerations
JIRA: https://jira.spring.io/browse/INT-3384 Polishing
This commit is contained in:
@@ -17,10 +17,10 @@
|
||||
package org.springframework.integration.xml.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.AbstractTransformerParser;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -38,8 +38,8 @@ public class MarshallingTransformerParser extends AbstractTransformerParser {
|
||||
@Override
|
||||
protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String resultTransformer = element.getAttribute("result-transformer");
|
||||
String resultFactory = element.getAttribute("result-factory");
|
||||
String resultType = element.getAttribute("result-type");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "result-type", "resultType");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "result-factory", "resultFactoryName");
|
||||
String marshaller = element.getAttribute("marshaller");
|
||||
Assert.hasText(marshaller, "the 'marshaller' attribute is required");
|
||||
builder.addConstructorArgReference(marshaller);
|
||||
@@ -50,7 +50,6 @@ public class MarshallingTransformerParser extends AbstractTransformerParser {
|
||||
if (StringUtils.hasText(extractPayload)) {
|
||||
builder.addPropertyValue("extractPayload", extractPayload);
|
||||
}
|
||||
XmlNamespaceUtils.configureResultFactory(builder, resultType, resultFactory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.integration.xml.config;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.integration.xml.result.DomResultFactory;
|
||||
import org.springframework.integration.xml.result.ResultFactory;
|
||||
import org.springframework.integration.xml.result.StringResultFactory;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Utility methods for the XML namespace.
|
||||
*
|
||||
* @author Jonas Partner
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
abstract class XmlNamespaceUtils {
|
||||
|
||||
private static final String DOM_RESULT = "DOMResult";
|
||||
|
||||
private static final String STRING_RESULT = "StringResult";
|
||||
|
||||
|
||||
/**
|
||||
* Helper method that encapsulates common logic for validating and building
|
||||
* a bean definition for a {@link ResultFactory} based on either the
|
||||
* 'result-factory' or 'result-type' attributes.
|
||||
*/
|
||||
static void configureResultFactory(BeanDefinitionBuilder builder, String resultType, String resultFactory) {
|
||||
boolean bothHaveText = StringUtils.hasText(resultFactory) && StringUtils.hasText(resultType);
|
||||
Assert.state(!bothHaveText, "Only one of 'result-factory' or 'result-type' should be specified.");
|
||||
if (StringUtils.hasText(resultType)) {
|
||||
Assert.state(resultType.equals(DOM_RESULT) || resultType.equals(STRING_RESULT),
|
||||
"Result type must be either 'DOMResult' or 'StringResult'");
|
||||
}
|
||||
if (StringUtils.hasText(resultFactory)) {
|
||||
builder.addPropertyReference("resultFactory", resultFactory);
|
||||
}
|
||||
else if (resultType.equals(STRING_RESULT)) {
|
||||
builder.addPropertyValue("resultFactory", new StringResultFactory());
|
||||
}
|
||||
else if (resultType.equals(DOM_RESULT)) {
|
||||
builder.addPropertyValue("resultFactory", new DomResultFactory());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,12 +34,6 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class XmlPayloadValidatingFilterParser extends AbstractConsumerEndpointParser {
|
||||
|
||||
/** Constant that defines a W3C XML Schema. */
|
||||
public static final String SCHEMA_W3C_XML = "http://www.w3.org/2001/XMLSchema";
|
||||
|
||||
/** Constant that defines a RELAX NG Schema. */
|
||||
public static final String SCHEMA_RELAX_NG = "http://relaxng.org/ns/structure/1.0";
|
||||
|
||||
@Override
|
||||
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder filterBuilder = BeanDefinitionBuilder.genericBeanDefinition(FilterFactoryBean.class);
|
||||
@@ -58,7 +52,7 @@ public class XmlPayloadValidatingFilterParser extends AbstractConsumerEndpointPa
|
||||
selectorBuilder.addConstructorArgValue(schemaLocation);
|
||||
// it is a restriction with the default value of 'xml-schema' which
|
||||
// corresponds to 'http://www.w3.org/2001/XMLSchema'
|
||||
String schemaType = "xml-schema".equals(element.getAttribute("schema-type")) ? SCHEMA_W3C_XML : SCHEMA_RELAX_NG;
|
||||
String schemaType = element.getAttribute("schema-type");
|
||||
selectorBuilder.addConstructorArgValue(schemaType);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.util.xml.DomUtils;
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mike Bazos
|
||||
* @author liujiong
|
||||
*/
|
||||
public class XsltPayloadTransformerParser extends AbstractTransformerParser {
|
||||
|
||||
@@ -50,8 +51,8 @@ public class XsltPayloadTransformerParser extends AbstractTransformerParser {
|
||||
String xslResource = element.getAttribute("xsl-resource");
|
||||
String xslTemplates = element.getAttribute("xsl-templates");
|
||||
String resultTransformer = element.getAttribute("result-transformer");
|
||||
String resultFactory = element.getAttribute("result-factory");
|
||||
String resultType = element.getAttribute("result-type");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "result-type");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "result-factory", "resultFactoryName");
|
||||
String transformerFactoryClass = element.getAttribute("transformer-factory-class");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "xslt-param-headers");
|
||||
Assert.isTrue(StringUtils.hasText(xslResource) ^ StringUtils.hasText(xslTemplates),
|
||||
@@ -62,11 +63,6 @@ public class XsltPayloadTransformerParser extends AbstractTransformerParser {
|
||||
else if (StringUtils.hasText(xslTemplates)) {
|
||||
builder.addConstructorArgReference(xslTemplates);
|
||||
}
|
||||
XmlNamespaceUtils.configureResultFactory(builder, resultType, resultFactory);
|
||||
boolean resultFactorySpecified = StringUtils.hasText(resultFactory) || StringUtils.hasText(resultType);
|
||||
if(resultFactorySpecified){
|
||||
builder.addPropertyValue("alwaysUseResultFactory", true);
|
||||
}
|
||||
if (StringUtils.hasText(resultTransformer)) {
|
||||
builder.addConstructorArgReference(resultTransformer);
|
||||
}
|
||||
|
||||
@@ -40,10 +40,29 @@ import org.springframework.xml.validation.XmlValidatorFactory;
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Liujiong
|
||||
* @since 2.0
|
||||
*/
|
||||
public class XmlValidatingMessageSelector implements MessageSelector {
|
||||
|
||||
public enum SchemaType {
|
||||
|
||||
XML_SCHEMA(XmlValidatorFactory.SCHEMA_W3C_XML),
|
||||
|
||||
RELAX_NG(XmlValidatorFactory.SCHEMA_RELAX_NG);
|
||||
|
||||
private final String url;
|
||||
|
||||
private SchemaType(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final XmlValidator xmlValidator;
|
||||
@@ -58,6 +77,7 @@ public class XmlValidatingMessageSelector implements MessageSelector {
|
||||
this.xmlValidator = xmlValidator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a selector with a default {@link XmlValidator}. The validator will be initialized with
|
||||
* the provided 'schema' location {@link Resource} and 'schemaType'. The valid options for schema
|
||||
@@ -69,12 +89,17 @@ public class XmlValidatingMessageSelector implements MessageSelector {
|
||||
*
|
||||
* @throws IOException if the XmlValidatorFactory fails to create a validator
|
||||
*/
|
||||
public XmlValidatingMessageSelector(Resource schema, String schemaType) throws IOException {
|
||||
public XmlValidatingMessageSelector(Resource schema, SchemaType schemaType) throws IOException {
|
||||
Assert.notNull(schema, "You must provide XML schema location to perform validation");
|
||||
if (!StringUtils.hasText(schemaType)) {
|
||||
schemaType = XmlValidatorFactory.SCHEMA_W3C_XML;
|
||||
if (schemaType == null) {
|
||||
schemaType = SchemaType.XML_SCHEMA;
|
||||
}
|
||||
this.xmlValidator = XmlValidatorFactory.createValidator(schema, schemaType);
|
||||
this.xmlValidator = XmlValidatorFactory.createValidator(schema, schemaType.getUrl());
|
||||
}
|
||||
|
||||
public XmlValidatingMessageSelector(Resource schema, String schemaType) throws IOException {
|
||||
this(schema, StringUtils.isEmpty(schemaType) ? null :
|
||||
SchemaType.valueOf(schemaType.toUpperCase().replaceFirst("-", "_")));
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +131,7 @@ public class XmlValidatingMessageSelector implements MessageSelector {
|
||||
if (this.throwExceptionOnRejection) {
|
||||
throw new MessageRejectedException(message, "Message was rejected due to XML Validation errors",
|
||||
new AggregatedXmlMessageValidationException(
|
||||
Arrays.<Throwable> asList(validationExceptions)));
|
||||
Arrays.<Throwable>asList(validationExceptions)));
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Message was rejected due to XML Validation errors");
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.integration.xml.transformer;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.integration.transformer.AbstractTransformer;
|
||||
import org.springframework.integration.xml.result.DomResultFactory;
|
||||
import org.springframework.integration.xml.result.ResultFactory;
|
||||
import org.springframework.integration.xml.result.StringResultFactory;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* super class for XmlTransformer
|
||||
*
|
||||
* @author Jonas Partner
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @author Liujiong
|
||||
*/
|
||||
public abstract class AbstractXmlTransformer extends AbstractTransformer {
|
||||
|
||||
public static final String DOM_RESULT = "DOMResult";
|
||||
|
||||
public static final String STRING_RESULT = "StringResult";
|
||||
|
||||
private volatile String resultType;
|
||||
|
||||
private volatile String resultFactoryName;
|
||||
|
||||
private volatile ResultFactory resultFactory = new DomResultFactory();
|
||||
|
||||
public void setResultFactoryName(String resultFactoryName) {
|
||||
this.resultFactoryName = resultFactoryName;
|
||||
}
|
||||
|
||||
public void setResultType(String resultType) {
|
||||
this.resultType = resultType;
|
||||
}
|
||||
|
||||
public void setResultFactory(ResultFactory resultFactory) {
|
||||
Assert.notNull(resultFactory, "ResultFactory must not be null");
|
||||
this.resultFactory = resultFactory;
|
||||
}
|
||||
|
||||
public String getResultType() {
|
||||
return resultType;
|
||||
}
|
||||
|
||||
public String getResultFactoryName() {
|
||||
return resultFactoryName;
|
||||
}
|
||||
|
||||
public ResultFactory getResultFactory() {
|
||||
return resultFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInit() throws Exception {
|
||||
super.onInit();
|
||||
ResultFactory generatedResultFactory = configureResultFactory(resultType, resultFactoryName, this.getBeanFactory());
|
||||
if (generatedResultFactory != null) {
|
||||
resultFactory = generatedResultFactory;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that encapsulates common logic for validating and building
|
||||
* a bean definition for a {@link ResultFactory} based on either the
|
||||
* 'result-factory' or 'result-type' attributes.
|
||||
*/
|
||||
private ResultFactory configureResultFactory(String resultType, String resultFactoryName, BeanFactory beanFactory) {
|
||||
boolean bothHaveText = StringUtils.hasText(resultFactoryName) && StringUtils.hasText(resultType);
|
||||
ResultFactory resultFactory = null;
|
||||
Assert.state(!bothHaveText, "Only one of 'result-factory' or 'result-type' should be specified.");
|
||||
if (StringUtils.hasText(resultType)) {
|
||||
Assert.state(resultType.equals(DOM_RESULT) || resultType.equals(STRING_RESULT),
|
||||
"Result type must be either 'DOMResult' or 'StringResult'");
|
||||
}
|
||||
if (StringUtils.hasText(resultFactoryName)) {
|
||||
resultFactory = (ResultFactory) beanFactory.getBean(resultFactoryName);
|
||||
}
|
||||
else if (STRING_RESULT.equals(resultType)) {
|
||||
resultFactory = new StringResultFactory();
|
||||
}
|
||||
else if (DOM_RESULT.equals(resultType)) {
|
||||
resultFactory = new DomResultFactory();
|
||||
}
|
||||
return resultFactory;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,8 +22,6 @@ import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.Result;
|
||||
|
||||
import org.springframework.integration.transformer.AbstractTransformer;
|
||||
import org.springframework.integration.xml.result.DomResultFactory;
|
||||
import org.springframework.integration.xml.result.ResultFactory;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
@@ -35,12 +33,10 @@ import org.springframework.util.Assert;
|
||||
* @author Mark Fisher
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
public class MarshallingTransformer extends AbstractTransformer {
|
||||
public class MarshallingTransformer extends AbstractXmlTransformer {
|
||||
|
||||
private final Marshaller marshaller;
|
||||
|
||||
private volatile ResultFactory resultFactory;
|
||||
|
||||
private final ResultTransformer resultTransformer;
|
||||
|
||||
private volatile boolean extractPayload = true;
|
||||
@@ -50,7 +46,6 @@ public class MarshallingTransformer extends AbstractTransformer {
|
||||
Assert.notNull(marshaller, "a marshaller is required");
|
||||
this.marshaller = marshaller;
|
||||
this.resultTransformer = resultTransformer;
|
||||
this.resultFactory = new DomResultFactory();
|
||||
}
|
||||
|
||||
public MarshallingTransformer(Marshaller marshaller) throws ParserConfigurationException {
|
||||
@@ -58,11 +53,6 @@ public class MarshallingTransformer extends AbstractTransformer {
|
||||
}
|
||||
|
||||
|
||||
public void setResultFactory(ResultFactory resultFactory) {
|
||||
Assert.notNull(resultFactory, "ResultFactory must not be null");
|
||||
this.resultFactory = resultFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether the source Message's payload should be extracted prior
|
||||
* to marshalling. This value is set to "true" by default. To send the
|
||||
@@ -79,11 +69,12 @@ public class MarshallingTransformer extends AbstractTransformer {
|
||||
return "xml:marshalling-transformer";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object doTransform(Message<?> message) {
|
||||
Object source = (this.extractPayload) ? message.getPayload() : message;
|
||||
Object transformedPayload = null;
|
||||
Result result = this.resultFactory.createResult(source);
|
||||
Result result = this.getResultFactory().createResult(source);
|
||||
if (result == null) {
|
||||
throw new MessagingException(
|
||||
"Unable to marshal payload, ResultFactory returned null.");
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.integration.expression.ExpressionUtils;
|
||||
import org.springframework.integration.transformer.AbstractTransformer;
|
||||
import org.springframework.integration.xml.result.DomResultFactory;
|
||||
import org.springframework.integration.xml.result.ResultFactory;
|
||||
import org.springframework.integration.xml.source.DomSourceFactory;
|
||||
@@ -47,6 +46,7 @@ import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.PatternMatchUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
@@ -77,7 +77,7 @@ import org.springframework.xml.transform.StringSource;
|
||||
* @author Mike Bazos
|
||||
* @author Gary Russell
|
||||
*/
|
||||
public class XsltPayloadTransformer extends AbstractTransformer implements BeanClassLoaderAware {
|
||||
public class XsltPayloadTransformer extends AbstractXmlTransformer implements BeanClassLoaderAware {
|
||||
|
||||
private final ResultTransformer resultTransformer;
|
||||
|
||||
@@ -93,8 +93,6 @@ public class XsltPayloadTransformer extends AbstractTransformer implements BeanC
|
||||
|
||||
private volatile SourceFactory sourceFactory = new DomSourceFactory();
|
||||
|
||||
private volatile ResultFactory resultFactory = new DomResultFactory();
|
||||
|
||||
private volatile boolean resultFactoryExplicitlySet;
|
||||
|
||||
private volatile boolean alwaysUseSourceFactory = false;
|
||||
@@ -155,8 +153,7 @@ public class XsltPayloadTransformer extends AbstractTransformer implements BeanC
|
||||
* @param resultFactory The result factory.
|
||||
*/
|
||||
public void setResultFactory(ResultFactory resultFactory) {
|
||||
Assert.notNull(sourceFactory, "ResultFactory must not be null");
|
||||
this.resultFactory = resultFactory;
|
||||
super.setResultFactory(resultFactory);
|
||||
this.resultFactoryExplicitlySet = true;
|
||||
}
|
||||
|
||||
@@ -192,6 +189,21 @@ public class XsltPayloadTransformer extends AbstractTransformer implements BeanC
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResultType(String resultType) {
|
||||
super.setResultType(resultType);
|
||||
if (StringUtils.hasText(resultType)) {
|
||||
this.alwaysUseResultFactory = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResultFactoryName(String resultFactoryName) {
|
||||
super.setResultFactoryName(resultFactoryName);
|
||||
if (StringUtils.hasText(resultFactoryName)) {
|
||||
this.alwaysUseResultFactory = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentType() {
|
||||
@@ -270,7 +282,7 @@ public class XsltPayloadTransformer extends AbstractTransformer implements BeanC
|
||||
result = new StringResult();
|
||||
}
|
||||
else {
|
||||
result = this.resultFactory.createResult(payload);
|
||||
result = this.getResultFactory().createResult(payload);
|
||||
}
|
||||
transformer.transform(source, result);
|
||||
if (this.resultTransformer != null) {
|
||||
@@ -300,7 +312,7 @@ public class XsltPayloadTransformer extends AbstractTransformer implements BeanC
|
||||
else {
|
||||
source = new DOMSource(documentPayload);
|
||||
}
|
||||
Result result = this.resultFactory.createResult(documentPayload);
|
||||
Result result = this.getResultFactory().createResult(documentPayload);
|
||||
if (!DOMResult.class.isAssignableFrom(result.getClass())) {
|
||||
throw new MessagingException(
|
||||
"Document to Document conversion requires a DOMResult-producing ResultFactory implementation.");
|
||||
|
||||
@@ -38,10 +38,7 @@
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="result-type" use="optional">
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="DOMResult"/>
|
||||
<xsd:enumeration value="StringResult"/>
|
||||
</xsd:restriction>
|
||||
<xsd:union memberTypes="resultType xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="result-factory" type="xsd:string" use="optional">
|
||||
@@ -211,10 +208,7 @@
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="DOMResult"/>
|
||||
<xsd:enumeration value="StringResult"/>
|
||||
</xsd:restriction>
|
||||
<xsd:union memberTypes="resultType xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="result-transformer" type="xsd:string" use="optional">
|
||||
@@ -294,13 +288,7 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="BOOLEAN_RESULT"/>
|
||||
<xsd:enumeration value="STRING_RESULT"/>
|
||||
<xsd:enumeration value="NUMBER_RESULT"/>
|
||||
<xsd:enumeration value="NODE_RESULT"/>
|
||||
<xsd:enumeration value="NODE_LIST_RESULT"/>
|
||||
</xsd:restriction>
|
||||
<xsd:union memberTypes="evaluationType xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="node-mapper">
|
||||
@@ -421,13 +409,7 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="BOOLEAN_RESULT"/>
|
||||
<xsd:enumeration value="STRING_RESULT"/>
|
||||
<xsd:enumeration value="NUMBER_RESULT"/>
|
||||
<xsd:enumeration value="NODE_RESULT"/>
|
||||
<xsd:enumeration value="NODE_LIST_RESULT"/>
|
||||
</xsd:restriction>
|
||||
<xsd:union memberTypes="evaluationType xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="overwrite">
|
||||
@@ -796,10 +778,7 @@
|
||||
<xsd:attribute name="schema-location"/>
|
||||
<xsd:attribute name="schema-type" default="xml-schema">
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="xml-schema"/>
|
||||
<xsd:enumeration value="relax-ng"/>
|
||||
</xsd:restriction>
|
||||
<xsd:union memberTypes="schemaType xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
@@ -883,5 +862,29 @@
|
||||
<xsd:attribute name="expression" type="xsd:string" use="optional"/>
|
||||
<xsd:attribute name="value" type="xsd:string" use="optional"/>
|
||||
</xsd:complexType>
|
||||
|
||||
|
||||
<xsd:simpleType name="resultType">
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="DOMResult"/>
|
||||
<xsd:enumeration value="StringResult"/>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:simpleType name="evaluationType">
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="BOOLEAN_RESULT"/>
|
||||
<xsd:enumeration value="STRING_RESULT"/>
|
||||
<xsd:enumeration value="NUMBER_RESULT"/>
|
||||
<xsd:enumeration value="NODE_RESULT"/>
|
||||
<xsd:enumeration value="NODE_LIST_RESULT"/>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:simpleType name="schemaType">
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="xml-schema"/>
|
||||
<xsd:enumeration value="relax-ng"/>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
|
||||
</xsd:schema>
|
||||
|
||||
@@ -3,24 +3,38 @@
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/integration/xml
|
||||
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
|
||||
|
||||
|
||||
<context:property-placeholder properties-ref="props"/>
|
||||
|
||||
<util:properties id="props">
|
||||
<beans:prop key="booleanResult">BOOLEAN_RESULT</beans:prop>
|
||||
<beans:prop key="stringResult">STRING_RESULT</beans:prop>
|
||||
<beans:prop key="numberResult">NUMBER_RESULT</beans:prop>
|
||||
<beans:prop key="nodeResult">NODE_RESULT</beans:prop>
|
||||
<beans:prop key="nodeListResult">NODE_LIST_RESULT</beans:prop>
|
||||
</util:properties>
|
||||
|
||||
<si:channel id="output">
|
||||
<si:queue/>
|
||||
</si:channel>
|
||||
|
||||
<xpath-header-enricher input-channel="input" output-channel="output">
|
||||
<header name="name" xpath-expression="/person/@name" />
|
||||
<header name="age" xpath-expression="/person/@age" evaluation-type="NUMBER_RESULT" header-type="int"/>
|
||||
<header name="married" xpath-expression="/person/@married = 'true'" evaluation-type="BOOLEAN_RESULT" />
|
||||
<header name="node-test" xpath-expression="/person/@age" evaluation-type="NODE_RESULT" />
|
||||
<header name="node-list-test" xpath-expression="/person/@*" evaluation-type="NODE_LIST_RESULT" />
|
||||
<header name="ref-test" xpath-expression-ref="testExpression" evaluation-type="NUMBER_RESULT" />
|
||||
<header name="age" xpath-expression="/person/@age" evaluation-type="${numberResult}" header-type="int"/>
|
||||
<header name="married" xpath-expression="/person/@married = 'true'" evaluation-type="${booleanResult}" />
|
||||
<header name="node-test" xpath-expression="/person/@age" evaluation-type="${nodeResult}" />
|
||||
<header name="node-list-test" xpath-expression="/person/@*" evaluation-type="${nodeListResult}" />
|
||||
<header name="ref-test" xpath-expression-ref="testExpression" evaluation-type="${numberResult}" />
|
||||
</xpath-header-enricher>
|
||||
|
||||
<xpath-expression id="testExpression" expression="/person/@age * 2"/>
|
||||
|
||||
@@ -3,32 +3,46 @@
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/integration/xml
|
||||
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
|
||||
|
||||
|
||||
<context:property-placeholder properties-ref="props"/>
|
||||
|
||||
<util:properties id="props">
|
||||
<beans:prop key="booleanResult">BOOLEAN_RESULT</beans:prop>
|
||||
<beans:prop key="stringResult">STRING_RESULT</beans:prop>
|
||||
<beans:prop key="numberResult">NUMBER_RESULT</beans:prop>
|
||||
<beans:prop key="nodeResult">NODE_RESULT</beans:prop>
|
||||
<beans:prop key="nodeListResult">NODE_LIST_RESULT</beans:prop>
|
||||
</util:properties>
|
||||
|
||||
<si:channel id="output">
|
||||
<si:queue/>
|
||||
</si:channel>
|
||||
|
||||
<xpath-transformer input-channel="defaultInput" xpath-expression="/person/@name" output-channel="output"/>
|
||||
|
||||
<xpath-transformer input-channel="numberInput" xpath-expression="/person/@age" evaluation-type="NUMBER_RESULT" output-channel="output"/>
|
||||
<xpath-transformer input-channel="numberInput" xpath-expression="/person/@age" evaluation-type="${numberResult}" output-channel="output"/>
|
||||
|
||||
<xpath-transformer input-channel="booleanInput" xpath-expression="/person/@married = 'true'" evaluation-type="BOOLEAN_RESULT" output-channel="output"/>
|
||||
<xpath-transformer input-channel="booleanInput" xpath-expression="/person/@married = 'true'" evaluation-type="${booleanResult}" output-channel="output"/>
|
||||
|
||||
<xpath-transformer input-channel="nodeInput" xpath-expression="/person/@age" evaluation-type="NODE_RESULT" output-channel="output"/>
|
||||
<xpath-transformer input-channel="nodeInput" xpath-expression="/person/@age" evaluation-type="${nodeResult}" output-channel="output"/>
|
||||
|
||||
<xpath-transformer input-channel="nodeListInput" xpath-expression="/person/@*" evaluation-type="NODE_LIST_RESULT" output-channel="output"/>
|
||||
<xpath-transformer input-channel="nodeListInput" xpath-expression="/person/@*" evaluation-type="${nodeListResult}" output-channel="output"/>
|
||||
|
||||
<xpath-transformer input-channel="nodeMapperInput" xpath-expression="/person/@age" node-mapper="testNodeMapper" output-channel="output"/>
|
||||
|
||||
<xpath-transformer input-channel="customConverterInput" xpath-expression="/test/@type" converter="testXmlPayloadConverter" output-channel="output"/>
|
||||
|
||||
<xpath-transformer input-channel="expressionRefInput" xpath-expression-ref="testExpression" evaluation-type="NUMBER_RESULT" output-channel="output"/>
|
||||
<xpath-transformer input-channel="expressionRefInput" xpath-expression-ref="testExpression" evaluation-type="${numberResult}" output-channel="output"/>
|
||||
|
||||
<xpath-expression id="testExpression" expression="/person/@age * 2"/>
|
||||
|
||||
|
||||
@@ -3,11 +3,22 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-xml="http://www.springframework.org/schema/integration/xml"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/integration/xml http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
|
||||
|
||||
<context:property-placeholder properties-ref="props"/>
|
||||
|
||||
<util:properties id="props">
|
||||
<prop key="xmlSchema">xml-schema</prop>
|
||||
</util:properties>
|
||||
|
||||
<int-xml:validating-filter id="filterA"
|
||||
schema-type="${xmlSchema}"
|
||||
input-channel="inputChannelA"
|
||||
output-channel="validOutputChannel"
|
||||
discard-channel="invalidOutputChannel"
|
||||
@@ -38,4 +49,5 @@
|
||||
<int:channel id="invalidOutputChannel">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -23,17 +23,20 @@ import static org.junit.Assert.fail;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.MessageRejectedException;
|
||||
import org.springframework.integration.xml.AggregatedXmlMessageValidationException;
|
||||
import org.springframework.integration.xml.util.XmlTestUtil;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Jonas Partner
|
||||
@@ -42,11 +45,15 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext
|
||||
public class XmlPayloadValidatingFilterParserTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext ac;
|
||||
|
||||
@Test
|
||||
public void testValidMessage() throws Exception {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
|
||||
Document doc = XmlTestUtil.getDocumentForString("<greeting>hello</greeting>");
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
PollableChannel validChannel = ac.getBean("validOutputChannel", PollableChannel.class);
|
||||
@@ -56,7 +63,6 @@ public class XmlPayloadValidatingFilterParserTests {
|
||||
}
|
||||
@Test
|
||||
public void testInvalidMessageWithDiscardChannel() throws Exception {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
|
||||
Document doc = XmlTestUtil.getDocumentForString("<greeting><other/></greeting>");
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
PollableChannel validChannel = ac.getBean("validOutputChannel", PollableChannel.class);
|
||||
@@ -68,7 +74,6 @@ public class XmlPayloadValidatingFilterParserTests {
|
||||
}
|
||||
@Test
|
||||
public void testInvalidMessageWithThrowException() throws Exception {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
|
||||
Document doc = XmlTestUtil.getDocumentForString("<greeting ping=\"pong\"><other/></greeting>");
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
MessageChannel inputChannel = ac.getBean("inputChannelB", MessageChannel.class);
|
||||
@@ -88,7 +93,6 @@ public class XmlPayloadValidatingFilterParserTests {
|
||||
}
|
||||
@Test
|
||||
public void testValidMessageWithValidator() throws Exception {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
|
||||
Document doc = XmlTestUtil.getDocumentForString("<greeting>hello</greeting>");
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
PollableChannel validChannel = ac.getBean("validOutputChannel", PollableChannel.class);
|
||||
@@ -96,16 +100,15 @@ public class XmlPayloadValidatingFilterParserTests {
|
||||
inputChannel.send(docMessage);
|
||||
assertNotNull(validChannel.receive(100));
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@Test
|
||||
public void testInvalidMessageWithValidatorAndDiscardChannel() throws Exception {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
|
||||
Document doc = XmlTestUtil.getDocumentForString("<greeting><other/></greeting>");
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
PollableChannel validChannel = ac.getBean("validOutputChannel", PollableChannel.class);
|
||||
PollableChannel invalidChannel = ac.getBean("invalidOutputChannel", PollableChannel.class);
|
||||
MessageChannel inputChannel = ac.getBean("inputChannelC", MessageChannel.class);
|
||||
inputChannel.send(docMessage);
|
||||
assertNotNull(invalidChannel.receive(100));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,32 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:si-xml="http://www.springframework.org/schema/integration/xml"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si-xml="http://www.springframework.org/schema/integration/xml"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/integration/xml
|
||||
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
|
||||
|
||||
<context:property-placeholder properties-ref="props"/>
|
||||
|
||||
<util:properties id="props">
|
||||
<prop key="domResult">DOMResult</prop>
|
||||
<prop key="stringResult">StringResult</prop>
|
||||
</util:properties>
|
||||
|
||||
<si:channel id="output">
|
||||
<si:queue capacity="1"/>
|
||||
</si:channel>
|
||||
|
||||
<si:channel id="withResourceIn"/>
|
||||
|
||||
<si-xml:xslt-transformer id="xsltTransformerWithResource"
|
||||
input-channel="withResourceIn"
|
||||
output-channel="output"
|
||||
xsl-resource="org/springframework/integration/xml/config/test.xsl"/>
|
||||
|
||||
<si:channel id="withTemplatesIn"/>
|
||||
|
||||
<si-xml:xslt-transformer id="xsltTransformerWithTemplates"
|
||||
input-channel="withTemplatesIn"
|
||||
output-channel="output"
|
||||
xsl-templates="templates"/>
|
||||
|
||||
<si:channel id="withTemplatesAndResultTransformerIn"/>
|
||||
|
||||
<si-xml:xslt-transformer id="xsltTransformerWithTemplatesAndResultTransformer"
|
||||
input-channel="withTemplatesAndResultTransformerIn"
|
||||
output-channel="output"
|
||||
@@ -34,6 +48,7 @@
|
||||
result-transformer="resultTransformer"/>
|
||||
|
||||
<si:channel id="withTemplatesAndResultFactoryIn"/>
|
||||
|
||||
<si-xml:xslt-transformer id="xsltTransformerWithTemplatesAndResultFactory"
|
||||
input-channel="withTemplatesAndResultFactoryIn"
|
||||
output-channel="output"
|
||||
@@ -41,23 +56,24 @@
|
||||
result-factory="stubResultFactory"/>
|
||||
|
||||
<si:channel id="withTemplatesAndStringResultTypeIn"/>
|
||||
|
||||
<si-xml:xslt-transformer id="xsltTransformerWithTemplatesAndStringResultType"
|
||||
input-channel="withTemplatesAndStringResultTypeIn"
|
||||
output-channel="output"
|
||||
xsl-templates="templates"
|
||||
result-type="StringResult"/>
|
||||
result-type="${stringResult}"/>
|
||||
|
||||
|
||||
<si-xml:xslt-transformer id="docInStringResultOutTransformer"
|
||||
input-channel="docinStringResultOutTransformerChannel"
|
||||
output-channel="output" result-type="StringResult"
|
||||
output-channel="output" result-type="${stringResult}"
|
||||
xsl-resource="classpath:org/springframework/integration/xml/transformer/transformer.xslt">
|
||||
</si-xml:xslt-transformer>
|
||||
|
||||
|
||||
<si-xml:xslt-transformer id="stringResultOutTransformer"
|
||||
input-channel="stringResultOutTransformerChannel"
|
||||
output-channel="output" result-type="DOMResult"
|
||||
output-channel="output" result-type="${domResult}"
|
||||
xsl-resource="classpath:org/springframework/integration/xml/transformer/transform.xsl">
|
||||
</si-xml:xslt-transformer>
|
||||
|
||||
@@ -80,5 +96,4 @@
|
||||
|
||||
<bean id="stubResultFactory" class="org.springframework.integration.xml.config.StubResultFactory"/>
|
||||
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -47,109 +47,104 @@ import org.springframework.xml.transform.StringResult;
|
||||
*/
|
||||
public class XsltPayloadTransformerParserTests {
|
||||
|
||||
private final String doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><order><orderItem>test</orderItem></order>";
|
||||
private final String doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><order><orderItem>test</orderItem></order>";
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private PollableChannel output;
|
||||
private PollableChannel output;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
applicationContext = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
output = (PollableChannel) applicationContext.getBean("output");
|
||||
}
|
||||
@Before
|
||||
public void setUp() {
|
||||
applicationContext = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
output = (PollableChannel) applicationContext.getBean("output");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithResourceProvided() throws Exception {
|
||||
MessageChannel input = (MessageChannel) applicationContext.getBean("withResourceIn");
|
||||
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
|
||||
input.send(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertTrue("Payload was not a DOMResult", result.getPayload() instanceof DOMResult);
|
||||
Document doc = (Document) ((DOMResult) result.getPayload()).getNode();
|
||||
assertEquals("Wrong payload", "test", doc.getDocumentElement().getTextContent());
|
||||
assertNotNull(TestUtils.getPropertyValue(applicationContext.getBean("xsltTransformerWithResource.handler"),
|
||||
"transformer.evaluationContext.beanResolver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithResourceProvided() throws Exception {
|
||||
MessageChannel input = (MessageChannel) applicationContext.getBean("withResourceIn");
|
||||
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
|
||||
input.send(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertTrue("Payload was not a DOMResult", result.getPayload() instanceof DOMResult);
|
||||
Document doc = (Document) ((DOMResult) result.getPayload()).getNode();
|
||||
assertEquals("Wrong payload", "test", doc.getDocumentElement().getTextContent());
|
||||
assertNotNull(TestUtils.getPropertyValue(applicationContext.getBean("xsltTransformerWithResource.handler"),
|
||||
"transformer.evaluationContext.beanResolver"));
|
||||
}
|
||||
@Test
|
||||
public void testWithTemplatesProvided() throws Exception {
|
||||
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesIn");
|
||||
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
|
||||
input.send(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertTrue("Payload was not a DOMResult", result.getPayload() instanceof DOMResult);
|
||||
Document doc = (Document) ((DOMResult) result.getPayload()).getNode();
|
||||
assertEquals("Wrong payload", "test", doc.getDocumentElement().getTextContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithTemplatesProvided() throws Exception {
|
||||
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesIn");
|
||||
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
|
||||
input.send(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertTrue("Payload was not a DOMResult", result.getPayload() instanceof DOMResult);
|
||||
Document doc = (Document) ((DOMResult) result.getPayload()).getNode();
|
||||
assertEquals("Wrong payload", "test", doc.getDocumentElement().getTextContent());
|
||||
}
|
||||
@Test
|
||||
public void testWithTemplatesAndResultTransformer() throws Exception {
|
||||
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesAndResultTransformerIn");
|
||||
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
|
||||
input.send(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertEquals("Wrong payload type", String.class, result.getPayload().getClass());
|
||||
String strResult = (String) result.getPayload();
|
||||
assertEquals("Wrong payload", "testReturn", strResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithTemplatesAndResultTransformer() throws Exception {
|
||||
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesAndResultTransformerIn");
|
||||
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
|
||||
input.send(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertEquals("Wrong payload type", String.class, result.getPayload().getClass());
|
||||
String strResult = (String) result.getPayload();
|
||||
assertEquals("Wrong payload", "testReturn", strResult);
|
||||
}
|
||||
@Test
|
||||
public void testWithResourceProvidedAndStubResultFactory() throws Exception {
|
||||
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesAndResultFactoryIn");
|
||||
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
|
||||
input.send(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertTrue("Payload was not a StubStringResult", result.getPayload() instanceof StubStringResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithResourceProvidedAndStubResultFactory() throws Exception {
|
||||
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesAndResultFactoryIn");
|
||||
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
|
||||
input.send(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertTrue("Payload was not a StubStringResult", result.getPayload() instanceof StubStringResult);
|
||||
}
|
||||
@Test
|
||||
public void testWithResourceAndStringResultType() throws Exception {
|
||||
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesAndStringResultTypeIn");
|
||||
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
|
||||
input.send(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertTrue("Payload was not a StringResult", result.getPayload() instanceof StringResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithResourceAndStringResultType() throws Exception {
|
||||
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesAndStringResultTypeIn");
|
||||
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
|
||||
input.send(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertTrue("Payload was not a StringResult", result.getPayload() instanceof StringResult);
|
||||
}
|
||||
@Test
|
||||
public void docInStringResultOut() throws Exception {
|
||||
MessageChannel input = applicationContext.getBean("docinStringResultOutTransformerChannel",
|
||||
MessageChannel.class);
|
||||
Message<?> message = MessageBuilder.withPayload(XmlTestUtil.getDocumentForString(this.doc)).build();
|
||||
input.send(message);
|
||||
Message<?> resultMessage = output.receive();
|
||||
Assert.assertEquals("Wrong payload type", StringResult.class, resultMessage.getPayload().getClass());
|
||||
String payload = resultMessage.getPayload().toString();
|
||||
Assert.assertTrue(payload.contains("<bob>test</bob>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringInDocResultOut() throws Exception {
|
||||
MessageChannel input = applicationContext.getBean("stringResultOutTransformerChannel", MessageChannel.class);
|
||||
Message<?> message = MessageBuilder.withPayload(this.doc).build();
|
||||
input.send(message);
|
||||
Message<?> resultMessage = output.receive();
|
||||
Assert.assertEquals("Wrong payload type", DOMResult.class, resultMessage.getPayload().getClass());
|
||||
Document payload = (Document) ((DOMResult) resultMessage.getPayload()).getNode();
|
||||
Assert.assertTrue(XmlTestUtil.docToString(payload).contains("<bob>test</bob>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void docInStringResultOut() throws Exception {
|
||||
MessageChannel input = applicationContext.getBean("docinStringResultOutTransformerChannel", MessageChannel.class);
|
||||
Message<?> message = MessageBuilder.withPayload(XmlTestUtil.getDocumentForString(this.doc)).
|
||||
build();
|
||||
input.send(message);
|
||||
Message<?> resultMessage = output.receive();
|
||||
Assert.assertEquals("Wrong payload type", StringResult.class, resultMessage.getPayload().getClass());
|
||||
String payload = resultMessage.getPayload().toString();
|
||||
Assert.assertTrue(payload.contains("<bob>test</bob>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringInDocResultOut() throws Exception {
|
||||
MessageChannel input = applicationContext.getBean("stringResultOutTransformerChannel", MessageChannel.class);
|
||||
Message<?> message = MessageBuilder.withPayload(this.doc).
|
||||
build();
|
||||
input.send(message);
|
||||
Message<?> resultMessage = output.receive();
|
||||
Assert.assertEquals("Wrong payload type", DOMResult.class, resultMessage.getPayload().getClass());
|
||||
Document payload = (Document) ((DOMResult) resultMessage.getPayload()).getNode();
|
||||
Assert.assertTrue(XmlTestUtil.docToString(payload).contains("<bob>test</bob>"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void stringInAndCustomResultFactory() throws Exception {
|
||||
MessageChannel input = applicationContext.getBean("stringInCustomResultFactoryChannel", MessageChannel.class);
|
||||
Message<?> message = MessageBuilder.withPayload(XmlTestUtil.getDocumentForString(this.doc)).
|
||||
build();
|
||||
input.send(message);
|
||||
Message<?> resultMessage = output.receive();
|
||||
Assert.assertEquals("Wrong payload type", CustomTestResultFactory.FixedStringResult.class, resultMessage.getPayload().getClass());
|
||||
String payload = resultMessage.getPayload().toString();
|
||||
Assert.assertTrue(payload.contains("fixedStringForTesting"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringInAndCustomResultFactory() throws Exception {
|
||||
MessageChannel input = applicationContext.getBean("stringInCustomResultFactoryChannel", MessageChannel.class);
|
||||
Message<?> message = MessageBuilder.withPayload(XmlTestUtil.getDocumentForString(this.doc)).build();
|
||||
input.send(message);
|
||||
Message<?> resultMessage = output.receive();
|
||||
Assert.assertEquals("Wrong payload type", CustomTestResultFactory.FixedStringResult.class, resultMessage
|
||||
.getPayload().getClass());
|
||||
String payload = resultMessage.getPayload().toString();
|
||||
Assert.assertTrue(payload.contains("fixedStringForTesting"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="xmlValidatingMessageSelector" class="org.springframework.integration.xml.selector.XmlValidatingMessageSelector">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.core.io.ByteArrayResource">
|
||||
<constructor-arg value="#{new byte[] { 0x03 } }"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
<constructor-arg value="foo"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -13,12 +13,18 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xml.selector;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.validation.XmlValidatorFactory;
|
||||
import org.springframework.integration.xml.selector.XmlValidatingMessageSelector.SchemaType;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -29,23 +35,34 @@ public class XmlValidatingMessageSelectorTests {
|
||||
@Test
|
||||
public void validateCreationWithSchemaAndDefaultSchemaType() throws Exception{
|
||||
Resource resource = new ByteArrayResource("<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'/>".getBytes());
|
||||
new XmlValidatingMessageSelector(resource, null);
|
||||
new XmlValidatingMessageSelector(resource, (SchemaType) null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void validateCreationWithSchemaAndProvidedSchemaType() throws Exception{
|
||||
Resource resource = new ByteArrayResource("<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'/>".getBytes());
|
||||
new XmlValidatingMessageSelector(resource, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
new XmlValidatingMessageSelector(resource, SchemaType.XML_SCHEMA);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
|
||||
@Test
|
||||
public void validateFailureInvalidSchemaLanguage() throws Exception{
|
||||
Resource resource = new ByteArrayResource("<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'/>".getBytes());
|
||||
new XmlValidatingMessageSelector(resource, "foo");
|
||||
ConfigurableApplicationContext context = null;
|
||||
try {
|
||||
context = new ClassPathXmlApplicationContext("XmlValidatingMessageSelectorTests-context.xml", this.getClass());
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue(e.getMessage().contains("java.lang.IllegalArgumentException: No enum constant"));
|
||||
}
|
||||
finally {
|
||||
if(context != null) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void validateFailureWhenNoSchemaResourceProvided() throws Exception{
|
||||
new XmlValidatingMessageSelector(null, null);
|
||||
new XmlValidatingMessageSelector(null, (SchemaType) null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,22 +4,29 @@
|
||||
xmlns:si-xml="http://www.springframework.org/schema/integration/xml"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/xml
|
||||
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<context:property-placeholder properties-ref="props"/>
|
||||
|
||||
<util:properties id="props">
|
||||
<prop key="result">DOMResult</prop>
|
||||
</util:properties>
|
||||
|
||||
<context:annotation-config/>
|
||||
|
||||
<si:channel id="marshallIn"/>
|
||||
|
||||
<si:channel id="unmarshallIn"/>
|
||||
|
||||
|
||||
<si:channel id="unmarshallOut">
|
||||
<si:queue capacity="10" />
|
||||
</si:channel>
|
||||
@@ -28,12 +35,10 @@
|
||||
<si:queue capacity="10" />
|
||||
</si:channel>
|
||||
|
||||
<si-xml:marshalling-transformer id="marshaller" input-channel="marshallIn" output-channel="marshallOut" marshaller="marshallerUnmarshaller" />
|
||||
|
||||
<si-xml:marshalling-transformer id="marshaller" input-channel="marshallIn" output-channel="marshallOut" marshaller="marshallerUnmarshaller" result-type="${result}" />
|
||||
|
||||
<si-xml:unmarshalling-transformer id="unmarshaller" input-channel="unmarshallIn" output-channel="unmarshallOut" unmarshaller="marshallerUnmarshaller" />
|
||||
|
||||
|
||||
<bean id="marshallerUnmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller" >
|
||||
<property name="classesToBeBound">
|
||||
<list>
|
||||
@@ -42,4 +47,4 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user