Skip to content

Commit 761c354

Browse files
committed
SWS-725 - Add a constructor/setter to WebServiceTemplate which takes a Marshaller and assigns it as both Marshaller and Unmarshaller
1 parent 62f40d2 commit 761c354

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,46 @@ public WebServiceTemplate(WebServiceMessageFactory messageFactory) {
140140
initDefaultStrategies();
141141
}
142142

143+
/**
144+
* Creates a new <code>WebServiceTemplate</code> with the given marshaller. If the given {@link
145+
* Marshaller} also implements the {@link Unmarshaller} interface, it is used for both marshalling and
146+
* unmarshalling. Otherwise, an exception is thrown.
147+
* <p/>
148+
* Note that all {@link Marshaller} implementations in Spring also implement the {@link Unmarshaller} interface,
149+
* so that you can safely use this constructor.
150+
*
151+
* @param marshaller object used as marshaller and unmarshaller
152+
* @throws IllegalArgumentException when <code>marshaller</code> does not implement the {@link Unmarshaller}
153+
* interface
154+
* @since 2.0.3
155+
*/
156+
public WebServiceTemplate(Marshaller marshaller) {
157+
Assert.notNull(marshaller, "marshaller must not be null");
158+
if (!(marshaller instanceof Unmarshaller)) {
159+
throw new IllegalArgumentException("Marshaller [" + marshaller + "] does not implement the Unmarshaller " +
160+
"interface. Please set an Unmarshaller explicitly by using the " +
161+
"WebServiceTemplate(Marshaller, Unmarshaller) constructor.");
162+
}
163+
else {
164+
this.setMarshaller(marshaller);
165+
this.setUnmarshaller((Unmarshaller) marshaller);
166+
}
167+
}
168+
169+
/**
170+
* Creates a new <code>MarshallingMethodEndpointAdapter</code> with the given marshaller and unmarshaller.
171+
*
172+
* @param marshaller the marshaller to use
173+
* @param unmarshaller the unmarshaller to use
174+
* @since 2.0.3
175+
*/
176+
public WebServiceTemplate(Marshaller marshaller, Unmarshaller unmarshaller) {
177+
Assert.notNull(marshaller, "marshaller must not be null");
178+
Assert.notNull(unmarshaller, "unmarshaller must not be null");
179+
this.setMarshaller(marshaller);
180+
this.setUnmarshaller(unmarshaller);
181+
}
182+
143183
/** Returns the default URI to be used on operations that do not have a URI parameter. */
144184
public String getDefaultUri() {
145185
if (destinationProvider != null) {

0 commit comments

Comments
 (0)