SimpleWebServiceTargetAdapter is now SimpleWebServiceHandler, and MarshallingWebServiceTargetAdapter is now MarshallingWebServiceHandler. The "ws-target" element is now "ws-handler", and the WebServiceHandlerParser (formerly WebServiceTargetAdapterParser) now creates a MessageHandler instance only - rather than creating the HandlerEndpoint itself. Therefore, the "ws-handler" should be referenced from the "handler" attribute of a <handler-endpoint/> element. See the modified WebServiceDemo (and its configuration file: "temperatureConversion.xml") in the "org.springframework.integration.samples" module for an example.

This commit is contained in:
Mark Fisher
2008-05-28 15:37:13 +00:00
parent ccc3e06928
commit f242075a73
12 changed files with 170 additions and 195 deletions

View File

@@ -0,0 +1,75 @@
/*
* 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.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.ws.handler.MarshallingWebServiceHandler;
import org.springframework.integration.ws.handler.SimpleWebServiceHandler;
import org.springframework.util.StringUtils;
/**
* Parser for the &lt;ws-handler/&gt; element.
*
* @author Mark Fisher
*/
public class WebServiceHandlerParser extends AbstractSingleBeanDefinitionParser {
@Override
protected Class<?> getBeanClass(Element element) {
return (StringUtils.hasText(element.getAttribute("marshaller"))) ?
MarshallingWebServiceHandler.class : SimpleWebServiceHandler.class;
}
@Override
protected boolean shouldGenerateId() {
return false;
}
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
String uri = element.getAttribute("uri");
if (!StringUtils.hasText(uri)) {
throw new ConfigurationException("The 'uri' attribute is required.");
}
builder.addConstructorArgValue(uri);
String marshallerRef = element.getAttribute("marshaller");
if (StringUtils.hasText(marshallerRef)) {
builder.addConstructorArgReference(marshallerRef);
String unmarshallerRef = element.getAttribute("unmarshaller");
if (StringUtils.hasText(unmarshallerRef)) {
builder.addConstructorArgReference(unmarshallerRef);
}
}
else {
String sourceExtractorRef = element.getAttribute("source-extractor");
if (StringUtils.hasText(sourceExtractorRef)) {
builder.addConstructorArgReference(sourceExtractorRef);
}
}
}
}

View File

@@ -1,94 +0,0 @@
/*
* 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.ConfigurationException;
import org.springframework.integration.endpoint.HandlerEndpoint;
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 &lt;ws-target/&gt; element.
*
* @author Mark Fisher
*/
public class WebServiceTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
protected Class<?> getBeanClass(Element element) {
return HandlerEndpoint.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 ConfigurationException("The 'channel' attribute is required.");
}
if (!StringUtils.hasText(uri)) {
throw new ConfigurationException("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.addConstructorArgReference(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;
}
}

View File

@@ -19,16 +19,15 @@
]]></xsd:documentation>
</xsd:annotation>
<xsd:element name="ws-target">
<xsd:element name="ws-handler">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Defines a Web Service target channel adapter.
Defines a Web Service MessageHandler adapter.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="uri" type="xsd:string" use="required"/>
<xsd:attribute name="channel" type="xsd:string" use="required"/>
<xsd:attribute name="marshaller" type="xsd:string"/>
<xsd:attribute name="unmarshaller" type="xsd:string"/>
<xsd:attribute name="source-extractor" type="xsd:string"/>

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.ws.adapter;
package org.springframework.integration.ws.handler;
import java.io.IOException;
import java.net.URI;
@@ -32,11 +32,11 @@ import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.client.core.SoapActionCallback;
/**
* Base class for Web Service target channel adapters.
* Base class for Web Service {@link MessageHandler} adapters.
*
* @author Mark Fisher
*/
public abstract class AbstractWebServiceTargetAdapter implements MessageHandler {
public abstract class AbstractWebServiceHandler implements MessageHandler {
public static final String SOAP_ACTION_PROPERTY_KEY = "_ws.soapAction";
@@ -46,8 +46,8 @@ public abstract class AbstractWebServiceTargetAdapter implements MessageHandler
private volatile WebServiceMessageCallback requestCallback;
public AbstractWebServiceTargetAdapter(URI uri) {
Assert.notNull(uri, "'uri' must not be null");
public AbstractWebServiceHandler(URI uri) {
Assert.notNull(uri, "URI must not be null");
this.webServiceTemplate.setDefaultUri(uri.toString());
}
@@ -70,7 +70,7 @@ public abstract class AbstractWebServiceTargetAdapter implements MessageHandler
public final Message<?> handle(Message<?> message) {
Object responsePayload = this.doHandle(message.getPayload(), this.getRequestCallback(message));
return (responsePayload != null ? new GenericMessage<Object>(responsePayload, message.getHeader()) : null);
return responsePayload != null ? new GenericMessage<Object>(responsePayload, message.getHeader()) : null;
}
protected abstract Object doHandle(Object requestPayload, WebServiceMessageCallback requestCallback);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.ws.adapter;
package org.springframework.integration.ws.handler;
import java.net.URI;
@@ -24,15 +24,15 @@ import org.springframework.util.Assert;
import org.springframework.ws.client.core.WebServiceMessageCallback;
/**
* A marshalling Web Service target channel adapter.
* A marshalling Web Service MessageHandler adapter.
*
* @author Mark Fisher
* @see Marshaller
* @see Unmarshaller
*/
public class MarshallingWebServiceTargetAdapter extends AbstractWebServiceTargetAdapter {
public class MarshallingWebServiceHandler extends AbstractWebServiceHandler {
public MarshallingWebServiceTargetAdapter(URI uri, Marshaller marshaller, Unmarshaller unmarshaller) {
public MarshallingWebServiceHandler(URI uri, Marshaller marshaller, Unmarshaller unmarshaller) {
super(uri);
Assert.notNull(marshaller, "marshaller must not be null");
Assert.notNull(unmarshaller, "unmarshaller must not be null");
@@ -40,7 +40,7 @@ public class MarshallingWebServiceTargetAdapter extends AbstractWebServiceTarget
this.getWebServiceTemplate().setUnmarshaller(unmarshaller);
}
public MarshallingWebServiceTargetAdapter(URI uri, Marshaller marshaller) {
public MarshallingWebServiceHandler(URI uri, Marshaller marshaller) {
super(uri);
Assert.notNull(marshaller, "marshaller must not be null");
Assert.isInstanceOf(Unmarshaller.class, marshaller,

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.ws.adapter;
package org.springframework.integration.ws.handler;
import java.io.IOException;
import java.net.URI;
@@ -32,20 +32,20 @@ import org.springframework.xml.transform.StringSource;
import org.springframework.xml.transform.TransformerObjectSupport;
/**
* A target channel adapter for calling out to a Web Service.
* A MessageHandler adapter for invoking a Web Service.
*
* @author Mark Fisher
*/
public class SimpleWebServiceTargetAdapter extends AbstractWebServiceTargetAdapter {
public class SimpleWebServiceHandler extends AbstractWebServiceHandler {
private final SourceExtractor sourceExtractor;
public SimpleWebServiceTargetAdapter(URI uri) {
public SimpleWebServiceHandler(URI uri) {
this(uri, null);
}
public SimpleWebServiceTargetAdapter(URI uri, SourceExtractor sourceExtractor) {
public SimpleWebServiceHandler(URI uri, SourceExtractor sourceExtractor) {
super(uri);
this.sourceExtractor = (sourceExtractor != null) ? sourceExtractor : new DefaultSourceExtractor();
}
@@ -65,7 +65,7 @@ public class SimpleWebServiceTargetAdapter extends AbstractWebServiceTargetAdapt
}
throw new MessagingException("Unsupported payload type '" + requestPayload.getClass() +
"'. " + this.getClass().getName() + " only supports 'java.lang.String' and '" + Source.class.getName() +
"'. Consider using the '" + MarshallingWebServiceTargetAdapter.class.getName() + "' instead.");
"'. Consider using the '" + MarshallingWebServiceHandler.class.getName() + "' instead.");
}

View File

@@ -1 +1 @@
ws-target=org.springframework.integration.ws.config.WebServiceTargetAdapterParser
ws-handler=org.springframework.integration.ws.config.WebServiceHandlerParser

View File

@@ -23,9 +23,9 @@ import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.HandlerEndpoint;
import org.springframework.integration.ws.adapter.MarshallingWebServiceTargetAdapter;
import org.springframework.integration.ws.adapter.SimpleWebServiceTargetAdapter;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.integration.ws.handler.MarshallingWebServiceHandler;
import org.springframework.integration.ws.handler.SimpleWebServiceHandler;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;
import org.springframework.ws.client.core.SourceExtractor;
@@ -33,39 +33,36 @@ import org.springframework.ws.client.core.SourceExtractor;
/**
* @author Mark Fisher
*/
public class WebServiceTargetAdapterParserTests {
public class WebServiceHandlerParserTests {
@Test
public void testSimpleWebServiceTargetAdapterWithDefaultSourceExtractor() {
public void testSimpleWebServiceHandlerWithDefaultSourceExtractor() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"simpleWebServiceTargetAdapterParserTests.xml", this.getClass());
HandlerEndpoint endpoint =
(HandlerEndpoint) context.getBean("adapterWithDefaultSourceExtractor");
assertEquals(SimpleWebServiceTargetAdapter.class, endpoint.getHandler().getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint.getHandler());
"simpleWebServiceHandlerParserTests.xml", this.getClass());
MessageHandler handler = (MessageHandler) context.getBean("handlerWithDefaultSourceExtractor");
assertEquals(SimpleWebServiceHandler.class, handler.getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(handler);
assertEquals("DefaultSourceExtractor", accessor.getPropertyValue("sourceExtractor").getClass().getSimpleName());
}
@Test
public void testSimpleWebServiceTargetAdapterWithCustomSourceExtractor() {
public void testSimpleWebServiceHandlerWithCustomSourceExtractor() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"simpleWebServiceTargetAdapterParserTests.xml", this.getClass());
HandlerEndpoint endpoint =
(HandlerEndpoint) context.getBean("adapterWithCustomSourceExtractor");
assertEquals(SimpleWebServiceTargetAdapter.class, endpoint.getHandler().getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint.getHandler());
"simpleWebServiceHandlerParserTests.xml", this.getClass());
MessageHandler handler = (MessageHandler) context.getBean("handlerWithCustomSourceExtractor");
assertEquals(SimpleWebServiceHandler.class, handler.getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(handler);
SourceExtractor sourceExtractor = (SourceExtractor) context.getBean("sourceExtractor");
assertEquals(sourceExtractor, accessor.getPropertyValue("sourceExtractor"));
}
@Test
public void testWebServiceTargetAdapterWithAllInOneMarshaller() {
public void testWebServiceHandlerWithAllInOneMarshaller() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"marshallingWebServiceTargetAdapterParserTests.xml", this.getClass());
HandlerEndpoint endpoint =
(HandlerEndpoint) context.getBean("adapterWithAllInOneMarshaller");
assertEquals(MarshallingWebServiceTargetAdapter.class, endpoint.getHandler().getClass());
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(endpoint.getHandler());
"marshallingWebServiceHandlerParserTests.xml", this.getClass());
MessageHandler handler = (MessageHandler) context.getBean("handlerWithAllInOneMarshaller");
assertEquals(MarshallingWebServiceHandler.class, handler.getClass());
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(
handlerAccessor.getPropertyValue("webServiceTemplate"));
Marshaller marshaller = (Marshaller) context.getBean("marshallerAndUnmarshaller");
@@ -76,11 +73,10 @@ public class WebServiceTargetAdapterParserTests {
@Test
public void testWebServiceTargetAdapterWithSeparateMarshallerAndUnmarshaller() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"marshallingWebServiceTargetAdapterParserTests.xml", this.getClass());
HandlerEndpoint endpoint =
(HandlerEndpoint) context.getBean("adapterWithSeparateMarshallerAndUnmarshaller");
assertEquals(MarshallingWebServiceTargetAdapter.class, endpoint.getHandler().getClass());
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(endpoint.getHandler());
"marshallingWebServiceHandlerParserTests.xml", this.getClass());
MessageHandler handler = (MessageHandler) context.getBean("handlerWithSeparateMarshallerAndUnmarshaller");
assertEquals(MarshallingWebServiceHandler.class, handler.getClass());
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(
handlerAccessor.getPropertyValue("webServiceTemplate"));
Marshaller marshaller = (Marshaller) context.getBean("marshaller");

View File

@@ -7,15 +7,14 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-ws-1.0.xsd">
<si:message-bus/>
<si:ws-handler id="handlerWithAllInOneMarshaller"
uri="http://example.org"
marshaller="marshallerAndUnmarshaller"/>
<si:channel id="testChannel"/>
<si:ws-target id="adapterWithAllInOneMarshaller" uri="http://example.org" channel="testChannel"
marshaller="marshallerAndUnmarshaller"/>
<si:ws-target id="adapterWithSeparateMarshallerAndUnmarshaller" uri="http://example.org" channel="testChannel"
marshaller="marshaller" unmarshaller="unmarshaller"/>
<si:ws-handler id="handlerWithSeparateMarshallerAndUnmarshaller"
uri="http://example.org"
marshaller="marshaller"
unmarshaller="unmarshaller"/>
<bean id="marshallerAndUnmarshaller" class="org.springframework.integration.ws.config.StubMarshallerAndUnmarshaller"/>

View File

@@ -7,14 +7,12 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-ws-1.0.xsd">
<si:message-bus/>
<si:ws-handler id="handlerWithDefaultSourceExtractor"
uri="http://example.org"/>
<si:channel id="testChannel"/>
<si:ws-target id="adapterWithDefaultSourceExtractor" uri="http://example.org" channel="testChannel"/>
<si:ws-target id="adapterWithCustomSourceExtractor" uri="http://example.org" channel="testChannel"
source-extractor="sourceExtractor"/>
<si:ws-handler id="handlerWithCustomSourceExtractor"
uri="http://example.org"
source-extractor="sourceExtractor"/>
<bean id="sourceExtractor" class="org.springframework.integration.ws.config.StubSourceExtractor"/>