rewrite-spring icon indicating copy to clipboard operation
rewrite-spring copied to clipboard

Upgrade to HttpClient5 for HttpComponentsClientHttpRequestFactory in Spring 6

Open nmck257 opened this issue 1 year ago • 4 comments

NOTE: Requires Apache HttpComponents 5.1 or higher, as of Spring 6.0. https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.html

HttpComponents did a GAV change with 5, so projects with explicit dependencies on this library may be stuck on 4.x and fall into the compatibility trap documented above.

This recipe could possibly have an applicability test for projects using HttpComponentsClientHttpRequestFactory, to decrease risk of performing this upgrade (and introducing some other breaking change) on projects which don't imminently need it.

nmck257 avatar Mar 03 '23 15:03 nmck257

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#apache-httpclient-in-resttemplate

Support for Apache HttpClient has been removed in Spring Framework 6.0, immediately replaced by org.apache.httpcomponents.client5:httpclient5 (note: this dependency has a different groupId). If you are noticing issues with HTTP client behavior, it could be that RestTemplate is falling back to the JDK client. org.apache.httpcomponents:httpclient can be brought transitively by other dependencies, so your application might rely on this dependency without declaring it.

https://hc.apache.org/httpcomponents-client-5.2.x/migration-guide/preparation.html https://hc.apache.org/httpcomponents-client-5.2.x/migration-guide/migration-to-classic.html

Just for the records ;)

MahatmaFatalError avatar Jun 15 '23 15:06 MahatmaFatalError

FWIW https://chat.openai.com/share/3b804a18-c795-41e6-8254-335e340e9347 I asked chatGPT to do the job ;)

MahatmaFatalError avatar Jun 29 '23 11:06 MahatmaFatalError

I'm assuming this is the same issue I have just seen, which is that when I applied the recipe org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2 to upgrade to Spring Boot 3.2, my build.gradle dependency implementation 'org.apache.httpcomponents:httpclient' was not replaced with implementation 'org.apache.httpcomponents.client5:httpclient5' and I had to do it manually.

If this is not the same issue (?) I can create a separate new issue.

aholland avatar Jan 20 '24 18:01 aholland

As an update here: we've spin off the Apache HttpClient recipes into rewrite-apache: https://github.com/openrewrite/rewrite-apache/tree/main/src/main/java/org/openrewrite/apache

To resolve this issue we'd need to add a dependency on rewrite-apache here and link the migration into the Spring Boot 3 migration, which should be fairly straightforward. Anyone welcome to pitch in!

timtebeek avatar Mar 08 '24 11:03 timtebeek