Spring Integration

org.springframework.integration.http.inbound
Class HttpRequestHandlingController

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.HttpRequestHandlingController
All Implemented Interfaces:
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, TrackableComponent, org.springframework.web.servlet.mvc.Controller

public class HttpRequestHandlingController
extends MessagingGatewaySupport
implements org.springframework.web.servlet.mvc.Controller

Inbound HTTP endpoint that implements Spring's Controller interface to be used with a DispatcherServlet front controller.

The viewName will be passed into the ModelAndView return value.

This endpoint will have request/reply behavior by default. That can be overridden by passing false to the constructor. In the request/reply case, the core map will be passed to the view, and it will contain either the reply Message or payload depending on the value of extractReplyPayload (true by default, meaning just the payload). The corresponding key in the map is determined by the replyKey property (with a default of "reply").

Since:
2.0
Author:
Mark Fisher

Field Summary
 
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
logger
 
Constructor Summary
HttpRequestHandlingController()
           
HttpRequestHandlingController(boolean expectReply)
           
 
Method Summary
protected  java.lang.Object 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.
 java.lang.String getComponentType()
          Subclasses may implement this method to provide component type information.
protected  java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> getMessageConverters()
           
 org.springframework.web.servlet.ModelAndView handleRequest(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  boolean isExpectReply()
           
protected  void onInit()
          Locates the MultipartResolver bean based on the default name defined by the DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME constant if available.
 void setErrorCode(java.lang.String errorCode)
          The error code to use to signal an error in the message handling.
 void setErrorsKey(java.lang.String errorsKey)
          The key used to expose Errors in the core, in the case that message handling fails.
 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 setReplyKey(java.lang.String replyKey)
          Specify the key to be used when adding the reply Message or payload to the core map (will be payload only unless the value of HttpRequestHandlingEndpointSupport.setExtractReplyPayload(boolean) is false).
 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.
 void setViewName(java.lang.String viewName)
          Specify the view name.
 
Methods inherited from class org.springframework.integration.gateway.MessagingGatewaySupport
doStart, 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

HttpRequestHandlingController

public HttpRequestHandlingController()

HttpRequestHandlingController

public HttpRequestHandlingController(boolean expectReply)
Method Detail

setViewName

public void setViewName(java.lang.String viewName)
Specify the view name.


setReplyKey

public void setReplyKey(java.lang.String replyKey)
Specify the key to be used when adding the reply Message or payload to the core map (will be payload only unless the value of HttpRequestHandlingEndpointSupport.setExtractReplyPayload(boolean) is false). The default key is "reply".


setErrorsKey

public void setErrorsKey(java.lang.String errorsKey)
The key used to expose Errors in the core, in the case that message handling fails. Defaults to "errors".

Parameters:
errorsKey - the key value to set

setErrorCode

public void setErrorCode(java.lang.String errorCode)
The error code to use to signal an error in the message handling. In the case of an error this code will be provided in an object error to be optionally translated in the standard MVC way using a MessageSource. The default value is spring.integration.http.handler.error. Three arguments are provided: the exception, its message and its stack trace as a String.

Parameters:
errorCode - the error code to set

handleRequest

public final org.springframework.web.servlet.ModelAndView handleRequest(javax.servlet.http.HttpServletRequest servletRequest,
                                                                        javax.servlet.http.HttpServletResponse servletResponse)
                                                                 throws java.lang.Exception
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.

Specified by:
handleRequest in interface org.springframework.web.servlet.mvc.Controller
Throws:
java.lang.Exception

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.


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

doHandleRequest

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

Throws:
java.io.IOException

Spring Integration