|
Spring Web Services Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.xml.transform.TransformerObjectSupport
org.springframework.ws.client.support.WebServiceAccessor
org.springframework.ws.client.core.WebServiceTemplate
public class WebServiceTemplate
The central class for client-side Web services. It provides a message-driven approach to sending and
receiving WebServiceMessage
instances.
Source
objects to read data from, or
use the pluggable Marshaller
support. For invoking the marshalling methods
,
the marshaller
and unmarshaller
properties
must be set.
This template uses a SoapFaultMessageResolver
to handle fault response messages. Another FaultMessageResolver
can be defined with with faultMessageResolver
property. If this property is set to null
, no fault resolving is performed.
This template uses the following algorithm for sending and receiving. createConnection()
.createWebServiceMessage()
on the registered message factory to create a request message.doWithMessage()
on the request callback, if any. This
step stores content in the request message, based on Source
, marshalling, etc.send()
on the connection.hasError()
to check if the connection has an error. For an HTTP
transport, a status code other than 2xx
indicates an error. However, since a status code of 500 can also
indicate a SOAP fault, the template verifies whether the error is not a fault.handleError()
method, which by default throws a WebServiceTransportException
.receive
on the connection to read the response
message, if any.null
or false
hasFault()
to determine whether the response has a
fault. If it has, call the handleFault()
method.extractData()
on the response extractor, or doWithMessage
on the response callback.close
on the connection.
Field Summary | |
---|---|
static String |
MESSAGE_TRACING_LOG_CATEGORY
Log category to use for message tracing. |
protected static Log |
messageTracingLogger
Additional logger to use for message tracing. |
Fields inherited from class org.springframework.xml.transform.TransformerObjectSupport |
---|
logger |
Constructor Summary | |
---|---|
WebServiceTemplate()
Creates a new WebServiceTemplate using default settings. |
|
WebServiceTemplate(WebServiceMessageFactory messageFactory)
Creates a new WebServiceTemplate based on the given message factory. |
Method Summary | |
---|---|
String |
getDefaultUri()
Returns the default URI to be used on operations that do not have a URI parameter. |
FaultMessageResolver |
getFaultMessageResolver()
Returns the fault message resolver for this template. |
Marshaller |
getMarshaller()
Returns the marshaller for this template. |
Unmarshaller |
getUnmarshaller()
Returns the unmarshaller for this template. |
protected Object |
handleError(WebServiceConnection connection,
WebServiceMessage request)
Handles an error on the given connection. |
protected Object |
handleFault(WebServiceConnection connection,
WebServiceMessage request,
WebServiceMessage response)
Handles an fault in the given response message. |
protected boolean |
hasError(WebServiceConnection connection,
WebServiceMessage request)
Determines whether the given connection or message context has an error. |
protected boolean |
hasFault(WebServiceConnection connection,
WebServiceMessage response)
Determines whether the given connection or message has a fault. |
protected void |
initDefaultStrategies()
Initialize the default implementations for the template's strategies: SoapFaultMessageResolver , SaajSoapMessageFactory , and HttpUrlConnectionMessageSender . |
Object |
marshalSendAndReceive(Object requestPayload)
Sends a web service message that contains the given payload, marshalled by the configured Marshaller . |
Object |
marshalSendAndReceive(Object requestPayload,
WebServiceMessageCallback requestCallback)
Sends a web service message that contains the given payload, marshalled by the configured Marshaller . |
Object |
marshalSendAndReceive(String uri,
Object requestPayload)
Sends a web service message that contains the given payload, marshalled by the configured Marshaller . |
Object |
marshalSendAndReceive(String uri,
Object requestPayload,
WebServiceMessageCallback requestCallback)
Sends a web service message that contains the given payload, marshalled by the configured Marshaller . |
boolean |
sendAndReceive(String uri,
WebServiceMessageCallback requestCallback,
WebServiceMessageCallback responseCallback)
Sends a web service message that can be manipulated with the given request callback, handling the response with a response callback. |
Object |
sendAndReceive(String uri,
WebServiceMessageCallback requestCallback,
WebServiceMessageExtractor responseExtractor)
Sends a web service message that can be manipulated with the given callback, reading the result with a WebServiceMessageExtractor . |
boolean |
sendAndReceive(WebServiceMessageCallback requestCallback,
WebServiceMessageCallback responseCallback)
Sends a web service message that can be manipulated with the given request callback, handling the response with a response callback. |
Object |
sendAndReceive(WebServiceMessageCallback requestCallback,
WebServiceMessageExtractor responseExtractor)
Sends a web service message that can be manipulated with the given callback, reading the result with a WebServiceMessageExtractor . |
Object |
sendSourceAndReceive(Source requestPayload,
SourceExtractor responseExtractor)
Sends a web service message that contains the given payload, reading the result with a SourceExtractor . |
Object |
sendSourceAndReceive(Source requestPayload,
WebServiceMessageCallback requestCallback,
SourceExtractor responseExtractor)
Sends a web service message that contains the given payload, reading the result with a SourceExtractor . |
Object |
sendSourceAndReceive(String uri,
Source requestPayload,
SourceExtractor responseExtractor)
Sends a web service message that contains the given payload, reading the result with a SourceExtractor . |
Object |
sendSourceAndReceive(String uri,
Source requestPayload,
WebServiceMessageCallback requestCallback,
SourceExtractor responseExtractor)
Sends a web service message that contains the given payload, reading the result with a SourceExtractor . |
boolean |
sendSourceAndReceiveToResult(Source requestPayload,
Result responseResult)
Sends a web service message that contains the given payload. |
boolean |
sendSourceAndReceiveToResult(Source requestPayload,
WebServiceMessageCallback requestCallback,
Result responseResult)
Sends a web service message that contains the given payload. |
boolean |
sendSourceAndReceiveToResult(String uri,
Source requestPayload,
Result responseResult)
Sends a web service message that contains the given payload. |
boolean |
sendSourceAndReceiveToResult(String uri,
Source requestPayload,
WebServiceMessageCallback requestCallback,
Result responseResult)
Sends a web service message that contains the given payload. |
void |
setCheckConnectionForFault(boolean checkConnectionForFault)
Indicates whether the connection should be checked for fault
indicators (true ), or whether we should rely on the message only (false ). |
void |
setDefaultUri(String uri)
Set the default URI to be used on operations that do not have a URI parameter. |
void |
setFaultMessageResolver(FaultMessageResolver faultMessageResolver)
Sets the fault resolver for this template. |
void |
setMarshaller(Marshaller marshaller)
Sets the marshaller for this template. |
void |
setUnmarshaller(Unmarshaller unmarshaller)
Sets the unmarshaller for this template. |
Methods inherited from class org.springframework.ws.client.support.WebServiceAccessor |
---|
afterPropertiesSet, createConnection, getMessageFactory, getMessageSenders, setMessageFactory, setMessageSender, setMessageSenders |
Methods inherited from class org.springframework.xml.transform.TransformerObjectSupport |
---|
createTransformer, getTransformerFactory, transform |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String MESSAGE_TRACING_LOG_CATEGORY
protected static final Log messageTracingLogger
Constructor Detail |
---|
public WebServiceTemplate()
WebServiceTemplate
using default settings.
public WebServiceTemplate(WebServiceMessageFactory messageFactory)
WebServiceTemplate
based on the given message factory.
messageFactory
- the message factory to useMethod Detail |
---|
public String getDefaultUri()
public void setDefaultUri(String uri)
marshalSendAndReceive(Object)
,
marshalSendAndReceive(Object,WebServiceMessageCallback)
,
sendSourceAndReceiveToResult(Source,Result)
,
sendSourceAndReceiveToResult(Source,WebServiceMessageCallback,Result)
,
sendSourceAndReceive(Source,SourceExtractor)
,
sendSourceAndReceive(Source,WebServiceMessageCallback,SourceExtractor)
,
sendAndReceive(WebServiceMessageCallback,WebServiceMessageCallback)
public Marshaller getMarshaller()
public void setMarshaller(Marshaller marshaller)
public Unmarshaller getUnmarshaller()
public void setUnmarshaller(Unmarshaller unmarshaller)
public FaultMessageResolver getFaultMessageResolver()
public void setFaultMessageResolver(FaultMessageResolver faultMessageResolver)
SimpleFaultMessageResolver
, but may be set to
null
to disable fault handling.
public void setCheckConnectionForFault(boolean checkConnectionForFault)
connection
should be checked for fault
indicators (true
), or whether we should rely on the message
only (false
). The default is true
.
When using a HTTP transport, this property defines whether to check the HTTP response status code for fault
indicators. Both the SOAP specification and the WS-I Basic Profile define that a Web service must return a "500
Internal Server Error" HTTP status code if the response envelope is a Fault. Setting this property to
false
allows this template to deal with non-conformant services.
hasFault(WebServiceConnection,WebServiceMessage)
,
SOAP 1.1 specification,
WS-I Basic
Profileprotected void initDefaultStrategies()
SoapFaultMessageResolver
, SaajSoapMessageFactory
, and HttpUrlConnectionMessageSender
.
BeanInitializationException
- in case of initalization errorssetFaultMessageResolver(FaultMessageResolver)
,
WebServiceAccessor.setMessageFactory(WebServiceMessageFactory)
,
WebServiceAccessor.setMessageSender(WebServiceMessageSender)
public Object marshalSendAndReceive(Object requestPayload)
WebServiceOperations
Marshaller
. Returns the unmarshalled payload of the response message, if any.
This will only work with a default specified!
marshalSendAndReceive
in interface WebServiceOperations
requestPayload
- the object to marshal into the request message payload
null
if no response is givensetMarshaller(org.springframework.oxm.Marshaller)
,
setUnmarshaller(org.springframework.oxm.Unmarshaller)
public Object marshalSendAndReceive(String uri, Object requestPayload)
WebServiceOperations
Marshaller
. Returns the unmarshalled payload of the response message, if any.
marshalSendAndReceive
in interface WebServiceOperations
uri
- the URI to send the message torequestPayload
- the object to marshal into the request message payload
null
if no response is givensetMarshaller(org.springframework.oxm.Marshaller)
,
setUnmarshaller(org.springframework.oxm.Unmarshaller)
public Object marshalSendAndReceive(Object requestPayload, WebServiceMessageCallback requestCallback)
WebServiceOperations
Marshaller
. Returns the unmarshalled payload of the response message, if any. The given callback
allows changing of the request message after the payload has been marshalled to it.
This will only work with a default specified!
marshalSendAndReceive
in interface WebServiceOperations
requestPayload
- the object to marshal into the request message payloadrequestCallback
- callback to change message, can be null
null
if no response is givensetMarshaller(org.springframework.oxm.Marshaller)
,
setUnmarshaller(org.springframework.oxm.Unmarshaller)
public Object marshalSendAndReceive(String uri, Object requestPayload, WebServiceMessageCallback requestCallback)
WebServiceOperations
Marshaller
. Returns the unmarshalled payload of the response message, if any. The given callback
allows changing of the request message after the payload has been marshalled to it.
marshalSendAndReceive
in interface WebServiceOperations
uri
- the URI to send the message torequestPayload
- the object to marshal into the request message payloadrequestCallback
- callback to change message, can be null
null
if no response is givensetMarshaller(org.springframework.oxm.Marshaller)
,
setUnmarshaller(org.springframework.oxm.Unmarshaller)
public boolean sendSourceAndReceiveToResult(Source requestPayload, Result responseResult)
WebServiceOperations
Result
.
This will only work with a default uri specified!
sendSourceAndReceiveToResult
in interface WebServiceOperations
requestPayload
- the payload of the request messageresponseResult
- the result to write the response payload to
true
if a response was received; false
otherwisepublic boolean sendSourceAndReceiveToResult(String uri, Source requestPayload, Result responseResult)
WebServiceOperations
Result
.
sendSourceAndReceiveToResult
in interface WebServiceOperations
uri
- the URI to send the message torequestPayload
- the payload of the request messageresponseResult
- the result to write the response payload to
true
if a response was received; false
otherwisepublic boolean sendSourceAndReceiveToResult(Source requestPayload, WebServiceMessageCallback requestCallback, Result responseResult)
WebServiceOperations
Result
.
The given callback allows changing of the request message after the payload has been written to it.
This will only work with a default uri specified!
sendSourceAndReceiveToResult
in interface WebServiceOperations
requestPayload
- the payload of the request messagerequestCallback
- callback to change message, can be null
responseResult
- the result to write the response payload to
true
if a response was received; false
otherwisepublic boolean sendSourceAndReceiveToResult(String uri, Source requestPayload, WebServiceMessageCallback requestCallback, Result responseResult)
WebServiceOperations
Result
.
The given callback allows changing of the request message after the payload has been written to it.
sendSourceAndReceiveToResult
in interface WebServiceOperations
uri
- the URI to send the message torequestPayload
- the payload of the request messagerequestCallback
- callback to change message, can be null
responseResult
- the result to write the response payload to
true
if a response was received; false
otherwisepublic Object sendSourceAndReceive(Source requestPayload, SourceExtractor responseExtractor)
WebServiceOperations
SourceExtractor
.
This will only work with a default specified!
sendSourceAndReceive
in interface WebServiceOperations
requestPayload
- the payload of the request messageresponseExtractor
- object that will extract results
SourceExtractor
public Object sendSourceAndReceive(String uri, Source requestPayload, SourceExtractor responseExtractor)
WebServiceOperations
SourceExtractor
.
sendSourceAndReceive
in interface WebServiceOperations
uri
- the URI to send the message torequestPayload
- the payload of the request messageresponseExtractor
- object that will extract results
SourceExtractor
public Object sendSourceAndReceive(Source requestPayload, WebServiceMessageCallback requestCallback, SourceExtractor responseExtractor)
WebServiceOperations
SourceExtractor
.
The given callback allows changing of the request message after the payload has been written to it.
This will only work with a default uri specified!
sendSourceAndReceive
in interface WebServiceOperations
requestPayload
- the payload of the request messagerequestCallback
- callback to change message, can be null
responseExtractor
- object that will extract results
SourceExtractor
public Object sendSourceAndReceive(String uri, Source requestPayload, WebServiceMessageCallback requestCallback, SourceExtractor responseExtractor)
WebServiceOperations
SourceExtractor
.
The given callback allows changing of the request message after the payload has been written to it.
sendSourceAndReceive
in interface WebServiceOperations
uri
- the URI to send the message torequestPayload
- the payload of the request messagerequestCallback
- callback to change message, can be null
responseExtractor
- object that will extract results
SourceExtractor
public boolean sendAndReceive(WebServiceMessageCallback requestCallback, WebServiceMessageCallback responseCallback)
WebServiceOperations
sendAndReceive
in interface WebServiceOperations
requestCallback
- the callback to be used for manipulating the request messageresponseCallback
- the callback to be used for manipulating the response message
true
if a response was received; false
otherwisepublic boolean sendAndReceive(String uri, WebServiceMessageCallback requestCallback, WebServiceMessageCallback responseCallback)
WebServiceOperations
sendAndReceive
in interface WebServiceOperations
uri
- the URI to send the message torequestCallback
- the callback to be used for manipulating the request messageresponseCallback
- the callback to be used for manipulating the response message
true
if a response was received; false
otherwisepublic Object sendAndReceive(WebServiceMessageCallback requestCallback, WebServiceMessageExtractor responseExtractor)
WebServiceOperations
WebServiceMessageExtractor
.
This will only work with a default uri specified!
sendAndReceive
in interface WebServiceOperations
requestCallback
- the requestCallback to be used for manipulating the request messageresponseExtractor
- object that will extract results
WebServiceMessageExtractor
public Object sendAndReceive(String uri, WebServiceMessageCallback requestCallback, WebServiceMessageExtractor responseExtractor)
WebServiceOperations
WebServiceMessageExtractor
.
sendAndReceive
in interface WebServiceOperations
uri
- the URI to send the message torequestCallback
- the requestCallback to be used for manipulating the request messageresponseExtractor
- object that will extract results
WebServiceMessageExtractor
protected boolean hasError(WebServiceConnection connection, WebServiceMessage request) throws IOException
connection
first. If it indicates an
error, it makes sure that it is not a fault
.
connection
- the connection (possibly a FaultAwareWebServiceConnection
request
- the response message (possibly a FaultAwareWebServiceMessage
true
if the connection has an error; false
otherwise
IOException
- in case of I/O errorsprotected Object handleError(WebServiceConnection connection, WebServiceMessage request) throws IOException
WebServiceTransportException
.
connection
- the erronous connectionrequest
- the corresponding request message
sendAndReceive(String,WebServiceMessageCallback,
WebServiceMessageExtractor)
, if any
IOException
protected boolean hasFault(WebServiceConnection connection, WebServiceMessage response) throws IOException
connection
if the checkConnectionForFault
property is true, and defaults to the message
otherwise.
connection
- the connection (possibly a FaultAwareWebServiceConnection
response
- the response message (possibly a FaultAwareWebServiceMessage
true
if either the connection or the message has a fault; false
otherwise
IOException
- in case of I/O errorsprotected Object handleFault(WebServiceConnection connection, WebServiceMessage request, WebServiceMessage response) throws IOException
fault resolver
if registered, or invokes handleError(WebServiceConnection,
WebServiceMessage)
otherwise.
connection
- the erronous connectionrequest
- the corresponding request messageresponse
- the fault response message
sendAndReceive(String,WebServiceMessageCallback,
WebServiceMessageExtractor)
, if any
IOException
|
Spring Web Services Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |