Class AbstractHttpRequestExecutingMessageHandler

All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>, Aware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Ordered, ExpressionCapable, Orderable, MessageProducer, HeaderPropagationAware, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>
Direct Known Subclasses:
HttpRequestExecutingMessageHandler, WebFluxRequestExecutingMessageHandler

public abstract class AbstractHttpRequestExecutingMessageHandler extends AbstractReplyProducingMessageHandler
Base class for http outbound adapter/gateway.
Since:
5.0
Author:
Mark Fisher, Oleg Zhurakousky, Gary Russell, Gunnar Hillert, Artem Bilan, Wallace Wadge, Shiliang Li, Florian Schöffl, Christian Tzolov
  • Field Details

  • Constructor Details

    • AbstractHttpRequestExecutingMessageHandler

      public AbstractHttpRequestExecutingMessageHandler(Expression uriExpression)
  • Method Details

    • setEncodingMode

      public void setEncodingMode(DefaultUriBuilderFactory.EncodingMode encodingMode)
      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.
      Parameters:
      encodingMode - the mode to use for uri encoding
      Since:
      5.3
    • setHttpMethodExpression

      public void setHttpMethodExpression(Expression httpMethodExpression)
      Specify the SpEL Expression to determine HttpMethod at runtime.
      Parameters:
      httpMethodExpression - The method expression.
    • setHttpMethod

      public void setHttpMethod(HttpMethod httpMethod)
      Specify the HttpMethod for requests. The default method is POST.
      Parameters:
      httpMethod - The method.
    • setExtractPayload

      public void setExtractPayload(boolean extractPayload)
      Specify whether the outbound message's payload should be extracted when preparing the request body. Otherwise, the Message instance itself is serialized. The default value is true.
      Parameters:
      extractPayload - true if the payload should be extracted.
    • setCharset

      public void setCharset(String charset)
      Specify the charset name to use for converting String-typed payloads to bytes. The default is UTF-8.
      Parameters:
      charset - The charset.
    • isExpectReply

      public boolean isExpectReply()
      Returns:
      whether a reply Message is expected.
      See Also:
    • setExpectReply

      public void setExpectReply(boolean expectReply)
      Specify whether a reply Message is expected. If not, this handler will simply return null for a successful response or throw an Exception for a non-successful response. The default is true.
      Parameters:
      expectReply - true if a reply is expected.
    • setExpectedResponseType

      public void setExpectedResponseType(Class<?> expectedResponseType)
      Specify the expected response type for the REST request. Otherwise, it is null and an empty ResponseEntity is returned from HTTP client. To take advantage of the HttpMessageConverters registered on this adapter, provide a different type).
      Parameters:
      expectedResponseType - The expected type. Also see setExpectedResponseTypeExpression(Expression)
    • setExpectedResponseTypeExpression

      public void setExpectedResponseTypeExpression(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.
      Parameters:
      expectedResponseTypeExpression - The expected response type expression. Also see setExpectedResponseType(java.lang.Class<?>)
    • setHeaderMapper

      public void setHeaderMapper(HeaderMapper<HttpHeaders> headerMapper)
      Set the HeaderMapper to use when mapping between HTTP headers and MessageHeaders.
      Parameters:
      headerMapper - The header mapper.
    • setUriVariableExpressions

      public void setUriVariableExpressions(Map<String,Expression> uriVariableExpressions)
      Set the Map of URI variable expressions to evaluate against the outbound message when replacing the variable placeholders in a URI template.
      Parameters:
      uriVariableExpressions - The URI variable expressions.
    • setUriVariablesExpression

      public void setUriVariablesExpression(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.
      Parameters:
      uriVariablesExpression - The URI variables expression.
    • setTransferCookies

      public 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. Defaults to false.
      Parameters:
      transferCookies - the transferCookies to set.
    • setTrustedSpel

      public void setTrustedSpel(boolean trustedSpel)
      Set to true if you trust the source of SpEL expressions used to evaluate URI variables. Default is false, which means a SimpleEvaluationContext is used for evaluating such expressions, which restricts the use of some SpEL capabilities.
      Parameters:
      trustedSpel - true to trust.
      Since:
      4.3.15.
    • setExtractResponseBody

      public void setExtractResponseBody(boolean extractResponseBody)
      The flag to extract a body of the ResponseEntity for reply message payload. Defaults to true.
      Parameters:
      extractResponseBody - produce a reply message with a whole ResponseEntity or just its body.
      Since:
      5.5
    • getIntegrationPatternType

      public IntegrationPatternType getIntegrationPatternType()
      Description copied from interface: IntegrationPattern
      Return a pattern type this component implements.
      Specified by:
      getIntegrationPatternType in interface IntegrationPattern
      Overrides:
      getIntegrationPatternType in class AbstractReplyProducingMessageHandler
      Returns:
      the IntegrationPatternType this component implements.
    • doInit

      protected void doInit()
      Overrides:
      doInit in class AbstractReplyProducingMessageHandler
    • handleRequestMessage

      @Nullable protected Object handleRequestMessage(Message<?> requestMessage)
      Description copied from class: AbstractReplyProducingMessageHandler
      Subclasses must implement this method to handle the request Message. The return value may be a Message, a MessageBuilder, or any plain Object. The base class will handle the final creation of a reply Message from any of those starting points. If the return value is null, the Message flow will end here.
      Specified by:
      handleRequestMessage in class AbstractReplyProducingMessageHandler
      Parameters:
      requestMessage - The request message.
      Returns:
      The result of handling the message, or null.
    • exchange

      @Nullable protected abstract Object exchange(Object uri, HttpMethod httpMethod, HttpEntity<?> httpRequest, Object expectedResponseType, Message<?> requestMessage, Map<String,?> uriVariables)
    • getReply

      protected Object getReply(ResponseEntity<?> httpResponse)
    • mapHeaders

      protected HttpHeaders mapHeaders(Message<?> message)
    • evaluateTypeFromExpression

      @Nullable protected Object evaluateTypeFromExpression(Message<?> requestMessage, @Nullable Expression expression, String property)