org.springframework.integration.http
Class HttpInboundEndpoint

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.endpoint.AbstractEndpoint
          extended by org.springframework.integration.gateway.AbstractMessagingGateway
              extended by org.springframework.integration.gateway.SimpleMessagingGateway
                  extended by org.springframework.integration.http.HttpInboundEndpoint
All Implemented Interfaces:
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.Lifecycle, MessagingGateway, org.springframework.web.HttpRequestHandler

public class HttpInboundEndpoint
extends SimpleMessagingGateway
implements org.springframework.web.HttpRequestHandler

An inbound endpoint for handling an HTTP request and generating a response.

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). By default the request will be converted to a Message payload according to the rules of the DefaultInboundRequestMapper.

To customize the mapping of the request to the Message payload, provide a reference to an InboundRequestMapper implementation to the setRequestMapper(InboundRequestMapper) method.

The value for expectReply is false by default. This means that as soon as the Message is created and passed to the request channel, a response will be generated. If a view has been provided, it will be invoked to render the response, and it will have access to the request message in the model map. The corresponding key in that map is determined by the requestKey property (with a default of "requestMessage"). If no view is provided, and the 'expectReply' value is false then a simple OK status response will be issued.

To handle request-reply scenarios, set the 'expectReply' flag to true. By default, the reply Message's payload will be extracted prior to generating a response. The payload must be either a String, a byte array, or a Serializable object. To have the entire serialized Message written as the response body, switch the extractReplyPayload value to false.

In the request-reply case, if a 'view' is provided, the response will not be generated directly from the reply Message or its extracted payload. Instead, the model map will be passed to that view, and it will contain either the reply Message or payload depending on the value of extractReplyPayload. The corresponding key in the map will be determined by the replyKey property (with a default of "reply"). The map will also contain the original request Message as described above.

Since:
1.0.2
Author:
Mark Fisher

Field Summary
 
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
logger
 
Constructor Summary
HttpInboundEndpoint()
           
 
Method Summary
 void handleRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void onInit()
           
 void setExpectReply(boolean expectReply)
          Specify whether this endpoint should perform a request/reply operation.
 void setExtractReplyPayload(boolean extractReplyPayload)
          Specify whether the reply Message's payload should be passed in the response.
 void setReplyKey(java.lang.String replyKey)
          Specify the key to be used when storing the reply Message or payload in the model map.
 void setRequestKey(java.lang.String requestKey)
          Specify the key to be used when storing the request Message in the model map.
 void setRequestMapper(InboundRequestMapper requestMapper)
          Specify an InboundRequestMapper implementation to map from the inbound HttpServletRequest instances to Messages at runtime.
 void setSupportedMethods(java.lang.String... supportedMethods)
          Specify the supported request methods for this endpoint.
 void setView(org.springframework.web.servlet.View view)
          Specify a View to be used for rendering the response.
 
Methods inherited from class org.springframework.integration.gateway.SimpleMessagingGateway
fromMessage, toMessage
 
Methods inherited from class org.springframework.integration.gateway.AbstractMessagingGateway
doStart, doStop, receive, send, sendAndReceive, sendAndReceiveMessage, setReplyChannel, setReplyTimeout, setRequestChannel, setRequestTimeout, setShouldThrowErrors
 
Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
afterPropertiesSet, isRunning, setAutoStartup, setTaskScheduler, start, stop
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
getBeanFactory, getBeanName, getChannelResolver, getTaskScheduler, setBeanFactory, setBeanName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HttpInboundEndpoint

public HttpInboundEndpoint()
Method Detail

setSupportedMethods

public void setSupportedMethods(java.lang.String... supportedMethods)
Specify the supported request methods for this endpoint. By default, only GET and POST are supported.


setExpectReply

public void setExpectReply(boolean expectReply)
Specify whether this endpoint should perform a request/reply operation. Otherwise, it will only send the message and immediately generate a response. The default is 'false'.


setRequestMapper

public void setRequestMapper(InboundRequestMapper requestMapper)
Specify an InboundRequestMapper implementation to map from the inbound HttpServletRequest instances to Messages at runtime. The default implementation is DefaultInboundRequestMapper.


setExtractReplyPayload

public void setExtractReplyPayload(boolean extractReplyPayload)
Specify whether the reply Message's payload should be passed in the response. If this is set to 'false', the entire Message will be sent as bytes. Otherwise, the reply Message payload must be a String or byte array. If a 'view' has been provided, the reply value will be sent in the model Map to that View. If the 'view' is null, the String or byte array will be written directly to the HTTP response.

The default value is 'true'.

See Also:
setView(View)

setView

public void setView(org.springframework.web.servlet.View view)
Specify a View to be used for rendering the response. If no View is provided, the reply Message or its payload will be written directly to the response.

See Also:
setExtractReplyPayload(boolean)

setRequestKey

public void setRequestKey(java.lang.String requestKey)
Specify the key to be used when storing the request Message in the model map. This is only necessary when a view has been provided for rendering the response. The default key is "requestMessage".


setReplyKey

public void setReplyKey(java.lang.String replyKey)
Specify the key to be used when storing the reply Message or payload in the model map. This is only necessary when a view has been provided for rendering the response. The default key is "reply".


onInit

protected void onInit()
               throws java.lang.Exception
Overrides:
onInit in class AbstractMessagingGateway
Throws:
java.lang.Exception

handleRequest

public void handleRequest(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
                   throws javax.servlet.ServletException,
                          java.io.IOException
Specified by:
handleRequest in interface org.springframework.web.HttpRequestHandler
Throws:
javax.servlet.ServletException
java.io.IOException