Skip to content

feat: add Apache HttpClient 5.x adapter support#3614

Merged
LearningGp merged 6 commits into
alibaba:1.8from
uuuyuqi:feat/httpclient5-adapter
May 11, 2026
Merged

feat: add Apache HttpClient 5.x adapter support#3614
LearningGp merged 6 commits into
alibaba:1.8from
uuuyuqi:feat/httpclient5-adapter

Conversation

@uuuyuqi
Copy link
Copy Markdown
Collaborator

@uuuyuqi uuuyuqi commented Apr 28, 2026

What does this PR do?

Add sentinel-apache-httpclient5-adapter module that integrates Sentinel flow control with Apache HttpClient 5.x outgoing HTTP requests.

This is a companion to the existing sentinel-apache-httpclient-adapter (4.x), providing the same Sentinel protection capabilities for users who have migrated to HttpClient 5.x.

Features

  • ExecChainHandler-based integration: SentinelApacheHttpClient5Handler implements HC5's ExecChainHandler interface, allowing seamless integration via HttpClients.custom().addExecInterceptorBefore()
  • Configurable resource name extraction: Default extractor generates METHOD:URL format resource names (e.g., GET:http://example.com/api/users), with query string and fragment stripping
  • Customizable fallback handling: Default behavior throws SentinelRpcException; users can implement custom ApacheHttpClientFallback for alternative responses
  • Configurable resource name prefix: Default prefix httpclient:, fully customizable

Usage

CloseableHttpClient httpclient = HttpClients.custom()
    .addExecInterceptorBefore(ChainElement.MAIN_TRANSPORT.name(), "sentinel",
        new SentinelApacheHttpClient5Handler())
    .build();

Architecture

Follows the same design pattern as the existing HttpClient 4.x adapter:

  • SentinelApacheHttpClient5Handler — core handler (ExecChainHandler)
  • SentinelApacheHttpClientConfig — configuration holder
  • ApacheHttpClientResourceExtractor / DefaultApacheHttpClientResourceExtractor — resource name extraction
  • ApacheHttpClientFallback / DefaultApacheHttpClientFallback — fallback handling

Test Coverage

  • 21 unit & integration tests covering:
    • Default interceptor behavior
    • URL query string / fragment stripping
    • Custom resource extractor
    • Empty / custom prefix configuration
    • Fallback exception handling
    • Config validation (null safety)

Closes #3614

Made with Cursor

uuuyuqi added 3 commits April 28, 2026 11:43
Add sentinel-apache-httpclient5-adapter module that integrates Sentinel
flow control with Apache HttpClient 5.x outgoing HTTP requests.

Features:
- ExecChainHandler-based integration (SentinelApacheHttpClient5Handler)
- Configurable resource name extraction (METHOD:URL format by default)
- Query string and fragment stripping in resource names
- Customizable fallback handling (throws SentinelRpcException by default)
- Configurable resource name prefix (default: "httpclient:")

Follows the same architecture pattern as the existing HttpClient 4.x
adapter while adapting to HC5's ExecChainHandler API.

Closes alibaba#3614

Change-Id: I966295da9419beac99451fc6c9c31b1d75a9e7e6
Co-developed-by: Cursor <noreply@cursor.com>
After the 1.8.9 release, several PRs have been merged but
the development version was not updated. Bump to 1.8.10-SNAPSHOT
for next development iteration.

Change-Id: I2b7ba2b5b4e9e39d1f9749288d54b9926a512132
Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I1fe4682e41185dc7c8ed30541989f2881ba87549
Co-developed-by: Cursor <noreply@cursor.com>
@uuuyuqi
Copy link
Copy Markdown
Collaborator Author

uuuyuqi commented Apr 28, 2026

CI Failure Analysis

The CI build failure is not related to this PR. The failing test is:

com.alibaba.csp.sentinel.slots.system.SystemRuleManagerTest.testCheckMaxCpuUsageNotBBR

This is a pre-existing flaky test in sentinel-core that fails on JDK 11 in the CI environment (likely due to CPU usage measurement sensitivity in GitHub Actions runners). The other JDK builds (8/17/21) were cancelled due to fail-fast strategy.

For reference, the upstream 1.8 branch also has CI failures in recent runs (e.g., run #23330824085).

All 21 tests in the sentinel-apache-httpclient5-adapter module pass successfully across JDK versions.

uuuyuqi added 2 commits April 29, 2026 10:20
Change-Id: Ie28f99434badfc00decc914ffd27f83c837d947d
Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I60caec5b17e92a79827671e531a0818f61163b48
Co-developed-by: Cursor <noreply@cursor.com>
Copy link
Copy Markdown
Collaborator

@LearningGp LearningGp left a comment

Choose a reason for hiding this comment

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

The default extractor in HC4 returns only the URI path (e.g., /api/users), while HC5 returns METHOD:FULL_URL (e.g., GET:http://host/api/users). This results in incompatible resource naming conventions under the httpclient: prefix across the two versions. For users upgrading from HC4 to HC5, all existing flow control rules will break. I suggest clearly documenting this discrepancy and including migration notes in the README.

Document the default resource name format difference between HC4 and HC5
adapters so users understand that existing flow control rules will not
match automatically after migration, and provide a snippet for preserving
the legacy URI-only naming via a custom extractor.

Change-Id: Iadacf3d3288acb4b23ce67441a88c0b8ad0f0b6e
Co-developed-by: Claude <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@LearningGp LearningGp left a comment

Choose a reason for hiding this comment

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

LGTM

@LearningGp LearningGp merged commit 1375ff9 into alibaba:1.8 May 11, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants