Skip to content

Integrate Apache Http client with WebClient #24700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

martin-tarjanyi
Copy link
Contributor

@martin-tarjanyi martin-tarjanyi commented Mar 14, 2020

This PR aims to integrate Apache HttpClient 5 (which supports reactive streams and became GA last month) with WebClient.

Questions

  • Does Spring have some internal load tests which can be run the new implementation to see how it behaves under stress?
  • Should we support some kind of resource sharing just like it's done for the netty and jetty implementations?

Verified

This commit was signed with the committer’s verified signature.
metacosm Chris Laprun
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 14, 2020
@pivotal-issuemaster
Copy link

@martin-tarjanyi Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@martin-tarjanyi Thank you for signing the Contributor License Agreement!

@poutsma poutsma self-assigned this Mar 26, 2020
@poutsma
Copy link
Contributor

poutsma commented Mar 26, 2020

I will try and pick this up in the 5.3 timeline.

@poutsma poutsma added this to the 5.3 M1 milestone Mar 26, 2020
@poutsma
Copy link
Contributor

poutsma commented Mar 26, 2020

Thank you for submitting this PR. Could you please make sure that it conforms to our Code Style? This makes it significantly easier for us to review the PR.

Specifically, please make sure that there is an empty line in between class declaration and fields, and two before constructors. Please refer to other classes in the Spring Framework to see how they are formatted.

@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 26, 2020
…pache

# Conflicts:
#	spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java
@martin-tarjanyi
Copy link
Contributor Author

  • Added the requested code styles changes.
  • Reverted my change in WebClientIntegrationTests as @rstoyanchev made some refactoring there.
    • First test verified multiple request cookie handling and showed a potential bug in reactor-netty. This probably should be handled as a separate PR/issue: df32d7f#diff-e25ee214b9bfab881247f141b0ddb407R629-R632
    • Second test case verified response cookie handling: 14a63db#diff-e25ee214b9bfab881247f141b0ddb407R650-R684 - I found this test valuable as cookie mapping was a bit trickier in the Apache implementation than in the others. Now, I'm a bit uncertain whether I should extend some exisitng test case with this or just create a new one.
    • Please, advise on these.

@poutsma
Copy link
Contributor

poutsma commented Mar 27, 2020

  • Added the requested code styles changes.

Great! Thanks.

Indeed, I can duplicate this issue locally. Could you please file a separate issue against Spring Framework for this problem? Not sure if the reason is in our connector or in Reactor Netty itself, but we can migrate the issue if need be.

  • Second test case verified response cookie handling: 14a63db#diff-e25ee214b9bfab881247f141b0ddb407R650-R684 - I found this test valuable as cookie mapping was a bit trickier in the Apache implementation than in the others. Now, I'm a bit uncertain whether I should extend some exisitng test case with this or just create a new one.

Let's keep this as is, i.e. a new test in WebClientIntegrationTests, for now. It seems like a useful test to have.

I am now going to take a closer look at the code, so review comments will follow.

Copy link
Contributor

@poutsma poutsma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for submitting this PR.

While going through the code, I have some comments. Can you please resolve them?


@Override
public Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) {
return writeWith(Flux.from(body).flatMap(p -> p));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is supposed to flush after each inner buffer flux is complete. Is this code doing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely not, but I'm not sure. Let me tag Apache contributors @ok2c and @rschmitt maybe they can help out here.
So the question is: Is it possible to control when the reactive data producer flushes parts of the request body?
Also, folks, you are more than welcome to review this pull request if you have time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martin-tarjanyi I personally have little experience with reactive bindings but I hope @rschmitt can answer your question. What I could do though is to look at various ways of optimizing the implementation once it gets accepted.

@martin-tarjanyi
Copy link
Contributor Author

I've addressed most of the comments and answered where I have concerns.

@poutsma
Copy link
Contributor

poutsma commented Mar 30, 2020

Thank you. I have some further comments and changes I'd like to see, but I do not want to ask too much of you. The code is definitely in a good enough state now for me to take over.

Would you be willing to go through another round of comments? Or should I wrap it up?

@martin-tarjanyi
Copy link
Contributor Author

I'm happy to work on this, but if you think at this point it would be more efficient to take over then feel free to do so. Thanks for your review.

Copy link
Contributor

@poutsma poutsma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi and thanks again,

I have left some more comments. Please help me resolve them.

@rschmitt
Copy link

This looks good, from the perspective of httpcore5-reactive. I'm pleased to see that this integrates so cleanly with your existing abstractions (e.g. ReactiveHttpInputMessage); it's pretty much exactly what we were going for.

@poutsma poutsma closed this in 3bc1d42 Apr 29, 2020
poutsma added a commit that referenced this pull request Apr 29, 2020
* webclient_apache:
  Integrate Apache http client with WebClient
@poutsma
Copy link
Contributor

poutsma commented Apr 29, 2020

This PR has now been merged. Thanks for contributing, @martin-tarjanyi! And thanks for your support, @ok2c and @rschmitt.

kenny5he pushed a commit to kenny5he/spring-framework that referenced this pull request Jun 21, 2020
This commit introduces a ClientHttpConnector implementation backed by
Apache HttpComponents HttpClient 5.0.

Fixes spring-projectsgh-24700
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants