public class HttpRequestExecutingMessageHandler extends AbstractHttpRequestExecutingMessageHandler
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.uriFactory
messagingTemplate
EXPRESSION_PARSER, 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 java.lang.Object |
exchange(java.lang.Object uri,
org.springframework.http.HttpMethod httpMethod,
org.springframework.http.HttpEntity<?> httpRequest,
java.lang.Object expectedResponseType,
org.springframework.messaging.Message<?> requestMessage,
java.util.Map<java.lang.String,?> uriVariables) |
java.lang.String |
getComponentType() |
void |
setEncodingMode(org.springframework.web.util.DefaultUriBuilderFactory.EncodingMode encodingMode)
Set the encoding mode to use.
|
void |
setErrorHandler(org.springframework.web.client.ResponseErrorHandler errorHandler)
Set the
ResponseErrorHandler for the underlying RestTemplate . |
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 . |
doInit, evaluateTypeFromExpression, getIntegrationPatternType, getReply, handleRequestMessage, isExpectReply, mapHeaders, setCharset, setEncodeUri, setExpectedResponseType, setExpectedResponseTypeExpression, setExpectReply, setExtractPayload, setHeaderMapper, setHttpMethod, setHttpMethodExpression, setTransferCookies, setTrustedSpel, setUriVariableExpressions, setUriVariablesExpression
doInvokeAdvisedRequestHandler, getBeanClassLoader, getRequiresReply, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReply
addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, messageBuilderForReply, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, setSendTimeout, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeaders
handleMessage, onComplete, onError, onNext, onSubscribe
buildSendTimer, destroy, getManagedName, getManagedType, getMetricsCaptor, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public HttpRequestExecutingMessageHandler(java.net.URI uri)
uri
- The URI.public HttpRequestExecutingMessageHandler(java.lang.String uri)
uri
- The URI.public HttpRequestExecutingMessageHandler(org.springframework.expression.Expression uriExpression)
uriExpression
- The URI expression.public HttpRequestExecutingMessageHandler(java.lang.String uri, org.springframework.web.client.RestTemplate restTemplate)
uri
- The URI.restTemplate
- The rest template.public HttpRequestExecutingMessageHandler(org.springframework.expression.Expression uriExpression, @Nullable org.springframework.web.client.RestTemplate restTemplate)
uriExpression
- A SpEL Expression that can be resolved against the message object and
BeanFactory
.restTemplate
- The rest template.public java.lang.String getComponentType()
getComponentType
in interface org.springframework.integration.support.context.NamedComponent
getComponentType
in class org.springframework.integration.handler.MessageHandlerSupport
public void setErrorHandler(org.springframework.web.client.ResponseErrorHandler errorHandler)
ResponseErrorHandler
for the underlying RestTemplate
.errorHandler
- The error handler.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.messageConverters
- The message converters.RestTemplate.setMessageConverters(java.util.List)
public void setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
ClientHttpRequestFactory
for the underlying RestTemplate
.requestFactory
- The request factory.InterceptingHttpAccessor.setRequestFactory(ClientHttpRequestFactory)
public void setEncodingMode(org.springframework.web.util.DefaultUriBuilderFactory.EncodingMode encodingMode)
AbstractHttpRequestExecutingMessageHandler
DefaultUriBuilderFactory.EncodingMode#TEMPLATE_AND_VALUES
.
For more complicated scenarios consider to configure an UriTemplateHandler
on an externally provided RestTemplate
.setEncodingMode
in class AbstractHttpRequestExecutingMessageHandler
encodingMode
- the mode to use for uri encoding@Nullable protected java.lang.Object exchange(java.lang.Object uri, org.springframework.http.HttpMethod httpMethod, org.springframework.http.HttpEntity<?> httpRequest, java.lang.Object expectedResponseType, org.springframework.messaging.Message<?> requestMessage, java.util.Map<java.lang.String,?> uriVariables)
exchange
in class AbstractHttpRequestExecutingMessageHandler