Class HttpRequestExecutingMessageHandler
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.handler.AbstractMessageProducingHandler
org.springframework.integration.handler.AbstractReplyProducingMessageHandler
org.springframework.integration.http.outbound.AbstractHttpRequestExecutingMessageHandler
org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler
- All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>, Aware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Ordered, ComponentSourceAware, ExpressionCapable, Orderable, MessageProducer, HeaderPropagationAware, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>
A
MessageHandler
implementation that executes HTTP requests by delegating
to a RestClient or 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.- Since:
- 2.0
- Author:
- Mark Fisher, Oleg Zhurakousky, Gary Russell, Gunnar Hillert, Artem Bilan, Wallace Wadge, Shiliang Li, Arun Sethumadhavan, Glenn Renfro
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractReplyProducingMessageHandler
AbstractReplyProducingMessageHandler.RequestHandlerNested classes/interfaces inherited from interface IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
Fields inherited from class AbstractHttpRequestExecutingMessageHandler
uriFactoryFields inherited from class AbstractMessageProducingHandler
messagingTemplateFields inherited from class IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionCreate a handler that will send requests to the provided URI.HttpRequestExecutingMessageHandler(String uri, @Nullable RestClient restClient) Create a handler that will send requests to the provided URI using a provided RestClient.HttpRequestExecutingMessageHandler(String uri, @Nullable RestTemplate restTemplate) Deprecated, for removal: This API element is subject to removal in a future version.Create a handler that will send requests to the provided URI.HttpRequestExecutingMessageHandler(Expression uriExpression) Create a handler that will send requests to the provided URI Expression.HttpRequestExecutingMessageHandler(Expression uriExpression, @Nullable RestClient restClient) Create a handler that will send requests to the provided URI using a provided RestClient.HttpRequestExecutingMessageHandler(Expression uriExpression, @Nullable RestTemplate restTemplate) Deprecated, for removal: This API element is subject to removal in a future version.Since 7.1 in favor ofRestClient-based configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoiddefaultStatusHandler(Predicate<HttpStatusCode> predicate, RestClient.ResponseSpec.ErrorHandler errorHandler) protected voiddoInit()protected @Nullable Objectexchange(Object uri, HttpMethod httpMethod, HttpEntity<?> httpRequest, Object expectedResponseType, Message<?> requestMessage, Map<String, ?> uriVariables) voidsetDefaultStatusHandler(RestClient.ResponseSpec.ErrorHandler errorHandler) Set theRestClient.ResponseSpec.ErrorHandlerfor the underlyingRestClient, applied to anyerrorresponse status.voidsetEncodingMode(DefaultUriBuilderFactory.EncodingMode encodingMode) Set the encoding mode to use.voidsetErrorHandler(ResponseErrorHandler errorHandler) Deprecated, for removal: This API element is subject to removal in a future version.voidsetMessageConverters(List<HttpMessageConverter<?>> messageConverters) Set a list ofHttpMessageConverters to be used by the underlyingRestClient.voidsetRequestFactory(ClientHttpRequestFactory requestFactory) Set theClientHttpRequestFactoryfor the underlyingRestClient.Methods inherited from class AbstractHttpRequestExecutingMessageHandler
evaluateTypeFromExpression, getIntegrationPatternType, getReply, handleRequestMessage, isExpectReply, mapHeaders, setCharset, setExpectedResponseType, setExpectedResponseTypeExpression, setExpectReply, setExtractPayload, setExtractResponseBody, setHeaderMapper, setHttpMethod, setHttpMethodExpression, setTransferCookies, setTrustedSpel, setUriVariableExpressions, setUriVariablesExpressionMethods inherited from class AbstractReplyProducingMessageHandler
doInvokeAdvisedRequestHandler, getBeanClassLoader, getRequiresReply, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReplyMethods inherited from class AbstractMessageProducingHandler
addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, messageBuilderForReply, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, setSendTimeout, setupMessageProcessor, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeadersMethods inherited from class AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConventionMethods inherited from class MessageHandlerSupport
buildSendTimer, destroy, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackMethods inherited from class IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscriber
currentContextMethods inherited from interface IntegrationManagement
getThisAsMethods inherited from interface NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
HttpRequestExecutingMessageHandler
Create a handler that will send requests to the provided URI.- Parameters:
uri- The URI.
-
HttpRequestExecutingMessageHandler
Create a handler that will send requests to the provided URI.- Parameters:
uri- The URI.
-
HttpRequestExecutingMessageHandler
Create a handler that will send requests to the provided URI Expression.- Parameters:
uriExpression- The URI expression.
-
HttpRequestExecutingMessageHandler
@Deprecated(since="7.1", forRemoval=true) public HttpRequestExecutingMessageHandler(String uri, @Nullable RestTemplate restTemplate) Deprecated, for removal: This API element is subject to removal in a future version.Since 7.1 in favor ofRestClient-based configuration.Create a handler that will send requests to the provided URI using a provided RestTemplate.- Parameters:
uri- The URI.restTemplate- The rest template.
-
HttpRequestExecutingMessageHandler
@Deprecated(since="7.1", forRemoval=true) public HttpRequestExecutingMessageHandler(Expression uriExpression, @Nullable RestTemplate restTemplate) Deprecated, for removal: This API element is subject to removal in a future version.Since 7.1 in favor ofRestClient-based configuration.Create a handler that will send requests to the provided URI using a provided RestTemplate.- Parameters:
uriExpression- A SpEL Expression that can be resolved against the message object andBeanFactory.restTemplate- The rest template.
-
HttpRequestExecutingMessageHandler
Create a handler that will send requests to the provided URI using a provided RestClient.- Parameters:
uri- The URI.restClient- The rest client.- Since:
- 7.1
-
HttpRequestExecutingMessageHandler
public HttpRequestExecutingMessageHandler(Expression uriExpression, @Nullable RestClient restClient) Create a handler that will send requests to the provided URI using a provided RestClient.- Parameters:
uriExpression- A SpEL Expression that can be resolved against the message object andBeanFactory.restClient- The rest client.- Since:
- 7.1
-
-
Method Details
-
getComponentType
- Specified by:
getComponentTypein interfaceNamedComponent- Overrides:
getComponentTypein classMessageHandlerSupport
-
doInit
protected void doInit()- Overrides:
doInitin classAbstractHttpRequestExecutingMessageHandler
-
setErrorHandler
@Deprecated(since="7.2", forRemoval=true) public void setErrorHandler(ResponseErrorHandler errorHandler) Deprecated, for removal: This API element is subject to removal in a future version.Set theResponseErrorHandlerfor the underlyingRestTemplate.- Parameters:
errorHandler- The error handler.- See Also:
-
setDefaultStatusHandler
Set theRestClient.ResponseSpec.ErrorHandlerfor the underlyingRestClient, applied to anyerrorresponse status.- Parameters:
errorHandler- The error handler.- Since:
- 7.2
-
defaultStatusHandler
public void defaultStatusHandler(Predicate<HttpStatusCode> predicate, RestClient.ResponseSpec.ErrorHandler errorHandler) - Parameters:
predicate- the predicate for the response status to match for this error handler.errorHandler- The error handler.- Since:
- 7.2
-
setMessageConverters
Set a list ofHttpMessageConverters to be used by the underlyingRestClient. Converters configured via this method will override the default converters.- Parameters:
messageConverters- The message converters.- See Also:
-
setRequestFactory
Set theClientHttpRequestFactoryfor the underlyingRestClient.- Parameters:
requestFactory- The request factory.- See Also:
-
setEncodingMode
Description copied from class:AbstractHttpRequestExecutingMessageHandlerSet the encoding mode to use. By default, this is set toDefaultUriBuilderFactory.EncodingMode.TEMPLATE_AND_VALUES. For more complicated scenarios consider configuring anUriTemplateHandleron an externally providedRestTemplate.- Overrides:
setEncodingModein classAbstractHttpRequestExecutingMessageHandler- Parameters:
encodingMode- the mode to use for uri encoding
-
exchange
protected @Nullable Object exchange(Object uri, HttpMethod httpMethod, HttpEntity<?> httpRequest, Object expectedResponseType, Message<?> requestMessage, Map<String, ?> uriVariables) - Specified by:
exchangein classAbstractHttpRequestExecutingMessageHandler
-
RestClient-based configuration.