diff --git a/core/src/main/java/org/springframework/ws/client/core/WebServiceTemplate.java b/core/src/main/java/org/springframework/ws/client/core/WebServiceTemplate.java index 4d8a0995..a3fda342 100644 --- a/core/src/main/java/org/springframework/ws/client/core/WebServiceTemplate.java +++ b/core/src/main/java/org/springframework/ws/client/core/WebServiceTemplate.java @@ -286,24 +286,30 @@ public class WebServiceTemplate extends WebServiceAccessor implements WebService public Object marshalSendAndReceive(String uri, final Object requestPayload, final WebServiceMessageCallback requestCallback) { - if (getMarshaller() == null) { - throw new IllegalStateException("No marshaller registered. Check configuration of WebServiceTemplate."); - } - if (getUnmarshaller() == null) { - throw new IllegalStateException("No unmarshaller registered. Check configuration of WebServiceTemplate."); - } return sendAndReceive(uri, new WebServiceMessageCallback() { public void doWithMessage(WebServiceMessage request) throws IOException, TransformerException { - MarshallingUtils.marshal(getMarshaller(), requestPayload, request); - if (requestCallback != null) { - requestCallback.doWithMessage(request); + if (requestPayload != null) { + Marshaller marshaller = getMarshaller(); + if (marshaller == null) { + throw new IllegalStateException( + "No marshaller registered. Check configuration of WebServiceTemplate."); + } + MarshallingUtils.marshal(marshaller, requestPayload, request); + if (requestCallback != null) { + requestCallback.doWithMessage(request); + } } } }, new WebServiceMessageExtractor() { public Object extractData(WebServiceMessage response) throws IOException { - return MarshallingUtils.unmarshal(getUnmarshaller(), response); + Unmarshaller unmarshaller = getUnmarshaller(); + if (unmarshaller == null) { + throw new IllegalStateException( + "No unmarshaller registered. Check configuration of WebServiceTemplate."); + } + return MarshallingUtils.unmarshal(unmarshaller, response); } }); } diff --git a/core/src/main/java/org/springframework/ws/server/endpoint/AbstractMarshallingPayloadEndpoint.java b/core/src/main/java/org/springframework/ws/server/endpoint/AbstractMarshallingPayloadEndpoint.java index fa36de9a..9511a5d7 100644 --- a/core/src/main/java/org/springframework/ws/server/endpoint/AbstractMarshallingPayloadEndpoint.java +++ b/core/src/main/java/org/springframework/ws/server/endpoint/AbstractMarshallingPayloadEndpoint.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.beans.factory.InitializingBean; import org.springframework.oxm.Marshaller; import org.springframework.oxm.Unmarshaller; @@ -119,9 +120,7 @@ public abstract class AbstractMarshallingPayloadEndpoint implements MessageEndpo this.unmarshaller = unmarshaller; } - public final void afterPropertiesSet() throws Exception { - Assert.notNull(getMarshaller(), "marshaller is required"); - Assert.notNull(getUnmarshaller(), "unmarshaller is required"); + public void afterPropertiesSet() throws Exception { afterMarshallerSet(); } @@ -139,7 +138,9 @@ public abstract class AbstractMarshallingPayloadEndpoint implements MessageEndpo } private Object unmarshalRequest(WebServiceMessage request) throws IOException { - Object requestObject = MarshallingUtils.unmarshal(getUnmarshaller(), request); + Unmarshaller unmarshaller = getUnmarshaller(); + Assert.notNull(unmarshaller, "No unmarshaller registered. Check configuration of endpoint."); + Object requestObject = MarshallingUtils.unmarshal(unmarshaller, request); if (logger.isDebugEnabled()) { logger.debug("Unmarshalled payload request to [" + requestObject + "]"); } @@ -161,10 +162,12 @@ public abstract class AbstractMarshallingPayloadEndpoint implements MessageEndpo } private void marshalResponse(Object responseObject, WebServiceMessage response) throws IOException { + Marshaller marshaller = getMarshaller(); + Assert.notNull(marshaller, "No marshaller registered. Check configuration of endpoint."); if (logger.isDebugEnabled()) { logger.debug("Marshalling [" + responseObject + "] to response payload"); } - MarshallingUtils.marshal(getMarshaller(), responseObject, response); + MarshallingUtils.marshal(marshaller, responseObject, response); } /** @@ -184,6 +187,9 @@ public abstract class AbstractMarshallingPayloadEndpoint implements MessageEndpo * Template method that gets called after the marshaller and unmarshaller have been set. *
* The default implementation does nothing. + * + * @deprecated as of Spring Web Services 1.5: {@link #afterPropertiesSet()} is no longer final, so this can safely + * be overriden in subclasses */ public void afterMarshallerSet() throws Exception { }