org.springframework.integration.http.outbound
Class HttpRequestExecutingMessageHandler

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.handler.AbstractMessageHandler
          extended by org.springframework.integration.handler.AbstractReplyProducingMessageHandler
              extended by org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler
All Implemented Interfaces:
BeanFactoryAware, BeanNameAware, InitializingBean, Ordered, NamedComponent, Orderable, MessageHandler, MessageProducer, TrackableComponent

public class HttpRequestExecutingMessageHandler
extends AbstractReplyProducingMessageHandler

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

Field Summary
 
Fields inherited from class org.springframework.integration.handler.AbstractMessageHandler
logger
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
HttpRequestExecutingMessageHandler(java.lang.String uri)
          Create a handler that will send requests to the provided URI.
HttpRequestExecutingMessageHandler(java.lang.String uri, 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.
 
Method Summary
protected  java.lang.Object handleRequestMessage(Message<?> requestMessage)
          Subclasses must implement this method to handle the request Message.
 void onInit()
          Subclasses may implement this for initialization logic.
 void setCharset(java.lang.String charset)
          Specify the charset name to use for converting String-typed payloads to bytes.
 void setErrorHandler(ResponseErrorHandler errorHandler)
          Set the ResponseErrorHandler for the underlying RestTemplate.
 void setExpectedResponseType(java.lang.Class<?> expectedResponseType)
          Specify the expected response type for the REST request.
 void setExpectReply(boolean expectReply)
          Specify whether a reply Message is expected.
 void setExtractPayload(boolean extractPayload)
          Specify whether the outbound message's payload should be extracted when preparing the request body.
 void setHeaderMapper(HeaderMapper<HttpHeaders> headerMapper)
          Set the HeaderMapper to use when mapping between HTTP headers and MessageHeaders.
 void setHttpMethod(HttpMethod httpMethod)
          Specify the HttpMethod for requests.
 void setMessageConverters(java.util.List<HttpMessageConverter<?>> messageConverters)
          Set a list of HttpMessageConverters to be used by the underlying RestTemplate.
 void setRequestFactory(ClientHttpRequestFactory requestFactory)
          Set the ClientHttpRequestFactory for the underlying RestTemplate.
 void setUriVariableExpressions(java.util.Map<java.lang.String,java.lang.String> uriVariableExpressions)
          Set the Map of URI variable expressions to evaluate against the outbound message when replacing the variable placeholders in a URI template.
 
Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
getMessagingTemplate, handleMessageInternal, setChannelResolver, setOutputChannel, setRequiresReply, setSendTimeout, shouldCopyRequestHeaders
 
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
getComponentType, getOrder, handleMessage, setOrder, setShouldTrack
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getConversionService, getTaskScheduler, setBeanFactory, setBeanName, setComponentName, setConversionService, setTaskScheduler, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.integration.context.NamedComponent
getComponentName
 

Constructor Detail

HttpRequestExecutingMessageHandler

public HttpRequestExecutingMessageHandler(java.net.URI uri)
Create a handler that will send requests to the provided URI.


HttpRequestExecutingMessageHandler

public HttpRequestExecutingMessageHandler(java.lang.String uri)
Create a handler that will send requests to the provided URI.


HttpRequestExecutingMessageHandler

public HttpRequestExecutingMessageHandler(java.lang.String uri,
                                          RestTemplate restTemplate)
Create a handler that will send requests to the provided URI using a provided RestTemplate

Parameters:
uri -
restTemplate -
Method Detail

setHttpMethod

public void setHttpMethod(HttpMethod httpMethod)
Specify the HttpMethod for requests. The default method will be POST.


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 will be serialized. The default value is true.


setCharset

public void setCharset(java.lang.String charset)
Specify the charset name to use for converting String-typed payloads to bytes. The default is 'UTF-8'.


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.


setExpectedResponseType

public void setExpectedResponseType(java.lang.Class<?> expectedResponseType)
Specify the expected response type for the REST request. If this is null (the default), only the status code will be returned as the reply Message payload. To take advantage of the HttpMessageConverters registered on this adapter, provide a different type).


setErrorHandler

public void setErrorHandler(ResponseErrorHandler errorHandler)
Set the ResponseErrorHandler for the underlying RestTemplate.

See Also:
RestTemplate.setErrorHandler(ResponseErrorHandler)

setMessageConverters

public void setMessageConverters(java.util.List<HttpMessageConverter<?>> messageConverters)
Set a list of HttpMessageConverters to be used by the underlying RestTemplate. Converters configured via this method will override the default converters.

See Also:
RestTemplate.setMessageConverters(java.util.List)

setHeaderMapper

public void setHeaderMapper(HeaderMapper<HttpHeaders> headerMapper)
Set the HeaderMapper to use when mapping between HTTP headers and MessageHeaders.


setRequestFactory

public void setRequestFactory(ClientHttpRequestFactory requestFactory)
Set the ClientHttpRequestFactory for the underlying RestTemplate.

See Also:
HttpAccessor.setRequestFactory(ClientHttpRequestFactory)

setUriVariableExpressions

public void setUriVariableExpressions(java.util.Map<java.lang.String,java.lang.String> uriVariableExpressions)
Set the Map of URI variable expressions to evaluate against the outbound message when replacing the variable placeholders in a URI template.


onInit

public void onInit()
Description copied from class: IntegrationObjectSupport
Subclasses may implement this for initialization logic.

Overrides:
onInit in class AbstractReplyProducingMessageHandler

handleRequestMessage

protected java.lang.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