refactor(HttpClient): Remove HttpClient library - #354
Merged
Merged
Conversation
…te tests to use MockRestServiceServer
Member
Author
|
🎉 This PR is included in version 1.25.3 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.
Summary
This PR replaces usages of the legacy, end-of-life
org.apache.httpcomponents:httpclient(4.5.14) library with Spring's modern, built-inRestClient(available in Spring Boot 3.3.x viaspring-boot-starter-web) and removes the dependency frompom.xml.Motivation
RestClientas an idiomatic, fluent synchronous HTTP client backed by Java 11+java.net.http.HttpClientout of the box without requiring third-party dependencies.httpclientreduces the external dependency footprint.Changes
1. Dependency Removal
pom.xml: Removedorg.apache.httpcomponents:httpclient(4.5.14).2. Service & Controller Migrations
CRaterService.java:RestClient.BuilderandEnvironmentvia constructor.HttpClient,HttpPost, and manualBase64Basic Authentication header encoding withRestClient's fluent API (.headers(h -> h.setBasicAuth(...))).MediaType.APPLICATION_JSON_UTF8(application/json;charset=utf-8) as required by the CRater scoring endpoint..retrieve().body(String.class).ContactAPIController.java:HttpPost,NameValuePair,UrlEncodedFormEntity, and manualBufferedReaderstream reading withRestClientandLinkedMultiValueMap.DailyAdminJob.java:HttpClient,HttpPost, and manual connection release inpostStatisticswithRestClientandLinkedMultiValueMap.3. Test Improvements
CRaterServiceTest.java:MockRestServiceServer.test.organd eliminateFatal transport errorconnection exceptions in test logs.Verification
mvn test-compilemvn test -Dtest=CRaterServiceTest(4/4 passed)mvn test -Dtest=CRaterControllerTest(4/4 passed)org.apache.httpin the codebase.