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
Constructor and Description |
---|
HttpRequestExecutingMessageHandler(org.springframework.expression.Expression uriExpression)
Create a handler that will send requests to the provided URI Expression.
|
HttpRequestExecutingMessageHandler(org.springframework.expression.Expression uriExpression,
org.springframework.web.client.RestTemplate restTemplate)
Create a handler that will send requests to the provided URI using a provided RestTemplate
|
HttpRequestExecutingMessageHandler(java.lang.String uri)
Create a handler that will send requests to the provided URI.
|
HttpRequestExecutingMessageHandler(java.lang.String uri,
org.springframework.web.client.RestTemplate restTemplate)
Create a handler that will send requests to the provided URI using a provided RestTemplate
|
HttpRequestExecutingMessageHandler(java.net.URI uri)
Create a handler that will send requests to the provided URI.
|
Modifier and Type | Method and Description |
---|---|
protected void |
doInit() |
protected java.lang.Object |
handleRequestMessage(Message<?> requestMessage)
Subclasses must implement this method to handle the request Message.
|
protected org.springframework.http.HttpHeaders |
mapHeaders(Message<?> message) |
void |
setCharset(java.lang.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(org.springframework.web.client.ResponseErrorHandler errorHandler)
Set the
ResponseErrorHandler for the underlying RestTemplate . |
void |
setExpectedResponseType(java.lang.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(org.springframework.expression.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
Also see setExpectedResponseTypeExpression(Expression) |
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<org.springframework.http.HttpHeaders> headerMapper)
Set the
HeaderMapper to use when mapping between HTTP headers and MessageHeaders. |
void |
setHttpMethod(org.springframework.http.HttpMethod httpMethod)
Specify the
HttpMethod for requests. |
void |
setHttpMethodExpression(org.springframework.expression.Expression httpMethodExpression)
Specify the SpEL
Expression to determine HttpMethod dynamically |
void |
setMessageConverters(java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
Set a list of
HttpMessageConverter s to be used by the underlying RestTemplate . |
void |
setRequestFactory(org.springframework.http.client.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(java.util.Map<java.lang.String,org.springframework.expression.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(org.springframework.expression.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, setRequiresReply, setSendTimeout, shouldCopyRequestHeaders
getComponentType, getOrder, handleMessage, setOrder, setShouldTrack
afterPropertiesSet, getApplicationContextId, getBeanFactory, getComponentName, getConversionService, getIntegrationProperties, getIntegrationProperty, getTaskScheduler, setApplicationContext, setBeanFactory, setBeanName, setComponentName, setConversionService, setTaskScheduler, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getComponentName
public HttpRequestExecutingMessageHandler(java.net.URI uri)
public HttpRequestExecutingMessageHandler(java.lang.String uri)
public HttpRequestExecutingMessageHandler(org.springframework.expression.Expression uriExpression)
public HttpRequestExecutingMessageHandler(java.lang.String uri, org.springframework.web.client.RestTemplate restTemplate)
uri
- restTemplate
- public HttpRequestExecutingMessageHandler(org.springframework.expression.Expression uriExpression, org.springframework.web.client.RestTemplate restTemplate)
uriExpression
- A SpEL Expression that can be resolved against the message object and
BeanFactory
.restTemplate
- public void setEncodeUri(boolean encodeUri)
uriVariables
expanding and before send request via RestTemplate
. The default value is true
.UriComponentsBuilder
public void setHttpMethodExpression(org.springframework.expression.Expression httpMethodExpression)
Expression
to determine HttpMethod
dynamicallyhttpMethodExpression
- public void setHttpMethod(org.springframework.http.HttpMethod httpMethod)
HttpMethod
for requests. The default method will be POST.public void setExtractPayload(boolean extractPayload)
true
.public void setCharset(java.lang.String charset)
public void setExpectReply(boolean expectReply)
public void setExpectedResponseType(java.lang.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).
Also see setExpectedResponseTypeExpression(Expression)
public void setExpectedResponseTypeExpression(org.springframework.expression.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 name
Also see setExpectedResponseTypeExpression(Expression)
public void setErrorHandler(org.springframework.web.client.ResponseErrorHandler errorHandler)
ResponseErrorHandler
for the underlying RestTemplate
.RestTemplate.setErrorHandler(ResponseErrorHandler)
public void setMessageConverters(java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
HttpMessageConverter
s to be used by the underlying RestTemplate
.
Converters configured via this method will override the default converters.RestTemplate.setMessageConverters(java.util.List)
public void setHeaderMapper(HeaderMapper<org.springframework.http.HttpHeaders> headerMapper)
HeaderMapper
to use when mapping between HTTP headers and MessageHeaders.public void setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
ClientHttpRequestFactory
for the underlying RestTemplate
.HttpAccessor.setRequestFactory(ClientHttpRequestFactory)
public void setUriVariableExpressions(java.util.Map<java.lang.String,org.springframework.expression.Expression> uriVariableExpressions)
public void setUriVariablesExpression(org.springframework.expression.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.public void setTransferCookies(boolean transferCookies)
transferCookies
- the transferCookies to set.protected void doInit()
doInit
in class AbstractReplyProducingMessageHandler
protected java.lang.Object handleRequestMessage(Message<?> requestMessage)
AbstractReplyProducingMessageHandler
handleRequestMessage
in class AbstractReplyProducingMessageHandler
protected org.springframework.http.HttpHeaders mapHeaders(Message<?> message)