The synchronous request methods are similar to the synchronous send methods, except that the request methods force the message exchange pattern to be InOut (conforming to request/reply semantics). Hence, it is generally convenient to use a synchronous request method, if you expect to receive a reply from the producer endpoint.
The basic request()
method is a general-purpose method that uses
a processor to populate a default exchange and forces the message exchange
pattern to be InOut (so that the invocation obeys
request/reply semantics). The return value is the exchange that you get after it
has been processed by the producer endpoint, where the Out
message contains the reply message.
The request()
methods for sending an exchange populated by a
processor let you specify the target endpoint in one of the following ways: as
an endpoint URI, or as an Endpoint
object.
Exchange request(String endpointUri, Processor processor); Exchange request(Endpoint endpoint, Processor processor);
If you are only concerned with the contents of the message body in the request
and in the reply, you can use the requestBody()
methods to provide
the request message body as an argument and let the producer template take care
of inserting the body into a default exchange object.
The requestBody()
methods let you specify the target endpoint in
one of the following ways: as the default endpoint, as an endpoint URI, or as an
Endpoint
object. The return value is the body of the reply
message (Out message body), which can either be returned as
plain Object
or converted to a specific type, T
, using
the built-in type converters (see Built-In Type Converters).
Object requestBody(Object body); <T> T requestBody(Object body, Class<T> type); Object requestBody( String endpointUri, Object body ); <T> T requestBody( String endpointUri, Object body, Class<T> type ); Object requestBody( Endpoint endpoint, Object body ); <T> T requestBody( Endpoint endpoint, Object body, Class<T> type );
You can try out the effect of setting a single header value using the
requestBodyAndHeader()
methods. You supply the message body and
header setting as arguments to requestBodyAndHeader()
and let the
producer template take care of inserting the body and exchange property into a
default exchange object.
The requestBodyAndHeader()
methods let you specify the target
endpoint in one of the following ways: as an endpoint URI, or as an
Endpoint
object. The return value is the body of the reply
message (Out message body), which can either be returned as
plain Object
or converted to a specific type, T
, using
the built-in type converters (see Built-In Type Converters).
Object requestBodyAndHeader( String endpointUri, Object body, String header, Object headerValue ); <T> T requestBodyAndHeader( String endpointUri, Object body, String header, Object headerValue, Class<T> type ); Object requestBodyAndHeader( Endpoint endpoint, Object body, String header, Object headerValue ); <T> T requestBodyAndHeader( Endpoint endpoint, Object body, String header, Object headerValue, Class<T> type );
The requestBodyAndHeaders()
methods are similar to the
requestBodyAndHeader()
methods, except that instead of
supplying just a single header setting, these methods allow you to specify a
complete hash map of header settings.
Object requestBodyAndHeaders( String endpointUri, Object body, Map<String, Object> headers ); <T> T requestBodyAndHeaders( String endpointUri, Object body, Map<String, Object> headers, Class<T> type ); Object requestBodyAndHeaders( Endpoint endpoint, Object body, Map<String, Object> headers ); <T> T requestBodyAndHeaders( Endpoint endpoint, Object body, Map<String, Object> headers, Class<T> type );