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<org.springframework.messaging.Message<?>>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.core.Ordered, org.springframework.integration.context.ComponentSourceAware, org.springframework.integration.context.ExpressionCapable, org.springframework.integration.context.Orderable, org.springframework.integration.core.MessageProducer, org.springframework.integration.handler.HeaderPropagationAware, org.springframework.integration.IntegrationPattern, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.IntegrationManagement, org.springframework.integration.support.management.TrackableComponent, org.springframework.messaging.MessageHandler, reactor.core.CoreSubscriber<org.springframework.messaging.Message<?>>

public class HttpRequestExecutingMessageHandler extends AbstractHttpRequestExecutingMessageHandler
A 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.
Since:
2.0
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler

    org.springframework.integration.handler.AbstractReplyProducingMessageHandler.RequestHandler

    Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement

    org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides
  • Field Summary

    Fields inherited from class org.springframework.integration.http.outbound.AbstractHttpRequestExecutingMessageHandler

    uriFactory

    Fields inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler

    messagingTemplate

    Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport

    EXPRESSION_PARSER, logger

    Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement

    METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a handler that will send requests to the provided URI.
    HttpRequestExecutingMessageHandler(String uri, org.springframework.web.client.RestTemplate restTemplate)
    Create a handler that will send requests to the provided URI using a provided RestTemplate.
    Create a handler that will send requests to the provided URI.
    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)
    4 Create a handler that will send requests to the provided URI using a provided RestTemplate.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Object
    exchange(Object uri, org.springframework.http.HttpMethod httpMethod, org.springframework.http.HttpEntity<?> httpRequest, Object expectedResponseType, org.springframework.messaging.Message<?> requestMessage, Map<String,?> uriVariables)
     
     
    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(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
    Set a list of HttpMessageConverters to be used by the underlying RestTemplate.
    void
    setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
    Set the ClientHttpRequestFactory for the underlying RestTemplate.

    Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler

    doInvokeAdvisedRequestHandler, getBeanClassLoader, getRequiresReply, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReply

    Methods inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler

    addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, messageBuilderForReply, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, setSendTimeout, setupMessageProcessor, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeaders

    Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler

    handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConvention

    Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport

    buildSendTimer, destroy, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack

    Methods inherited from class org.springframework.integration.context.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, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface reactor.core.CoreSubscriber

    currentContext

    Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement

    getThisAs

    Methods inherited from interface org.springframework.integration.support.context.NamedComponent

    getBeanName, getComponentName
  • Constructor Details

    • HttpRequestExecutingMessageHandler

      public HttpRequestExecutingMessageHandler(URI uri)
      Create a handler that will send requests to the provided URI.
      Parameters:
      uri - The URI.
    • HttpRequestExecutingMessageHandler

      public HttpRequestExecutingMessageHandler(String uri)
      Create a handler that will send requests to the provided URI.
      Parameters:
      uri - The URI.
    • HttpRequestExecutingMessageHandler

      public HttpRequestExecutingMessageHandler(org.springframework.expression.Expression uriExpression)
      Create a handler that will send requests to the provided URI Expression.
      Parameters:
      uriExpression - The URI expression.
    • HttpRequestExecutingMessageHandler

      public HttpRequestExecutingMessageHandler(String uri, @Nullable org.springframework.web.client.RestTemplate restTemplate)
      Create a handler that will send requests to the provided URI using a provided RestTemplate.
      Parameters:
      uri - The URI.
      restTemplate - The rest template.
    • HttpRequestExecutingMessageHandler

      public HttpRequestExecutingMessageHandler(org.springframework.expression.Expression uriExpression, @Nullable org.springframework.web.client.RestTemplate restTemplate)
      4 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 and BeanFactory.
      restTemplate - The rest template.
  • Method Details

    • getComponentType

      public String getComponentType()
      Specified by:
      getComponentType in interface org.springframework.integration.support.context.NamedComponent
      Overrides:
      getComponentType in class org.springframework.integration.handler.MessageHandlerSupport
    • setErrorHandler

      public void setErrorHandler(org.springframework.web.client.ResponseErrorHandler errorHandler)
      Set the ResponseErrorHandler for the underlying RestTemplate.
      Parameters:
      errorHandler - The error handler.
      See Also:
      • RestTemplate.setErrorHandler(ResponseErrorHandler)
    • setMessageConverters

      public void setMessageConverters(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
      Set a list of HttpMessageConverters to be used by the underlying RestTemplate. Converters configured via this method will override the default converters.
      Parameters:
      messageConverters - The message converters.
      See Also:
      • RestTemplate.setMessageConverters(java.util.List)
    • setRequestFactory

      public void setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
      Set the ClientHttpRequestFactory for the underlying RestTemplate.
      Parameters:
      requestFactory - The request factory.
      See Also:
      • InterceptingHttpAccessor.setRequestFactory(ClientHttpRequestFactory)
    • setEncodingMode

      public void setEncodingMode(org.springframework.web.util.DefaultUriBuilderFactory.EncodingMode encodingMode)
      Description copied from class: AbstractHttpRequestExecutingMessageHandler
      Set the encoding mode to use. By default, this is set to DefaultUriBuilderFactory.EncodingMode.TEMPLATE_AND_VALUES. For more complicated scenarios consider configuring an UriTemplateHandler on an externally provided RestTemplate.
      Overrides:
      setEncodingMode in class AbstractHttpRequestExecutingMessageHandler
      Parameters:
      encodingMode - the mode to use for uri encoding
    • exchange

      @Nullable protected Object exchange(Object uri, org.springframework.http.HttpMethod httpMethod, org.springframework.http.HttpEntity<?> httpRequest, @Nullable Object expectedResponseType, org.springframework.messaging.Message<?> requestMessage, @Nullable Map<String,?> uriVariables)
      Specified by:
      exchange in class AbstractHttpRequestExecutingMessageHandler