public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMessageHandler
MessageHandler
implementation that executes HTTP requests by delegating
to a RestTemplate
instance. If the 'expectReply' flag is set to true (the default)
then a reply Message will be generated from the HTTP response. If that response contains
a body, it will be used as the reply Message's payload. Otherwise the reply Message's
payload will contain the response status as an instance of the HttpStatus
enum.
When there is a response body, the HttpStatus
enum instance will instead be
copied to the MessageHeaders of the reply. In both cases, the response headers will
be mapped to the reply Message's headers by this handler's HeaderMapper
instance.AbstractReplyProducingMessageHandler.RequestHandler
logger
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
HttpRequestExecutingMessageHandler(Expression uriExpression)
Create a handler that will send requests to the provided URI Expression.
|
HttpRequestExecutingMessageHandler(Expression uriExpression,
RestTemplate restTemplate)
Create a handler that will send requests to the provided URI using a provided RestTemplate
|
HttpRequestExecutingMessageHandler(String uri)
Create a handler that will send requests to the provided URI.
|
HttpRequestExecutingMessageHandler(String uri,
RestTemplate restTemplate)
Create a handler that will send requests to the provided URI using a provided RestTemplate
|
HttpRequestExecutingMessageHandler(URI uri)
Create a handler that will send requests to the provided URI.
|
Modifier and Type | Method and Description |
---|---|
protected void |
doInit() |
String |
getComponentType()
Subclasses may implement this method to provide component type information.
|
protected Object |
handleRequestMessage(Message<?> requestMessage)
Subclasses must implement this method to handle the request Message.
|
protected HttpHeaders |
mapHeaders(Message<?> message) |
void |
setCharset(String charset)
Specify the charset name to use for converting String-typed payloads to
bytes.
|
void |
setEncodeUri(boolean encodeUri)
Specify whether the real URI should be encoded after
uriVariables
expanding and before send request via RestTemplate . |
void |
setErrorHandler(ResponseErrorHandler errorHandler)
Set the
ResponseErrorHandler for the underlying RestTemplate . |
void |
setExpectedResponseType(Class<?> expectedResponseType)
Specify the expected response type for the REST request
otherwise the default response type is
ResponseEntity and will
be returned as a payload of the reply Message. |
void |
setExpectedResponseTypeExpression(Expression expectedResponseTypeExpression)
Specify the
Expression to determine the type for the expected response
The returned value of the expression could be an instance of Class or
String representing a fully qualified class name |
void |
setExpectReply(boolean expectReply)
Specify whether a reply Message is expected.
|
void |
setExtractPayload(boolean extractPayload)
Specify whether the outbound message's payload should be extracted
when preparing the request body.
|
void |
setHeaderMapper(HeaderMapper<HttpHeaders> headerMapper) |
void |
setHttpMethod(HttpMethod httpMethod)
Specify the
HttpMethod for requests. |
void |
setHttpMethodExpression(Expression httpMethodExpression)
Specify the SpEL
Expression to determine HttpMethod dynamically |
void |
setMessageConverters(List<HttpMessageConverter<?>> messageConverters)
Set a list of
HttpMessageConverter s to be used by the underlying RestTemplate . |
void |
setRequestFactory(ClientHttpRequestFactory requestFactory)
Set the
ClientHttpRequestFactory for the underlying RestTemplate . |
void |
setTransferCookies(boolean transferCookies)
Set to true if you wish 'Set-Cookie' headers in responses to be
transferred as 'Cookie' headers in subsequent interactions for
a message.
|
void |
setUriVariableExpressions(Map<String,Expression> uriVariableExpressions)
Set the Map of URI variable expressions to evaluate against the outbound message
when replacing the variable placeholders in a URI template.
|
void |
setUriVariablesExpression(Expression uriVariablesExpression)
Set the
Expression to evaluate against the outbound message; the expression
must evaluate to a Map of URI variable expressions to evaluate against the outbound message
when replacing the variable placeholders in a URI template. |
doInvokeAdvisedRequestHandler, getMessagingTemplate, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setChannelResolver, setOutputChannel, setOutputChannelName, setRequiresReply, setSendTimeout, shouldCopyRequestHeaders
getOrder, handleMessage, setOrder, setShouldTrack
afterPropertiesSet, getApplicationContextId, getBeanFactory, getComponentName, getConversionService, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, setApplicationContext, setBeanFactory, setBeanName, setComponentName, setConversionService, setMessageBuilderFactory, setTaskScheduler, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getComponentName
public HttpRequestExecutingMessageHandler(URI uri)
uri
- The URI.public HttpRequestExecutingMessageHandler(String uri)
uri
- The URI.public HttpRequestExecutingMessageHandler(Expression uriExpression)
uriExpression
- The URI expression.public HttpRequestExecutingMessageHandler(String uri, RestTemplate restTemplate)
uri
- The URI.restTemplate
- The rest template.public HttpRequestExecutingMessageHandler(Expression uriExpression, RestTemplate restTemplate)
uriExpression
- A SpEL Expression that can be resolved against the message object and
BeanFactory
.restTemplate
- The rest template.public void setEncodeUri(boolean encodeUri)
uriVariables
expanding and before send request via RestTemplate
. The default value is true
.encodeUri
- true if the URI should be encoded.UriComponentsBuilder
public void setHttpMethodExpression(Expression httpMethodExpression)
Expression
to determine HttpMethod
dynamicallyhttpMethodExpression
- The method expression.public void setHttpMethod(HttpMethod httpMethod)
HttpMethod
for requests. The default method will be POST.httpMethod
- The method.public void setExtractPayload(boolean extractPayload)
true
.extractPayload
- true if the payload should be extracted.public void setCharset(String charset)
charset
- The charset.public void setExpectReply(boolean expectReply)
expectReply
- true if a reply is expected.public void setExpectedResponseType(Class<?> expectedResponseType)
ResponseEntity
and will
be returned as a payload of the reply Message.
To take advantage of the HttpMessageConverters
registered on this adapter, provide a different type).expectedResponseType
- The expected type.
Also see setExpectedResponseTypeExpression(Expression)
public void setExpectedResponseTypeExpression(Expression expectedResponseTypeExpression)
Expression
to determine the type for the expected response
The returned value of the expression could be an instance of Class
or
String
representing a fully qualified class nameexpectedResponseTypeExpression
- The expected response type expression.
Also see setExpectedResponseTypeExpression(Expression)
public void setErrorHandler(ResponseErrorHandler errorHandler)
ResponseErrorHandler
for the underlying RestTemplate
.errorHandler
- The error handler.RestTemplate.setErrorHandler(ResponseErrorHandler)
public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters)
HttpMessageConverter
s to be used by the underlying RestTemplate
.
Converters configured via this method will override the default converters.messageConverters
- The message converters.RestTemplate.setMessageConverters(java.util.List)
public void setHeaderMapper(HeaderMapper<HttpHeaders> headerMapper)
headerMapper
- The header mapper.
Set the HeaderMapper
to use when mapping between HTTP headers and MessageHeaders.public void setRequestFactory(ClientHttpRequestFactory requestFactory)
ClientHttpRequestFactory
for the underlying RestTemplate
.requestFactory
- The request factory.HttpAccessor.setRequestFactory(ClientHttpRequestFactory)
public void setUriVariableExpressions(Map<String,Expression> uriVariableExpressions)
uriVariableExpressions
- The URI variable expressions.public void setUriVariablesExpression(Expression uriVariablesExpression)
Expression
to evaluate against the outbound message; the expression
must evaluate to a Map of URI variable expressions to evaluate against the outbound message
when replacing the variable placeholders in a URI template.uriVariablesExpression
- The URI variables expression.public void setTransferCookies(boolean transferCookies)
transferCookies
- the transferCookies to set.public String getComponentType()
IntegrationObjectSupport
getComponentType
in interface NamedComponent
getComponentType
in class AbstractMessageHandler
protected void doInit()
doInit
in class AbstractReplyProducingMessageHandler
protected Object handleRequestMessage(Message<?> requestMessage)
AbstractReplyProducingMessageHandler
handleRequestMessage
in class AbstractReplyProducingMessageHandler
requestMessage
- The request message.null
.protected HttpHeaders mapHeaders(Message<?> message)