From 2b4f08270e6212b9b2fe880fb9e1559e91e35484 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sat, 29 Mar 2008 15:18:53 +0000 Subject: [PATCH] Using URI instead of String in target adapters. DefaultSourceExtractor now creates a DOMSource if the source to extract from is not already a DOMSource. --- .../AbstractWebServiceTargetAdapter.java | 7 ++++--- .../MarshallingWebServiceTargetAdapter.java | 8 +++++--- .../adapter/SimpleWebServiceTargetAdapter.java | 17 +++++++++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/adapter/AbstractWebServiceTargetAdapter.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/adapter/AbstractWebServiceTargetAdapter.java index 36896729c4..54980af44c 100644 --- a/spring-integration-ws/src/main/java/org/springframework/integration/ws/adapter/AbstractWebServiceTargetAdapter.java +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/adapter/AbstractWebServiceTargetAdapter.java @@ -17,6 +17,7 @@ package org.springframework.integration.ws.adapter; import java.io.IOException; +import java.net.URI; import org.springframework.integration.handler.MessageHandler; import org.springframework.integration.message.GenericMessage; @@ -45,9 +46,9 @@ public abstract class AbstractWebServiceTargetAdapter implements MessageHandler private volatile WebServiceMessageCallback requestCallback; - public AbstractWebServiceTargetAdapter(String uri) { - Assert.hasText(uri, "'uri' must not be empty or null"); - this.webServiceTemplate.setDefaultUri(uri); + public AbstractWebServiceTargetAdapter(URI uri) { + Assert.notNull(uri, "'uri' must not be null"); + this.webServiceTemplate.setDefaultUri(uri.toString()); } 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 index 78846a0622..c653d7807f 100644 --- 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 @@ -16,6 +16,8 @@ package org.springframework.integration.ws.adapter; +import java.net.URI; + import org.springframework.oxm.Marshaller; import org.springframework.oxm.Unmarshaller; import org.springframework.util.Assert; @@ -30,7 +32,7 @@ import org.springframework.ws.client.core.WebServiceMessageCallback; */ public class MarshallingWebServiceTargetAdapter extends AbstractWebServiceTargetAdapter { - public MarshallingWebServiceTargetAdapter(String uri, Marshaller marshaller, Unmarshaller unmarshaller) { + public MarshallingWebServiceTargetAdapter(URI uri, Marshaller marshaller, Unmarshaller unmarshaller) { super(uri); Assert.notNull(marshaller, "marshaller must not be null"); Assert.notNull(unmarshaller, "unmarshaller must not be null"); @@ -38,10 +40,10 @@ public class MarshallingWebServiceTargetAdapter extends AbstractWebServiceTarget this.getWebServiceTemplate().setUnmarshaller(unmarshaller); } - public MarshallingWebServiceTargetAdapter(String uri, Marshaller marshaller) { + public MarshallingWebServiceTargetAdapter(URI uri, Marshaller marshaller) { super(uri); Assert.notNull(marshaller, "marshaller must not be null"); - Assert.isTrue(marshaller instanceof Unmarshaller, + 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."); diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/adapter/SimpleWebServiceTargetAdapter.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/adapter/SimpleWebServiceTargetAdapter.java index cdd8ee17d5..07ab794016 100644 --- a/spring-integration-ws/src/main/java/org/springframework/integration/ws/adapter/SimpleWebServiceTargetAdapter.java +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/adapter/SimpleWebServiceTargetAdapter.java @@ -17,15 +17,19 @@ package org.springframework.integration.ws.adapter; import java.io.IOException; +import java.net.URI; import javax.xml.transform.Source; import javax.xml.transform.TransformerException; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.dom.DOMSource; import org.springframework.integration.message.MessageHandlingException; import org.springframework.ws.client.core.SourceExtractor; import org.springframework.ws.client.core.WebServiceMessageCallback; import org.springframework.xml.transform.StringResult; import org.springframework.xml.transform.StringSource; +import org.springframework.xml.transform.TransformerObjectSupport; /** * A target channel adapter for calling out to a Web Service. @@ -37,11 +41,11 @@ public class SimpleWebServiceTargetAdapter extends AbstractWebServiceTargetAdapt private final SourceExtractor sourceExtractor; - public SimpleWebServiceTargetAdapter(String uri) { + public SimpleWebServiceTargetAdapter(URI uri) { this(uri, null); } - public SimpleWebServiceTargetAdapter(String uri, SourceExtractor sourceExtractor) { + public SimpleWebServiceTargetAdapter(URI uri, SourceExtractor sourceExtractor) { super(uri); this.sourceExtractor = (sourceExtractor != null) ? sourceExtractor : new DefaultSourceExtractor(); } @@ -65,10 +69,15 @@ public class SimpleWebServiceTargetAdapter extends AbstractWebServiceTargetAdapt } - private static class DefaultSourceExtractor implements SourceExtractor { + private static class DefaultSourceExtractor extends TransformerObjectSupport implements SourceExtractor { public Object extractData(Source source) throws IOException, TransformerException { - return source; + if (source instanceof DOMSource) { + return source; + } + DOMResult result = new DOMResult(); + this.transform(source, result); + return new DOMSource(result.getNode()); } }