Using Spring Web Services on the ClientIntroduction
Spring-WS provides a client-side Web service API that allows for consistent, XML-driven access to Web
services. It also allows for use of marshallers and unmarshallers.
The package org.springframework.ws.client.core provides the core functionality for using
the client-side access API. It contains template classes that simplifies the use of Web services, much like
the JdbcTemplate does for JDBC. The design principle common to Spring template
classes is to provide helper methods to perform common operations and for more sophisticated usage, delegate
the essence of the processing task to user implemented callback interfaces. The Web service template
follows the same design. The classes offer various
convenience methods for the sending and receiving of XML messages, marshalling objects to XML before sending,
and allows for multiple transports,
Using the client-side APIWebServiceTemplate
The WebServiceTemplate is the core class for client-side Web service access in
Spring-WS. It contains methods for sending Source objects, and receiving response
messages as either Source or Result. Additionally, it can
marshal objects to XML before sending them across a transport, and unmarshal the response XML into an
object again.
Transports
The WebServiceTemplate requires a reference to a
MessageSender. The message sender is responsible for sending the XML message
across a transport layer.
There are two implementations of the MessageSender interface for sending messages
via HTTP. The simplest implementation is the HttpUrlConnectionMessageSender,
which uses the facilities provided by Java SE itself. The alternative is the
CommonsHttpMessageSender, which uses the Jakarta Commons HttpClient. Use the
latter if you need more advanced and easy-to-use functionality. Both HTTP message senders require an
URL to be set using the url property.
Message factories
In addition to a message sender, the WebServiceTemplate requires a Web service
message factory. As explained in , there are two message factories
for SOAP: SaajSoapMessageFactory and
AxiomSoapMessageFactory.