rewrite-spring
rewrite-spring copied to clipboard
Upgrade to HttpClient5 for HttpComponentsClientHttpRequestFactory in Spring 6
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.
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 ;)
FWIW https://chat.openai.com/share/3b804a18-c795-41e6-8254-335e340e9347 I asked chatGPT to do the job ;)
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.
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!