21.2 Http Inbound Gateway

To receive messages over http you need to use an HttpInboundEndpoint. In common with the HttpInvoker support the Http Inbound Gateway needs to be deployed within a servlet container. The easiest way to do this is to provide a servlet definition in web.xml, see Section 20.2, “HttpInvoker Inbound Gateway” for further details. Below is an example bean definition for a simple HttpInboundEndpoint

<bean id="httpInbound" class="org.springframework.integration.http.HttpInboundEndpoint">
	<property name="requestChannel" ref="httpRequestChannel" />
	<property name="replyChannel" ref="httpReplyChannel" />	
</bean>

The HttpInboundEndpoint accepts an instance of InboundRequestMapper which allows customisation of the mapping from HttpServletRequest to Message. If none is provided the an instance of DefaultInboundRequestMapper will be used. This encapsulates a simple strategy, which for example will create a String message for a POST request where the content type starts with "text", see the Javadoc for full details.

In sending a response to the client there are a number of ways to customise the behaviour of the gateway. By default the gateway will simply acknowledge that the request was received by sending a 200 status code back. It is possible to customise this response by providing an implementation of the Spring MVC View which will be invoked with the created Message. In the case that the gateway should expect a reply to the Message then setting the expectReply flag will cause the gateway to wait for a response Message before creating an Http response. Below is an example of a gateway configured to use a custom view and to wait for a response. It also shows how to customise the Http methods accepted by the gateway, which are POST and GET by default.

<bean id="httpInbound" class="org.springframework.integration.http.HttpInboundEndpoint">
	<property name="requestChannel" ref="httpRequestChannel" />
	<property name="replyChannel" ref="httpReplyChannel" />
	<property name="view" ref="jsonView" />
	<property name="supportedMethods" >
		<list>
			<value>GET</value>
			<value>DELETE</value>
		</list>
	</property>
	<property name="expectReply" value="true" />
	<property name="requestMapper" ref="customRequestMapper" />
</bean>

The message created from the request will be available in the Model map. The key that is used for that map entry by default is 'requestMessage', but this can be overridden by setting the 'requestKey' property on the endpoint's configuration.