|
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.handleRequest() on the registered interceptors. Interceptors are executed in order. If any of the interceptors
creates a response message in the message context, skip to step 7.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
falsehasFault() to determine
whether the response has a fault. If it has, call ClientInterceptor.handleFault(MessageContext) and the
handleFault() method.ClientInterceptor.handleResponse(MessageContext)
and 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 |
receivedMessageTracingLogger
Additional logger to use for received message tracing. |
protected static Log |
sentMessageTracingLogger
Additional logger to use for sent message tracing. |
| Fields inherited from class org.springframework.xml.transform.TransformerObjectSupport |
|---|
logger |
| Constructor Summary | |
|---|---|
WebServiceTemplate()
Creates a new WebServiceTemplate using default settings. |
|
WebServiceTemplate(org.springframework.oxm.Marshaller marshaller)
Creates a new WebServiceTemplate with the given marshaller. |
|
WebServiceTemplate(org.springframework.oxm.Marshaller marshaller,
org.springframework.oxm.Unmarshaller unmarshaller)
Creates a new MarshallingMethodEndpointAdapter with the given marshaller and unmarshaller. |
|
WebServiceTemplate(WebServiceMessageFactory messageFactory)
Creates a new WebServiceTemplate based on the given message factory. |
|
| Method Summary | ||
|---|---|---|
protected
|
doSendAndReceive(MessageContext messageContext,
WebServiceConnection connection,
WebServiceMessageCallback requestCallback,
WebServiceMessageExtractor<T> responseExtractor)
Sends and receives a MessageContext. |
|
String |
getDefaultUri()
Returns the default URI to be used on operations that do not have a URI parameter. |
|
DestinationProvider |
getDestinationProvider()
Returns the destination provider used on operations that do not have a URI parameter. |
|
FaultMessageResolver |
getFaultMessageResolver()
Returns the fault message resolver for this template. |
|
ClientInterceptor[] |
getInterceptors()
Returns the client interceptors to apply to all web service invocations made by this template. |
|
org.springframework.oxm.Marshaller |
getMarshaller()
Returns the marshaller for this template. |
|
org.springframework.oxm.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,
MessageContext messageContext)
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. |
|
|
sendAndReceive(String uriString,
WebServiceMessageCallback requestCallback,
WebServiceMessageExtractor<T> 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. |
|
|
sendAndReceive(WebServiceMessageCallback requestCallback,
WebServiceMessageExtractor<T> responseExtractor)
Sends a web service message that can be manipulated with the given callback, reading the result with a WebServiceMessageExtractor. |
|
|
sendSourceAndReceive(Source requestPayload,
SourceExtractor<T> responseExtractor)
Sends a web service message that contains the given payload, reading the result with a SourceExtractor. |
|
|
sendSourceAndReceive(Source requestPayload,
WebServiceMessageCallback requestCallback,
SourceExtractor<T> responseExtractor)
Sends a web service message that contains the given payload, reading the result with a SourceExtractor. |
|
|
sendSourceAndReceive(String uri,
Source requestPayload,
SourceExtractor<T> responseExtractor)
Sends a web service message that contains the given payload, reading the result with a SourceExtractor. |
|
|
sendSourceAndReceive(String uri,
Source requestPayload,
WebServiceMessageCallback requestCallback,
SourceExtractor<T> 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 |
setCheckConnectionForError(boolean checkConnectionForError)
Indicates whether the connection should be checked for error indicators ( true), or whether these should be ignored (false). |
|
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 |
setDestinationProvider(DestinationProvider destinationProvider)
Set the destination provider 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 |
setInterceptors(ClientInterceptor[] interceptors)
Sets the client interceptors to apply to all web service invocations made by this template. |
|
void |
setMarshaller(org.springframework.oxm.Marshaller marshaller)
Sets the marshaller for this template. |
|
void |
setUnmarshaller(org.springframework.oxm.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, newTransformerFactory, setTransformerFactoryClass, 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 sentMessageTracingLogger
protected static final Log receivedMessageTracingLogger
| Constructor Detail |
|---|
public WebServiceTemplate()
WebServiceTemplate using default settings.
public WebServiceTemplate(WebServiceMessageFactory messageFactory)
WebServiceTemplate based on the given message factory.
messageFactory - the message factory to usepublic WebServiceTemplate(org.springframework.oxm.Marshaller marshaller)
WebServiceTemplate with the given marshaller. If the given Marshaller also implements the Unmarshaller interface, it is used for both marshalling and
unmarshalling. Otherwise, an exception is thrown.
Note that all Marshaller implementations in Spring also implement the Unmarshaller interface,
so that you can safely use this constructor.
marshaller - object used as marshaller and unmarshaller
IllegalArgumentException - when marshaller does not implement the Unmarshaller
interface
public WebServiceTemplate(org.springframework.oxm.Marshaller marshaller,
org.springframework.oxm.Unmarshaller unmarshaller)
MarshallingMethodEndpointAdapter with the given marshaller and unmarshaller.
marshaller - the marshaller to useunmarshaller - the unmarshaller to use| Method Detail |
|---|
public String getDefaultUri()
public void setDefaultUri(String uri)
setDestinationProvider(DestinationProvider), but not both.
marshalSendAndReceive(Object),
marshalSendAndReceive(Object,WebServiceMessageCallback),
sendSourceAndReceiveToResult(Source,Result),
sendSourceAndReceiveToResult(Source,WebServiceMessageCallback,Result),
sendSourceAndReceive(Source,SourceExtractor),
sendSourceAndReceive(Source,WebServiceMessageCallback,SourceExtractor),
sendAndReceive(WebServiceMessageCallback,WebServiceMessageCallback)public DestinationProvider getDestinationProvider()
public void setDestinationProvider(DestinationProvider destinationProvider)
setDefaultUri(String), but not both.
marshalSendAndReceive(Object),
marshalSendAndReceive(Object,WebServiceMessageCallback),
sendSourceAndReceiveToResult(Source,Result),
sendSourceAndReceiveToResult(Source,WebServiceMessageCallback,Result),
sendSourceAndReceive(Source,SourceExtractor),
sendSourceAndReceive(Source,WebServiceMessageCallback,SourceExtractor),
sendAndReceive(WebServiceMessageCallback,WebServiceMessageCallback)public org.springframework.oxm.Marshaller getMarshaller()
public void setMarshaller(org.springframework.oxm.Marshaller marshaller)
public org.springframework.oxm.Unmarshaller getUnmarshaller()
public void setUnmarshaller(org.springframework.oxm.Unmarshaller unmarshaller)
public FaultMessageResolver getFaultMessageResolver()
public void setFaultMessageResolver(FaultMessageResolver faultMessageResolver)
org.springframework.ws.soap.client.core.SoapFaultMessageResolver, SoapFaultMessageResolver, but may be
set to null to disable fault handling.
public void setCheckConnectionForError(boolean checkConnectionForError)
true), or whether these should be ignored (false). The default is
true.
When using an HTTP transport, this property defines whether to check the HTTP response status code is in the 2xx
Successful range. Both the SOAP specification and the WS-I Basic Profile define that a Web service must return a
"200 OK" or "202 Accepted" HTTP status code for a normal response. Setting this property to false
allows this template to deal with non-conforming services.
hasError(WebServiceConnection, WebServiceMessage),
SOAP 1.1 specification,
WS-I Basic
Profilepublic void setCheckConnectionForFault(boolean checkConnectionForFault)
true), or whether we should rely on the message only (false). The default is true.
When using an 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-conforming services.
hasFault(WebServiceConnection,WebServiceMessage),
SOAP 1.1 specification,
WS-I Basic
Profilepublic ClientInterceptor[] getInterceptors()
null if nonepublic final void setInterceptors(ClientInterceptor[] interceptors)
interceptors - array of endpoint interceptors, or null if noneprotected void initDefaultStrategies()
SoapFaultMessageResolver, SaajSoapMessageFactory, and HttpUrlConnectionMessageSender.
BeanInitializationException - in case of initalization errorssetFaultMessageResolver(FaultMessageResolver),
WebServiceAccessor.setMessageFactory(WebServiceMessageFactory),
WebServiceAccessor.setMessageSender(WebServiceMessageSender)public Object marshalSendAndReceive(Object requestPayload)
WebServiceOperationsMarshaller. Returns the unmarshalled payload of the response message, if any.
This will only work with a default uri specified!
marshalSendAndReceive in interface WebServiceOperationsrequestPayload - 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)
WebServiceOperationsMarshaller. Returns the unmarshalled payload of the response message, if any.
marshalSendAndReceive in interface WebServiceOperationsuri - 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)
WebServiceOperationsMarshaller. 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 uri specified!
marshalSendAndReceive in interface WebServiceOperationsrequestPayload - 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)
WebServiceOperationsMarshaller. 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 WebServiceOperationsuri - 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)
WebServiceOperationsResult.
This will only work with a default uri specified!
sendSourceAndReceiveToResult in interface WebServiceOperationsrequestPayload - the payload of the request messageresponseResult - the result to write the response payload to
true if a response was received; false otherwise
public boolean sendSourceAndReceiveToResult(String uri,
Source requestPayload,
Result responseResult)
WebServiceOperationsResult.
sendSourceAndReceiveToResult in interface WebServiceOperationsuri - 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 otherwise
public boolean sendSourceAndReceiveToResult(Source requestPayload,
WebServiceMessageCallback requestCallback,
Result responseResult)
WebServiceOperationsResult.
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 WebServiceOperationsrequestPayload - the payload of the request messagerequestCallback - callback to change message, can be nullresponseResult - the result to write the response payload to
true if a response was received; false otherwise
public boolean sendSourceAndReceiveToResult(String uri,
Source requestPayload,
WebServiceMessageCallback requestCallback,
Result responseResult)
WebServiceOperationsResult.
The given callback allows changing of the request message after the payload has been written to it.
sendSourceAndReceiveToResult in interface WebServiceOperationsuri - the URI to send the message torequestPayload - the payload of the request messagerequestCallback - callback to change message, can be nullresponseResult - the result to write the response payload to
true if a response was received; false otherwise
public <T> T sendSourceAndReceive(Source requestPayload,
SourceExtractor<T> responseExtractor)
WebServiceOperationsSourceExtractor.
This will only work with a default uri specified!
sendSourceAndReceive in interface WebServiceOperationsrequestPayload - the payload of the request messageresponseExtractor - object that will extract results
SourceExtractor
public <T> T sendSourceAndReceive(String uri,
Source requestPayload,
SourceExtractor<T> responseExtractor)
WebServiceOperationsSourceExtractor.
sendSourceAndReceive in interface WebServiceOperationsuri - the URI to send the message torequestPayload - the payload of the request messageresponseExtractor - object that will extract results
SourceExtractor
public <T> T sendSourceAndReceive(Source requestPayload,
WebServiceMessageCallback requestCallback,
SourceExtractor<T> responseExtractor)
WebServiceOperationsSourceExtractor.
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 WebServiceOperationsrequestPayload - the payload of the request messagerequestCallback - callback to change message, can be nullresponseExtractor - object that will extract results
SourceExtractor
public <T> T sendSourceAndReceive(String uri,
Source requestPayload,
WebServiceMessageCallback requestCallback,
SourceExtractor<T> responseExtractor)
WebServiceOperationsSourceExtractor.
The given callback allows changing of the request message after the payload has been written to it.
sendSourceAndReceive in interface WebServiceOperationsuri - the URI to send the message torequestPayload - the payload of the request messagerequestCallback - callback to change message, can be nullresponseExtractor - object that will extract results
SourceExtractor
public boolean sendAndReceive(WebServiceMessageCallback requestCallback,
WebServiceMessageCallback responseCallback)
WebServiceOperations
sendAndReceive in interface WebServiceOperationsrequestCallback - 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 otherwise
public boolean sendAndReceive(String uri,
WebServiceMessageCallback requestCallback,
WebServiceMessageCallback responseCallback)
WebServiceOperations
sendAndReceive in interface WebServiceOperationsuri - 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 otherwise
public <T> T sendAndReceive(WebServiceMessageCallback requestCallback,
WebServiceMessageExtractor<T> responseExtractor)
WebServiceOperationsWebServiceMessageExtractor.
This will only work with a default uri specified!
sendAndReceive in interface WebServiceOperationsrequestCallback - the requestCallback to be used for manipulating the request messageresponseExtractor - object that will extract results
WebServiceMessageExtractor
public <T> T sendAndReceive(String uriString,
WebServiceMessageCallback requestCallback,
WebServiceMessageExtractor<T> responseExtractor)
WebServiceOperationsWebServiceMessageExtractor.
sendAndReceive in interface WebServiceOperationsuriString - the URI to send the message torequestCallback - the requestCallback to be used for manipulating the request messageresponseExtractor - object that will extract results
WebServiceMessageExtractor
protected <T> T doSendAndReceive(MessageContext messageContext,
WebServiceConnection connection,
WebServiceMessageCallback requestCallback,
WebServiceMessageExtractor<T> responseExtractor)
throws IOException
MessageContext. Sends the request message, and
received to the repsonse message. Invocates the defined interceptors as part of the process.
messageContext - the message contextconnection - the connection to userequestCallback - the requestCallback to be used for manipulating the request messageresponseExtractor - object that will extract results
WebServiceMessageExtractor
WebServiceClientException - if there is a problem sending or receiving the message
IOException - in case of I/O errors
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 FaultAwareWebServiceConnectionrequest - the response message (possibly a FaultAwareWebServiceMessage
true if the connection has an error; false otherwise
IOException - in case of I/O errors
protected Object handleError(WebServiceConnection connection,
WebServiceMessage request)
throws IOException
WebServiceTransportException.
connection - the erroneous 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 FaultAwareWebServiceConnectionresponse - 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 errors
protected Object handleFault(WebServiceConnection connection,
MessageContext messageContext)
throws IOException
fault resolver if registered, or invokes handleError(WebServiceConnection,
WebServiceMessage) otherwise.
connection - the faulty connectionmessageContext - the message context
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 | |||||||||