The WebServiceHandlerParser now provides the WebServiceMessageFactory in the WebServiceTemplate constructor (INT-295).

This commit is contained in:
Mark Fisher
2008-07-10 01:54:46 +00:00
parent a3a50488d8
commit 7a2dd68965
4 changed files with 38 additions and 14 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.integration.ws.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
@@ -25,6 +26,8 @@ import org.springframework.integration.ConfigurationException;
import org.springframework.integration.ws.handler.MarshallingWebServiceHandler;
import org.springframework.integration.ws.handler.SimpleWebServiceHandler;
import org.springframework.util.StringUtils;
import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.SourceExtractor;
/**
* Parser for the <ws-handler/> element.
@@ -67,17 +70,22 @@ public class WebServiceHandlerParser extends AbstractSingleBeanDefinitionParser
else {
String sourceExtractorRef = element.getAttribute("source-extractor");
if (StringUtils.hasText(sourceExtractorRef)) {
builder.addConstructorArgReference(sourceExtractorRef);
builder.getBeanDefinition().getConstructorArgumentValues().addGenericArgumentValue(
new RuntimeBeanReference(sourceExtractorRef), SourceExtractor.class.getName());
}
else {
builder.addConstructorArgValue(null);
}
}
String messageFactoryRef = element.getAttribute("message-factory");
if (StringUtils.hasText(messageFactoryRef)) {
builder.getBeanDefinition().getConstructorArgumentValues().addGenericArgumentValue(
new RuntimeBeanReference(messageFactoryRef), WebServiceMessageFactory.class.getName());
}
String requestCallbackRef = element.getAttribute("request-callback");
if (StringUtils.hasText(requestCallbackRef)) {
builder.addPropertyReference("requestCallback", requestCallbackRef);
}
String messageFactoryRef = element.getAttribute("message-factory");
if (StringUtils.hasText(messageFactoryRef)) {
builder.addPropertyReference("messageFactory", messageFactoryRef);
}
String faultMessageResolverRef = element.getAttribute("fault-message-resolver");
if (StringUtils.hasText(faultMessageResolverRef)) {
builder.addPropertyReference("faultMessageResolver", faultMessageResolverRef);

View File

@@ -41,13 +41,15 @@ public abstract class AbstractWebServiceHandler implements MessageHandler {
public static final String SOAP_ACTION_PROPERTY_KEY = "_ws.soapAction";
private final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
private final WebServiceTemplate webServiceTemplate;
private volatile WebServiceMessageCallback requestCallback;
public AbstractWebServiceHandler(URI uri) {
public AbstractWebServiceHandler(URI uri, WebServiceMessageFactory messageFactory) {
Assert.notNull(uri, "URI must not be null");
this.webServiceTemplate = (messageFactory != null) ?
new WebServiceTemplate(messageFactory) : new WebServiceTemplate();
this.webServiceTemplate.setDefaultUri(uri.toString());
}

View File

@@ -21,6 +21,7 @@ import java.net.URI;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;
import org.springframework.util.Assert;
import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.WebServiceMessageCallback;
/**
@@ -32,23 +33,31 @@ import org.springframework.ws.client.core.WebServiceMessageCallback;
*/
public class MarshallingWebServiceHandler extends AbstractWebServiceHandler {
public MarshallingWebServiceHandler(URI uri, Marshaller marshaller, Unmarshaller unmarshaller) {
super(uri);
public MarshallingWebServiceHandler(URI uri, Marshaller marshaller, Unmarshaller unmarshaller, WebServiceMessageFactory messageFactory) {
super(uri, messageFactory);
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 MarshallingWebServiceHandler(URI uri, Marshaller marshaller) {
super(uri);
public MarshallingWebServiceHandler(URI uri, Marshaller marshaller, Unmarshaller unmarshaller) {
this(uri, marshaller, unmarshaller, null);
}
public MarshallingWebServiceHandler(URI uri, Marshaller marshaller, WebServiceMessageFactory messageFactory) {
super(uri, messageFactory);
Assert.notNull(marshaller, "marshaller must not be null");
Assert.isInstanceOf(Unmarshaller.class, marshaller,
"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);
this.getWebServiceTemplate().setUnmarshaller((Unmarshaller) marshaller);
}
public MarshallingWebServiceHandler(URI uri, Marshaller marshaller) {
this(uri, marshaller, (WebServiceMessageFactory) null);
}

View File

@@ -25,6 +25,7 @@ import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import org.springframework.integration.message.MessagingException;
import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.SourceExtractor;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.xml.transform.StringResult;
@@ -42,11 +43,15 @@ public class SimpleWebServiceHandler extends AbstractWebServiceHandler {
public SimpleWebServiceHandler(URI uri) {
this(uri, null);
this(uri, null, null);
}
public SimpleWebServiceHandler(URI uri, SourceExtractor sourceExtractor) {
super(uri);
this(uri, sourceExtractor, (WebServiceMessageFactory) null);
}
public SimpleWebServiceHandler(URI uri, SourceExtractor sourceExtractor, WebServiceMessageFactory messageFactory) {
super(uri, messageFactory);
this.sourceExtractor = (sourceExtractor != null) ? sourceExtractor : new DefaultSourceExtractor();
}