Skip to content

refactor(HttpClient): Remove HttpClient library - #354

Merged
hirokiterashima merged 4 commits into
developfrom
refactor/remove-http-client-dep
Sep 15, 2026
Merged

hirokiterashima merged 4 commits into
developfrom
refactor/remove-http-client-dep

Conversation

@hirokiterashima

Copy link
Copy Markdown
Member

Summary

This PR replaces usages of the legacy, end-of-life org.apache.httpcomponents:httpclient (4.5.14) library with Spring's modern, built-in RestClient (available in Spring Boot 3.3.x via spring-boot-starter-web) and removes the dependency from pom.xml.

Motivation

  • Security & Maintenance: Apache HttpClient 4.x reached End-of-Life (EOL) in late 2022 and will not receive future security patches or maintenance.
  • Spring Boot 3 Alignment: Spring 6 / Spring Boot 3 dropped support for Apache HttpClient 4.x. Spring now provides RestClient as an idiomatic, fluent synchronous HTTP client backed by Java 11+ java.net.http.HttpClient out of the box without requiring third-party dependencies.
  • Dependency Reduction: Eliminating httpclient reduces the external dependency footprint.

Changes

1. Dependency Removal

  • pom.xml: Removed org.apache.httpcomponents:httpclient (4.5.14).

2. Service & Controller Migrations

  • CRaterService.java:
    • Injected RestClient.Builder and Environment via constructor.
    • Replaced Apache HttpClient, HttpPost, and manual Base64 Basic Authentication header encoding with RestClient's fluent API (.headers(h -> h.setBasicAuth(...))).
    • Configured MediaType.APPLICATION_JSON_UTF8 (application/json;charset=utf-8) as required by the CRater scoring endpoint.
    • Replaced entity stream reading with .retrieve().body(String.class).
  • ContactAPIController.java:
    • Replaced HttpPost, NameValuePair, UrlEncodedFormEntity, and manual BufferedReader stream reading with RestClient and LinkedMultiValueMap.
  • DailyAdminJob.java:
    • Replaced HttpClient, HttpPost, and manual connection release in postStatistics with RestClient and LinkedMultiValueMap.
    • Cleaned up unused imports.

3. Test Improvements

  • CRaterServiceTest.java:
    • Updated the test setup to use Spring Test's MockRestServiceServer.
    • Mocked the HTTP POST requests across all 4 unit tests to prevent actual network calls to test.org and eliminate Fatal transport error connection exceptions in test logs.

Verification

  • Full compilation passes: mvn test-compile
  • Unit tests pass without network errors or exceptions:
    • mvn test -Dtest=CRaterServiceTest (4/4 passed)
    • mvn test -Dtest=CRaterControllerTest (4/4 passed)
  • Verified zero remaining imports or references to org.apache.http in the codebase.

@hirokiterashima
hirokiterashima merged commit 6ec5785 into develop Sep 15, 2026
2 checks passed
@hirokiterashima
hirokiterashima deleted the refactor/remove-http-client-dep branch September 15, 2026 22:41
@hirokiterashima

Copy link
Copy Markdown
Member Author

🎉 This PR is included in version 1.25.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant