INT-4208: Support AsycRest in HTTP Module

https://jira.spring.io/browse/INT-4208
https://jira.spring.io/browse/INT-4076

Add `AsyncRestTemplate` support in `HttpRequestExecutingMessageHandler` and corresponding config/dsl support

* Polishing Docs
This commit is contained in:
Shiliang Li
2017-01-31 23:35:28 +08:00
committed by Artem Bilan
parent e06c0e2927
commit 802061985c
20 changed files with 1947 additions and 841 deletions

View File

@@ -5,7 +5,7 @@
=== Introduction
The HTTP support allows for the execution of HTTP requests and the processing of inbound HTTP requests.
Because interaction over HTTP is always synchronous, even if all that is returned is a 200 status code, the HTTP support consists of two gateway implementations: `HttpInboundEndpoint` and `HttpRequestExecutingMessageHandler`.
the HTTP support consists of the following gateway implementations: `HttpInboundEndpoint`, `HttpRequestExecutingMessageHandler` and `AsyncHttpRequestExecutingMessageHandler`
[[http-inbound]]
=== Http Inbound Components
@@ -125,6 +125,7 @@ The key that is used for that map entry by default is 'reply', but this can be o
[[http-outbound]]
=== Http Outbound Components
==== HttpRequestExecutingMessageHandler
To configure the `HttpRequestExecutingMessageHandler` write a bean definition like this:
@@ -164,6 +165,7 @@ When set to true (default is false), a _Set-Cookie_ header received from the ser
This header will then be used on subsequent sends.
This enables simple stateful interactions, such as...
`...->logonGateway->...->doWorkGateway->...->logoffGateway->...`
If _transfer-cookies_ is false, any _Set-Cookie_ header received will remain as _Set-Cookie_ in the reply message, and will be dropped on subsequent sends.
@@ -190,6 +192,37 @@ The `expected-response-type` must be compatible with the (configured or default)
Of course, this can be an abstract class, or even an interface (such as `java.io.Serializable` when using java serialization and `Content-Type: application/x-java-serialized-object`).
=====
==== AsyncHttpRequestExecutingMessageHandler
The `AsyncHttpRequestExecutingMessageHandler` implementation is very similar to `HttpRequestExecutingMessageHandler` instead of delegating to a `AsyncRestTemplate`.
To configure it, write a bean like this:
[source,xml]
----
<bean id="httpAsyncOutbound"
class="org.springframework.integration.http.outbound.AsyncHttpRequestExecutingMessageHandler">
<constructor-arg value="http://localhost:8080/example" />
<property name="outputChannel" ref="responseChannel" />
</bean>
----
You can configure the `AsyncClientHttpRequestFactory` instance to use:
[source,xml]
----
<bean id="httpOutbound"
class="org.springframework.integration.http.outbound.AsyncHttpRequestExecutingMessageHandler">
<constructor-arg value="http://localhost:8080/example" />
<property name="outputChannel" ref="responseChannel" />
<property name="asyncRequestFactory" ref="customRequestFactory" />
</bean>
----
By default the HTTP request will be generated using an instance of `SimpleClientHttpRequestFactory`.
Use of the Apache Commons HTTP Async Client is also supported through the provided `HttpComponentsAsyncClientHttpRequestFactory` which can be injected as shown above.
For other settings like cookie, converters, etc, please see <<HttpRequestExecutingMessageHandler>> above.
[[http-namespace]]
=== HTTP Namespace Support
@@ -512,6 +545,34 @@ The configuration looks very similar to the gateway:
auto-startup="false"/>
----
If you want to execute the http request in an asynchronous way, you can use the `outbound-async-gateway` or `outbound-async-channel-adapter`.
[source,xml]
----
<int-http:outbound-async-gateway id="asyncExample1"
request-channel="requests"
url="http://localhost/test"
http-method-expression="headers.httpMethod"
extract-request-payload="false"
expected-response-type-expression="payload"
charset="UTF-8"
async-request-factory="requestFactory"
reply-timeout="1234"
reply-channel="replies"/>
<int-http:outbound-async-channel-adapter id="asyncExample2"
url="http://localhost/example"
http-method="GET"
channel="requests"
charset="UTF-8"
extract-payload="false"
expected-response-type="java.lang.String"
async-request-factory="someRequestFactory"
order="3"
auto-startup="false"/>
----
[NOTE]
=====
To specify the URL; you can use either the 'url' attribute or the 'url-expression' attribute.

View File

@@ -14,6 +14,11 @@ development process.
The new `MongoDbOutboundGateway` allows you to make queries to the database on demand by sending a message to its request channel.
See <<mongodb-outbound-gateway>> for more information.
==== HTTP Async Outbound Gateway and Channel Adapter
The new `AsyncHttpRequestExecutingMessageHandler` adds support for `AsyncRestTemplate` for outbound channel adapter and gateway.
See <<AsyncHttpRequestExecutingMessageHandler>> for more information.
[[x5.0-general]]
=== General Changes