From d58118145eb1255dd21239c756b82feef17fe5db Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 28 Mar 2008 20:43:50 +0000 Subject: [PATCH] Added MarshallingWebServiceTargetAdapter and WebServiceTargetAdapterParser. --- .../java/META-INF/spring-integration.parsers | 1 + .../src/main/java/META-INF/spring.schemas | 1 + .../MarshallingWebServiceTargetAdapter.java | 58 ++++++++++++ .../config/WebServiceTargetAdapterParser.java | 94 +++++++++++++++++++ .../ws/config/spring-integration-ws-1.0.xsd | 38 ++++++++ 5 files changed, 192 insertions(+) create mode 100644 spring-integration-ws/src/main/java/META-INF/spring-integration.parsers create mode 100644 spring-integration-ws/src/main/java/META-INF/spring.schemas create mode 100644 spring-integration-ws/src/main/java/org/springframework/integration/ws/adapter/MarshallingWebServiceTargetAdapter.java create mode 100644 spring-integration-ws/src/main/java/org/springframework/integration/ws/config/WebServiceTargetAdapterParser.java create mode 100644 spring-integration-ws/src/main/java/org/springframework/integration/ws/config/spring-integration-ws-1.0.xsd diff --git a/spring-integration-ws/src/main/java/META-INF/spring-integration.parsers b/spring-integration-ws/src/main/java/META-INF/spring-integration.parsers new file mode 100644 index 0000000000..389ffb1350 --- /dev/null +++ b/spring-integration-ws/src/main/java/META-INF/spring-integration.parsers @@ -0,0 +1 @@ +ws-target=org.springframework.integration.ws.config.WebServiceTargetAdapterParser \ No newline at end of file diff --git a/spring-integration-ws/src/main/java/META-INF/spring.schemas b/spring-integration-ws/src/main/java/META-INF/spring.schemas new file mode 100644 index 0000000000..fbb973f44f --- /dev/null +++ b/spring-integration-ws/src/main/java/META-INF/spring.schemas @@ -0,0 +1 @@ +http\://www.springframework.org/schema/integration/spring-integration-ws-1.0.xsd=org/springframework/integration/ws/config/spring-integration-ws-1.0.xsd diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/adapter/MarshallingWebServiceTargetAdapter.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/adapter/MarshallingWebServiceTargetAdapter.java new file mode 100644 index 0000000000..78846a0622 --- /dev/null +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/adapter/MarshallingWebServiceTargetAdapter.java @@ -0,0 +1,58 @@ +/* + * Copyright 2002-2008 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.ws.adapter; + +import org.springframework.oxm.Marshaller; +import org.springframework.oxm.Unmarshaller; +import org.springframework.util.Assert; +import org.springframework.ws.client.core.WebServiceMessageCallback; + +/** + * A marshalling Web Service target channel adapter. + * + * @author Mark Fisher + * @see Marshaller + * @see Unmarshaller + */ +public class MarshallingWebServiceTargetAdapter extends AbstractWebServiceTargetAdapter { + + public MarshallingWebServiceTargetAdapter(String uri, Marshaller marshaller, Unmarshaller unmarshaller) { + super(uri); + Assert.notNull(marshaller, "marshaller must not be null"); + Assert.notNull(unmarshaller, "unmarshaller must not be null"); + this.getWebServiceTemplate().setMarshaller(marshaller); + this.getWebServiceTemplate().setUnmarshaller(unmarshaller); + } + + public MarshallingWebServiceTargetAdapter(String uri, Marshaller marshaller) { + super(uri); + Assert.notNull(marshaller, "marshaller must not be null"); + Assert.isTrue(marshaller instanceof Unmarshaller, + "Marshaller [" + marshaller + "] does not implement the Unmarshaller interface. " + + "Please set an Unmarshaller explicitly by using the " + this.getClass().getName() + + "(String uri, Marshaller marshaller, Unmarshaller unmarshaller) constructor."); + this.getWebServiceTemplate().setMarshaller(marshaller); + this.getWebServiceTemplate().setUnmarshaller((Unmarshaller) marshaller); + } + + + @Override + protected Object doHandle(Object requestPayload, WebServiceMessageCallback requestCallback) { + return this.getWebServiceTemplate().marshalSendAndReceive(requestPayload, requestCallback); + } + +} diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/WebServiceTargetAdapterParser.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/WebServiceTargetAdapterParser.java new file mode 100644 index 0000000000..295051a26a --- /dev/null +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/WebServiceTargetAdapterParser.java @@ -0,0 +1,94 @@ +/* + * Copyright 2002-2008 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.ws.config; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.parsing.BeanComponentDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.MessagingConfigurationException; +import org.springframework.integration.endpoint.DefaultMessageEndpoint; +import org.springframework.integration.scheduling.Subscription; +import org.springframework.integration.ws.adapter.MarshallingWebServiceTargetAdapter; +import org.springframework.integration.ws.adapter.SimpleWebServiceTargetAdapter; +import org.springframework.util.StringUtils; + +/** + * Parser for the <ws-target/> element. + * + * @author Mark Fisher + */ +public class WebServiceTargetAdapterParser extends AbstractSingleBeanDefinitionParser { + + protected Class getBeanClass(Element element) { + return DefaultMessageEndpoint.class; + } + + protected boolean shouldGenerateId() { + return false; + } + + protected boolean shouldGenerateIdAsFallback() { + return true; + } + + protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + String channel = element.getAttribute("channel"); + String uri = element.getAttribute("uri"); + if (!StringUtils.hasText(channel)) { + throw new MessagingConfigurationException("The 'channel' attribute is required."); + } + if (!StringUtils.hasText(uri)) { + throw new MessagingConfigurationException("The 'uri' attribute is required."); + } + String marshallerRef = element.getAttribute("marshaller"); + String unmarshallerRef = element.getAttribute("unmarshaller"); + String sourceExtractorRef = element.getAttribute("source-extractor"); + RootBeanDefinition adapterDef = (StringUtils.hasText(marshallerRef)) ? + this.parseMarshallingAdapter(uri, marshallerRef, unmarshallerRef) : + this.parseSimpleAdapter(uri, sourceExtractorRef); + String adapterBeanName = parserContext.getReaderContext().generateBeanName(adapterDef); + parserContext.registerBeanComponent(new BeanComponentDefinition(adapterDef, adapterBeanName)); + builder.addPropertyReference("handler", adapterBeanName); + Subscription subscription = new Subscription(channel); + builder.addPropertyValue("subscription", subscription); + } + + private RootBeanDefinition parseMarshallingAdapter(String uri, String marshallerRef, String unmarshallerRef) { + RootBeanDefinition beanDefinition = new RootBeanDefinition(MarshallingWebServiceTargetAdapter.class); + beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(uri); + beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(marshallerRef)); + if (StringUtils.hasText(unmarshallerRef)) { + beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(unmarshallerRef)); + } + return beanDefinition; + } + + private RootBeanDefinition parseSimpleAdapter(String uri, String sourceExtrractorRef) { + RootBeanDefinition beanDefinition = new RootBeanDefinition(SimpleWebServiceTargetAdapter.class); + beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(uri); + if (StringUtils.hasText(sourceExtrractorRef)) { + beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(sourceExtrractorRef)); + } + return beanDefinition; + } + +} diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/spring-integration-ws-1.0.xsd b/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/spring-integration-ws-1.0.xsd new file mode 100644 index 0000000000..3f50a8ce18 --- /dev/null +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/spring-integration-ws-1.0.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + Defines a Web Service target channel adapter. + + + + + + + + + + + + \ No newline at end of file