Using URI instead of String in target adapters. DefaultSourceExtractor now creates a DOMSource if the source to extract from is not already a DOMSource.

This commit is contained in:
Mark Fisher
2008-03-29 15:18:53 +00:00
parent 8157f0783a
commit 2b4f08270e
3 changed files with 22 additions and 10 deletions

View File

@@ -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());
}

View File

@@ -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.");

View File

@@ -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());
}
}