Skip to content

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

Open
uuuyuqi wants to merge 3 commits intoalibaba:1.8from
uuuyuqi:feat/httpclient5-adapter
Open

feat: add Apache HttpClient 5.x adapter support#3614
uuuyuqi wants to merge 3 commits intoalibaba: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>
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.

1 participant