Spring Integration

org.springframework.integration.http.inbound
Class HttpRequestHandlingEndpointSupport

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.endpoint.AbstractEndpoint
          extended by org.springframework.integration.gateway.MessagingGatewaySupport
              extended by org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, NamedComponent, OrderlyShutdownCapable, TrackableComponent
Direct Known Subclasses:
HttpRequestHandlingController, HttpRequestHandlingMessagingGateway

public abstract class HttpRequestHandlingEndpointSupport
extends MessagingGatewaySupport
implements OrderlyShutdownCapable

Base class for HTTP request handling endpoints.

By default GET and POST requests are accepted, but the 'supportedMethods' property may be set to include others or limit the options (e.g. POST only). A GET request will generate a payload containing its 'parameterMap' while a POST request will be converted to a Message payload according to the registered HttpMessageConverters. Several are registered by default, but the list can be explicitly set via setMessageConverters(List).

To customize the mapping of request headers to the MessageHeaders, provide a reference to a HeaderMapper implementation to the setHeaderMapper(HeaderMapper) method.

The behavior is "request/reply" by default. Pass false to the constructor to force send-only as opposed to sendAndReceive. Send-only means that as soon as the Message is created and passed to the request channel, a response will be generated. Subclasses determine how that response is generated (e.g. simple status response or rendering a View).

In a request-reply scenario, the reply Message's payload will be extracted prior to generating a response by default. To have the entire serialized Message available for the response, switch the extractReplyPayload value to false.

Since:
2.0
Author:
Mark Fisher, Oleg Zhurakousky, Gary Russell

Field Summary
 
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
logger
 
Constructor Summary
HttpRequestHandlingEndpointSupport()
           
HttpRequestHandlingEndpointSupport(boolean expectReply)
           
 
Method Summary
 int afterShutdown()
          Called after normal shutdown of schedulers, executors etc, and after the shutdown delay has elapsed, but before any forced shutdown of any remaining active scheduler/executor threads.Can optionally return the number of active messages still in process.
 int beforeShutdown()
          Called before shutdown begins.
protected  org.springframework.expression.spel.support.StandardEvaluationContext createEvaluationContext()
           
protected  Message<?> doHandleRequest(javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse)
          Handles the HTTP request by generating a Message and sending it to the request channel.
protected  void doStart()
          Subclasses must implement this method with the start behavior.
 java.lang.String getComponentType()
          Subclasses may implement this method to provide component type information.
protected  java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> getMessageConverters()
           
protected  boolean isExpectReply()
           
protected  boolean isShuttingDown()
           
protected  void onInit()
          Locates the MultipartResolver bean based on the default name defined by the DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME constant if available.
 void setExtractReplyPayload(boolean extractReplyPayload)
          Specify whether only the reply Message's payload should be passed in the response.
 void setHeaderExpressions(java.util.Map<java.lang.String,org.springframework.expression.Expression> headerExpressions)
          Specifies a Map of SpEL expressions to evaluate in order to generate the Message headers.
 void setHeaderMapper(HeaderMapper<org.springframework.http.HttpHeaders> headerMapper)
          Set the HeaderMapper to use when mapping between HTTP headers and MessageHeaders.
 void setMessageConverters(java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
          Set the message body converters to use.
 void setMultipartResolver(org.springframework.web.multipart.MultipartResolver multipartResolver)
          Specify the MultipartResolver to use when checking requests.
 void setPath(java.lang.String path)
          Set the path template for which this endpoint expects requests.
 void setPayloadExpression(org.springframework.expression.Expression payloadExpression)
          Specifies a SpEL expression to evaluate in order to generate the Message payload.
 void setRequestPayloadType(java.lang.Class<?> requestPayloadType)
          Specify the type of payload to be generated when the inbound HTTP request content is read by the HttpMessageConverters.
 void setSupportedMethodNames(java.lang.String... supportedMethods)
          Specify the supported request method names for this gateway.
 void setSupportedMethods(org.springframework.http.HttpMethod... supportedMethods)
          Specify the supported request methods for this gateway.
protected  java.lang.Object setupResponseAndConvertReply(javax.servlet.http.HttpServletResponse servletResponse, Message<?> replyMessage)
          Deprecated. As of release 2.2, please use setupResponseAndConvertReply(ServletServerHttpResponse, Message) instead.
protected  java.lang.Object setupResponseAndConvertReply(org.springframework.http.server.ServletServerHttpResponse response, Message<?> replyMessage)
          Converts the reply message to the appropriate HTTP reply object and sets up the ServletServerHttpResponse.
 
Methods inherited from class org.springframework.integration.gateway.MessagingGatewaySupport
doStop, receive, send, sendAndReceive, sendAndReceiveMessage, setErrorChannel, setReplyChannel, setReplyMapper, setReplyTimeout, setRequestChannel, setRequestMapper, setRequestTimeout, setShouldTrack
 
Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
getPhase, isAutoStartup, isRunning, setAutoStartup, setPhase, setTaskScheduler, start, stop, stop
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getConversionService, getTaskScheduler, setBeanFactory, setBeanName, setComponentName, setConversionService, 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

HttpRequestHandlingEndpointSupport

public HttpRequestHandlingEndpointSupport()

HttpRequestHandlingEndpointSupport

public HttpRequestHandlingEndpointSupport(boolean expectReply)
Method Detail

isExpectReply

protected boolean isExpectReply()
Returns:
whether to expect reply

setPath

public void setPath(java.lang.String path)
Set the path template for which this endpoint expects requests. May include path variable {keys} to match against.


setPayloadExpression

public void setPayloadExpression(org.springframework.expression.Expression payloadExpression)
Specifies a SpEL expression to evaluate in order to generate the Message payload. The EvaluationContext will be populated with an HttpEntity instance as the root object, and it may contain one or both of the #pathVariables and #queryParameters variables if present. Those variables' values are Maps.


setHeaderExpressions

public void setHeaderExpressions(java.util.Map<java.lang.String,org.springframework.expression.Expression> headerExpressions)
Specifies a Map of SpEL expressions to evaluate in order to generate the Message headers. The keys in the map will be used as the header names. When evaluating the expression, the EvaluationContext will be populated with an HttpEntity instance as the root object, and it may contain one or both of the #pathVariables and #queryParameters variables if present. Those variables' values are Maps.


setMessageConverters

public void setMessageConverters(java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
Set the message body converters to use. These converters are used to convert from and to HTTP requests and responses.


getMessageConverters

protected java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> getMessageConverters()

setHeaderMapper

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


setSupportedMethodNames

public void setSupportedMethodNames(java.lang.String... supportedMethods)
Specify the supported request method names for this gateway. By default, only GET and POST are supported.


setSupportedMethods

public void setSupportedMethods(org.springframework.http.HttpMethod... supportedMethods)
Specify the supported request methods for this gateway. By default, only GET and POST are supported.


setRequestPayloadType

public void setRequestPayloadType(java.lang.Class<?> requestPayloadType)
Specify the type of payload to be generated when the inbound HTTP request content is read by the HttpMessageConverters. By default this value is null which means at runtime any "text" Content-Type will result in String while all others default to byte[].class.


setExtractReplyPayload

public void setExtractReplyPayload(boolean extractReplyPayload)
Specify whether only the reply Message's payload should be passed in the response. If this is set to 'false', the entire Message will be used to generate the response. The default is 'true'.


setMultipartResolver

public void setMultipartResolver(org.springframework.web.multipart.MultipartResolver multipartResolver)
Specify the MultipartResolver to use when checking requests. If no resolver is provided, the "multipartResolver" bean in the context will be used as a fallback. If that is not available either, this endpoint will not support multipart requests.


isShuttingDown

protected boolean isShuttingDown()

getComponentType

public java.lang.String getComponentType()
Description copied from class: IntegrationObjectSupport
Subclasses may implement this method to provide component type information.

Specified by:
getComponentType in interface NamedComponent
Overrides:
getComponentType in class MessagingGatewaySupport

onInit

protected void onInit()
               throws java.lang.Exception
Locates the MultipartResolver bean based on the default name defined by the DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME constant if available.

Overrides:
onInit in class MessagingGatewaySupport
Throws:
java.lang.Exception

doStart

protected void doStart()
Description copied from class: AbstractEndpoint
Subclasses must implement this method with the start behavior. This method will be invoked while holding the AbstractEndpoint.lifecycleLock.

Overrides:
doStart in class MessagingGatewaySupport

doHandleRequest

protected final Message<?> doHandleRequest(javax.servlet.http.HttpServletRequest servletRequest,
                                           javax.servlet.http.HttpServletResponse servletResponse)
                                    throws java.io.IOException
Handles the HTTP request by generating a Message and sending it to the request channel. If this gateway's 'expectReply' property is true, it will also generate a response from the reply Message once received.

Returns:
a the response Message
Throws:
java.io.IOException

setupResponseAndConvertReply

protected final java.lang.Object setupResponseAndConvertReply(org.springframework.http.server.ServletServerHttpResponse response,
                                                              Message<?> replyMessage)
Converts the reply message to the appropriate HTTP reply object and sets up the ServletServerHttpResponse.

Parameters:
response - The ServletServerHttpResponse.
replyMessage - The reply message.
Returns:
The message payload (if extractReplyPayload) otherwise the message.

setupResponseAndConvertReply

@Deprecated
protected final java.lang.Object setupResponseAndConvertReply(javax.servlet.http.HttpServletResponse servletResponse,
                                                                         Message<?> replyMessage)
Deprecated. As of release 2.2, please use setupResponseAndConvertReply(ServletServerHttpResponse, Message) instead.


createEvaluationContext

protected org.springframework.expression.spel.support.StandardEvaluationContext createEvaluationContext()

beforeShutdown

public int beforeShutdown()
Description copied from interface: OrderlyShutdownCapable
Called before shutdown begins. Implementations should stop accepting new messages. Can optionally return the number of active messages in process.

Specified by:
beforeShutdown in interface OrderlyShutdownCapable
Returns:
The number of active messages if available.

afterShutdown

public int afterShutdown()
Description copied from interface: OrderlyShutdownCapable
Called after normal shutdown of schedulers, executors etc, and after the shutdown delay has elapsed, but before any forced shutdown of any remaining active scheduler/executor threads.Can optionally return the number of active messages still in process.

Specified by:
afterShutdown in interface OrderlyShutdownCapable
Returns:
The number of active messages if available.

Spring Integration