Repository navigation
Conversation
Added AsyncRestTemplate, the asynchronous counterpart to the RestTemplate that was introduced in Spring 3. All methods on the AsyncRestTemplate are similar to those found on the synchronous RestTemplatem, except that they return Future wrappers instead of concrete results. To enable this, this commit introduces the AsyncClientHttpRequest and AsyncClientHttpRequestFactory, similar to the ClientHttpRequest and ClientHttpRequestFactory, except that ClientHttpRequest returns a Future<ClientHttpResponse> for the execute method. Two implementations of these interfaces are provided, one based on the HttpURLConnection incombination with a Spring AsyncTaskExecutor and one based on Apache HttpComponents HttpAsyncClient. Issue: SPR-8804
Contributor
Author
|
@rstoyanchev and @jhoeller, could you please review this before merging? Thanks. |
Contributor
|
Thanks Arjen. We'll have a look. |
|
how about a callback approach? Scenario: web request comes in, needs to submit 1-n requests to backends e.g. using AsyncRestTemplate. Would be easy to return a DeferredResult and set the result once the backend request completes: @RequestMapping("doSomething")
public DeferredResult<String> doSomething() {
DeferrredResult<> pendingResult = new DeferredResult<String>();
myAsyncTemplate.get( "http://.....", new ResultHandler<String>() {
public void processResult(String result) {
pendingResult.setResult( result );
}
});
return pendingResult;
}stupid idea? Is there another way/better way to do this that I am not aware of? |
Contributor
|
There are some further changes. See pull 351. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added AsyncRestTemplate, the asynchronous counterpart to the
RestTemplate that was introduced in Spring 3. All methods on the
AsyncRestTemplate are similar to those found on the synchronous
RestTemplatem, except that they return Future wrappers instead of
concrete results.
To enable this, this commit introduces the AsyncClientHttpRequest and
AsyncClientHttpRequestFactory, similar to the ClientHttpRequest and
ClientHttpRequestFactory, except that ClientHttpRequest returns a
Future for the execute method. Two implementations
of these interfaces are provided, one based on the HttpURLConnection
incombination with a Spring AsyncTaskExecutor and one based on Apache
HttpComponents HttpAsyncClient.
Issue: SPR-8804