INT-2655: (un)marshal Only via WebServiceTemplate

JIRA: https://jira.spring.io/browse/INT-2655

There might be some use-cases when end-user expect more control over sending/receiving messages via `WebServiceTemplate`.
It would be better to delegate (un)marshalling logic to the `WebServiceTemplate.marshalSendAndReceive()` directly.

Fix Checkstyle violations

Polishing
This commit is contained in:
Artem Bilan
2017-02-16 11:44:31 -05:00
committed by Gary Russell
parent b0094b32b7
commit dda2fea60e
4 changed files with 78 additions and 61 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -66,7 +66,7 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro
private final Map<String, Expression> uriVariableExpressions = new HashMap<String, Expression>();
private volatile StandardEvaluationContext evaluationContext;
private volatile StandardEvaluationContext evaluationContext;
private volatile WebServiceMessageCallback requestCallback;
@@ -140,6 +140,10 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro
}
public void setWebServiceTemplate(WebServiceTemplate webServiceTemplate) {
doSetWebServiceTemplate(webServiceTemplate);
}
protected final void doSetWebServiceTemplate(WebServiceTemplate webServiceTemplate) {
Assert.notNull(webServiceTemplate, "'webServiceTemplate' must not be null");
this.webServiceTemplate = webServiceTemplate;
this.webServiceTemplateExplicitlySet = true;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -25,8 +25,8 @@ import org.springframework.util.Assert;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.client.support.destination.DestinationProvider;
import org.springframework.ws.support.MarshallingUtils;
/**
* An outbound Messaging Gateway for invoking Web Services that also supports
@@ -35,18 +35,18 @@ import org.springframework.ws.support.MarshallingUtils;
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
*
* @see Marshaller
* @see Unmarshaller
*/
public class MarshallingWebServiceOutboundGateway extends AbstractWebServiceOutboundGateway {
private volatile Marshaller marshaller;
private volatile Unmarshaller unmarshaller;
public MarshallingWebServiceOutboundGateway(DestinationProvider destinationProvider, Marshaller marshaller,
Unmarshaller unmarshaller, WebServiceMessageFactory messageFactory) {
super(destinationProvider, messageFactory);
this.configureMarshallers(marshaller, unmarshaller);
configureMarshallers(marshaller, unmarshaller);
}
public MarshallingWebServiceOutboundGateway(DestinationProvider destinationProvider, Marshaller marshaller,
@@ -66,7 +66,7 @@ public class MarshallingWebServiceOutboundGateway extends AbstractWebServiceOutb
public MarshallingWebServiceOutboundGateway(String uri, Marshaller marshaller, Unmarshaller unmarshaller,
WebServiceMessageFactory messageFactory) {
super(uri, messageFactory);
this.configureMarshallers(marshaller, unmarshaller);
configureMarshallers(marshaller, unmarshaller);
}
public MarshallingWebServiceOutboundGateway(String uri, Marshaller marshaller, Unmarshaller unmarshaller) {
@@ -82,23 +82,32 @@ public class MarshallingWebServiceOutboundGateway extends AbstractWebServiceOutb
this(uri, marshaller, (WebServiceMessageFactory) null);
}
@Override
protected Object doHandle(String uri, Message<?> requestMessage, WebServiceMessageCallback requestCallback) {
Object reply = this.getWebServiceTemplate().sendAndReceive(uri,
new MarshallingRequestMessageCallback(requestCallback, requestMessage),
new MarshallingResponseMessageExtractor());
return reply;
/**
* Construct an instance based on the provided Web Service URI and {@code WebServiceTemplate}.
* @param uri the Web Service URI to use
* @param webServiceTemplate the WebServiceTemplate
* @since 5.0
*/
public MarshallingWebServiceOutboundGateway(String uri, WebServiceTemplate webServiceTemplate) {
super(uri, null);
doSetWebServiceTemplate(webServiceTemplate);
}
@Override
public String getComponentType() {
return "ws:outbound-gateway(marshaling)";
/**
* Construct an instance based on the provided {@code DestinationProvider} and {@code WebServiceTemplate}.
* @param destinationProvider the {@link DestinationProvider} to resolve Web Service URI at runtime
* @param webServiceTemplate the WebServiceTemplate
* @since 5.0
*/
public MarshallingWebServiceOutboundGateway(DestinationProvider destinationProvider,
WebServiceTemplate webServiceTemplate) {
super(destinationProvider, null);
doSetWebServiceTemplate(webServiceTemplate);
}
/**
* Sets the provided Marshaller and Unmarshaller on this gateway's WebServiceTemplate.
* Neither may be null.
*
* @param marshaller The marshaller.
* @param unmarshaller The unmarshaller.
*/
@@ -107,39 +116,39 @@ public class MarshallingWebServiceOutboundGateway extends AbstractWebServiceOutb
if (unmarshaller == null) {
Assert.isInstanceOf(Unmarshaller.class, marshaller,
"Marshaller [" + marshaller + "] does not implement the Unmarshaller interface. " +
"Please set an Unmarshaller explicitly by using one of the constructors that accepts " +
"both Marshaller and Unmarshaller arguments.");
"Please set an Unmarshaller explicitly by using one of the constructors that accepts " +
"both Marshaller and Unmarshaller arguments.");
unmarshaller = (Unmarshaller) marshaller;
}
Assert.notNull(unmarshaller, "unmarshaller must not be null");
this.marshaller = marshaller;
this.unmarshaller = unmarshaller;
getWebServiceTemplate().setMarshaller(marshaller);
getWebServiceTemplate().setUnmarshaller(unmarshaller);
}
private final class MarshallingRequestMessageCallback extends RequestMessageCallback {
@Override
public String getComponentType() {
return "ws:outbound-gateway(marshalling)";
}
MarshallingRequestMessageCallback(WebServiceMessageCallback requestCallback,
Message<?> requestMessage) {
@Override
protected Object doHandle(String uri, Message<?> requestMessage, WebServiceMessageCallback requestCallback) {
return getWebServiceTemplate()
.marshalSendAndReceive(uri, requestMessage.getPayload(),
new PassThroughRequestMessageCallback(requestCallback, requestMessage));
}
private final class PassThroughRequestMessageCallback extends RequestMessageCallback {
PassThroughRequestMessageCallback(WebServiceMessageCallback requestCallback, Message<?> requestMessage) {
super(requestCallback, requestMessage);
}
@Override
public void doWithMessageInternal(WebServiceMessage message, Object payload) throws IOException {
MarshallingUtils.marshal(MarshallingWebServiceOutboundGateway.this.marshaller, payload, message);
}
}
private class MarshallingResponseMessageExtractor extends ResponseMessageExtractor {
MarshallingResponseMessageExtractor() {
super();
}
@Override
public Object doExtractData(WebServiceMessage message) throws IOException {
return MarshallingUtils.unmarshal(MarshallingWebServiceOutboundGateway.this.unmarshaller, message);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -56,7 +56,7 @@ public class SimpleWebServiceOutboundGateway extends AbstractWebServiceOutboundG
public SimpleWebServiceOutboundGateway(DestinationProvider destinationProvider,
SourceExtractor<?> sourceExtractor) {
this(destinationProvider, sourceExtractor, (WebServiceMessageFactory) null);
this(destinationProvider, sourceExtractor, null);
}
public SimpleWebServiceOutboundGateway(DestinationProvider destinationProvider, SourceExtractor<?> sourceExtractor,
@@ -70,7 +70,7 @@ public class SimpleWebServiceOutboundGateway extends AbstractWebServiceOutboundG
}
public SimpleWebServiceOutboundGateway(String uri, SourceExtractor<?> sourceExtractor) {
this(uri, sourceExtractor, (WebServiceMessageFactory) null);
this(uri, sourceExtractor, null);
}
public SimpleWebServiceOutboundGateway(String uri, SourceExtractor<?> sourceExtractor,
@@ -160,7 +160,7 @@ public class SimpleWebServiceOutboundGateway extends AbstractWebServiceOutboundG
return this.result.toString();
}
else if (this.result instanceof DOMResult) {
return ((DOMResult) this.result).getNode();
return ((DOMResult) this.result).getNode();
}
else {
return this.result;