Advantages of WebServiceGatewaySupport vs WebServiceTemplate

Sorin picture Sorin · Mar 4, 2013 · Viewed 10.7k times · Source

I have to implement a webservice client using Spring WS.

I've read the documentation at http://static.springsource.org/spring-ws/site/reference/html/client.html but it's not clear to me what are the advantages of extending WebServiceGatewaySupport versus directly using WebServiceTemplate in my service class.

As far as I can tell from the source, the WebServiceGatewaySupport only has a couple of wrapper methods for the WebServiceTemplate and some initialization support.

So why should I extend WebServiceGatewaySupport instead of directly using a WebServiceTemplate ?

Thank you!

Answer

evandongen picture evandongen · Mar 7, 2013

I think this sums it all up (found in the client reference you linked):

Alternatively, consider deriving from Spring-WS's WebServiceGatewaySupport convenience base class, which exposes convenient bean properties to enable easy configuration. (You do not have to extend this base class... it is provided as a convenience class only.)

So, if the WebserviceTemplate offers all you need, that'll probably suffice. If you need anything extra you can use the WebServiceGatewaySupport as an example on how to wrap your own convenience methods around the WebserviceTemplate.

In my client software, I just configure the WebserviceTemplate in my @Configuration class like this:

@Bean
public WebServiceTemplate webServiceTemplate() {
    WebServiceTemplate template = new WebServiceTemplate();
    template.setMessageFactory(messageFactory());
    template.setDefaultUri(defaultUri);
    template.setMarshaller(marshaller());
    template.setUnmarshaller(marshaller());
    template.setInterceptors(new ClientInterceptor[] {interceptor()});

    return template;
}

(All the method calls are references to other methods in the configuration which aren't that relevant in this example). I can use that bean everywhere in my code to send messages.