Skip to content

Commit 7497061

Browse files
committed
SWS-315
1 parent ee8985c commit 7497061

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

core/src/main/java/org/springframework/ws/client/core/WebServiceTemplate.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,24 +286,30 @@ public Object marshalSendAndReceive(final Object requestPayload, final WebServic
286286
public Object marshalSendAndReceive(String uri,
287287
final Object requestPayload,
288288
final WebServiceMessageCallback requestCallback) {
289-
if (getMarshaller() == null) {
290-
throw new IllegalStateException("No marshaller registered. Check configuration of WebServiceTemplate.");
291-
}
292-
if (getUnmarshaller() == null) {
293-
throw new IllegalStateException("No unmarshaller registered. Check configuration of WebServiceTemplate.");
294-
}
295289
return sendAndReceive(uri, new WebServiceMessageCallback() {
296290

297291
public void doWithMessage(WebServiceMessage request) throws IOException, TransformerException {
298-
MarshallingUtils.marshal(getMarshaller(), requestPayload, request);
299-
if (requestCallback != null) {
300-
requestCallback.doWithMessage(request);
292+
if (requestPayload != null) {
293+
Marshaller marshaller = getMarshaller();
294+
if (marshaller == null) {
295+
throw new IllegalStateException(
296+
"No marshaller registered. Check configuration of WebServiceTemplate.");
297+
}
298+
MarshallingUtils.marshal(marshaller, requestPayload, request);
299+
if (requestCallback != null) {
300+
requestCallback.doWithMessage(request);
301+
}
301302
}
302303
}
303304
}, new WebServiceMessageExtractor() {
304305

305306
public Object extractData(WebServiceMessage response) throws IOException {
306-
return MarshallingUtils.unmarshal(getUnmarshaller(), response);
307+
Unmarshaller unmarshaller = getUnmarshaller();
308+
if (unmarshaller == null) {
309+
throw new IllegalStateException(
310+
"No unmarshaller registered. Check configuration of WebServiceTemplate.");
311+
}
312+
return MarshallingUtils.unmarshal(unmarshaller, response);
307313
}
308314
});
309315
}

core/src/main/java/org/springframework/ws/server/endpoint/AbstractMarshallingPayloadEndpoint.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.apache.commons.logging.Log;
2222
import org.apache.commons.logging.LogFactory;
23+
2324
import org.springframework.beans.factory.InitializingBean;
2425
import org.springframework.oxm.Marshaller;
2526
import org.springframework.oxm.Unmarshaller;
@@ -119,9 +120,7 @@ public final void setUnmarshaller(Unmarshaller unmarshaller) {
119120
this.unmarshaller = unmarshaller;
120121
}
121122

122-
public final void afterPropertiesSet() throws Exception {
123-
Assert.notNull(getMarshaller(), "marshaller is required");
124-
Assert.notNull(getUnmarshaller(), "unmarshaller is required");
123+
public void afterPropertiesSet() throws Exception {
125124
afterMarshallerSet();
126125
}
127126

@@ -139,7 +138,9 @@ public final void invoke(MessageContext messageContext) throws Exception {
139138
}
140139

141140
private Object unmarshalRequest(WebServiceMessage request) throws IOException {
142-
Object requestObject = MarshallingUtils.unmarshal(getUnmarshaller(), request);
141+
Unmarshaller unmarshaller = getUnmarshaller();
142+
Assert.notNull(unmarshaller, "No unmarshaller registered. Check configuration of endpoint.");
143+
Object requestObject = MarshallingUtils.unmarshal(unmarshaller, request);
143144
if (logger.isDebugEnabled()) {
144145
logger.debug("Unmarshalled payload request to [" + requestObject + "]");
145146
}
@@ -161,10 +162,12 @@ protected boolean onUnmarshalRequest(MessageContext messageContext, Object reque
161162
}
162163

163164
private void marshalResponse(Object responseObject, WebServiceMessage response) throws IOException {
165+
Marshaller marshaller = getMarshaller();
166+
Assert.notNull(marshaller, "No marshaller registered. Check configuration of endpoint.");
164167
if (logger.isDebugEnabled()) {
165168
logger.debug("Marshalling [" + responseObject + "] to response payload");
166169
}
167-
MarshallingUtils.marshal(getMarshaller(), responseObject, response);
170+
MarshallingUtils.marshal(marshaller, responseObject, response);
168171
}
169172

170173
/**
@@ -184,6 +187,9 @@ protected void onMarshalResponse(MessageContext messageContext, Object requestOb
184187
* Template method that gets called after the marshaller and unmarshaller have been set.
185188
* <p/>
186189
* The default implementation does nothing.
190+
*
191+
* @deprecated as of Spring Web Services 1.5: {@link #afterPropertiesSet()} is no longer final, so this can safely
192+
* be overriden in subclasses
187193
*/
188194
public void afterMarshallerSet() throws Exception {
189195
}

0 commit comments

Comments
 (0)