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.AbstractReplyProducingMessageHandler.RequestHandler
IntegrationManagement.ManagementOverrides
uriFactory
messagingTemplate
EXPRESSION_PARSER, logger
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
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 Object |
exchange(Object uri,
HttpMethod httpMethod,
HttpEntity<?> httpRequest,
Object expectedResponseType,
Message<?> requestMessage,
Map<String,?> uriVariables) |
String |
getComponentType()
Subclasses may implement this method to provide component type information.
|
void |
setEncodingMode(DefaultUriBuilderFactory.EncodingMode encodingMode)
Set the encoding mode to use.
|
void |
setErrorHandler(ResponseErrorHandler errorHandler)
Set the
ResponseErrorHandler for the underlying RestTemplate . |
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 . |
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
getThisAs
getBeanName, 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, @Nullable RestTemplate restTemplate)
uriExpression
- A SpEL Expression that can be resolved against the message object and
BeanFactory
.restTemplate
- The rest template.public String getComponentType()
IntegrationObjectSupport
getComponentType
in interface NamedComponent
getComponentType
in class MessageHandlerSupport
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 setRequestFactory(ClientHttpRequestFactory requestFactory)
ClientHttpRequestFactory
for the underlying RestTemplate
.requestFactory
- The request factory.InterceptingHttpAccessor.setRequestFactory(ClientHttpRequestFactory)
public void setEncodingMode(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 Object exchange(Object uri, HttpMethod httpMethod, HttpEntity<?> httpRequest, Object expectedResponseType, Message<?> requestMessage, Map<String,?> uriVariables)
exchange
in class AbstractHttpRequestExecutingMessageHandler