Skip to content

feat: support Spring RestClient#3602

Open
uuuyuqi wants to merge 6 commits intoalibaba:1.8from
uuuyuqi:uuuyuqi/feat-restclient-adapter
Open

feat: support Spring RestClient#3602
uuuyuqi wants to merge 6 commits intoalibaba:1.8from
uuuyuqi:uuuyuqi/feat-restclient-adapter

Conversation

@uuuyuqi
Copy link
Collaborator

@uuuyuqi uuuyuqi commented Mar 10, 2026

Describe what this PR does / why we need it

Closes #3601

Does this pull request fix one issue?

Closes #3601

Describe how you did it

add Sentinel RestClient Interceptor

Describe how to verify it

Run com.alibaba.csp.sentinel.adapter.spring.restclient.SentinelRestClientInterceptorSimpleTest to confirm the flow control behavior of Sentinel.

Special notes for reviews

None

uuuyuqi added 2 commits March 10, 2026 11:32
Change-Id: I49c8b1cf7a0a6f357b68b58bd352efc5981b76b2
Co-developed-by: OpenCode <noreply@opencode.ai>
Change-Id: Ieacaf949222f5871f934d2f0aa3bd6d73d1a087b

@PostMapping("/users")
public String createUser(@RequestBody String user) {
return "Created: " + user;

Check warning

Code scanning / CodeQL

Cross-site scripting Medium test

Cross-site scripting vulnerability due to a
user-provided value
.
uuuyuqi added 3 commits March 10, 2026 15:11
Change-Id: I2df54be42732b1c1786b4b9189639913b4598fd9
Co-developed-by: OpenCode <noreply@opencode.ai>
Change-Id: Ia9dceb36c2ef3a9a86a61110446c6aec4de331a9
Co-developed-by: OpenCode <noreply@opencode.ai>
Change-Id: I10f1752fa921aa8980e640c4fe7726d3c1764f37
Co-developed-by: OpenCode <noreply@opencode.ai>
@LearningGp LearningGp requested a review from Copilot March 12, 2026 08:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Sentinel adapter module to integrate with Spring Framework 6+ RestClient, providing resource extraction, flow-control/circuit-breaking interception, and fallback handling.

Changes:

  • Introduces SentinelRestClientInterceptor with configurable resource naming and fallback behavior.
  • Adds default implementations for resource extraction and blocked-request fallback response.
  • Adds a new Maven module with documentation and a set of unit/integration-style tests.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
sentinel-adapter/pom.xml Registers the new sentinel-spring-restclient-adapter module in the parent build.
sentinel-adapter/sentinel-spring-restclient-adapter/pom.xml Adds module dependencies (Spring Web/Boot/Test) and Surefire configuration.
sentinel-adapter/sentinel-spring-restclient-adapter/README.md Documents adapter usage, configuration, and resource naming.
sentinel-adapter/sentinel-spring-restclient-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/spring/restclient/SentinelRestClientInterceptor.java Implements the RestClient request interceptor with dual-level resource entries and fallback handling.
sentinel-adapter/sentinel-spring-restclient-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/spring/restclient/SentinelRestClientConfig.java Provides configuration (prefix, extractor, fallback) for the interceptor.
sentinel-adapter/sentinel-spring-restclient-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/spring/restclient/SentinelClientHttpResponse.java Defines the default blocked-response ClientHttpResponse implementation.
sentinel-adapter/sentinel-spring-restclient-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/spring/restclient/extractor/RestClientResourceExtractor.java Introduces extractor SPI for resource naming.
sentinel-adapter/sentinel-spring-restclient-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/spring/restclient/extractor/DefaultRestClientResourceExtractor.java Implements default resource naming from method + URL components.
sentinel-adapter/sentinel-spring-restclient-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/spring/restclient/fallback/RestClientFallback.java Introduces fallback SPI for blocked requests.
sentinel-adapter/sentinel-spring-restclient-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/spring/restclient/fallback/DefaultRestClientFallback.java Provides default blocked-request fallback response.
sentinel-adapter/sentinel-spring-restclient-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/spring/restclient/SentinelRestClientInterceptorSimpleTest.java Adds integration-style tests around flow control/degrade with an embedded Spring Boot app.
sentinel-adapter/sentinel-spring-restclient-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/spring/restclient/ManualTest.java Adds a manual runnable test/demo for the adapter.
sentinel-adapter/sentinel-spring-restclient-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/spring/restclient/SentinelRestClientConfigTest.java Adds config validation tests (null extractor/fallback).
sentinel-adapter/sentinel-spring-restclient-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/spring/restclient/SentinelClientHttpResponseTest.java Adds tests for blocked-response behavior.
sentinel-adapter/sentinel-spring-restclient-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/spring/restclient/extractor/DefaultRestClientResourceExtractorTest.java Adds tests for default resource name formatting.
sentinel-adapter/sentinel-spring-restclient-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/spring/restclient/fallback/DefaultRestClientFallbackTest.java Adds tests for default fallback handling.
sentinel-adapter/sentinel-spring-restclient-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/spring/restclient/app/TestApplication.java Provides Spring Boot test application used by integration tests.
sentinel-adapter/sentinel-spring-restclient-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/spring/restclient/app/TestController.java Provides endpoints used by integration tests (hello/users/error/delay).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +40 to +43
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

These imports (CountDownLatch, TimeUnit, AtomicBoolean, AtomicReference) are not used in the test class as shown. Please remove unused imports to avoid warnings and keep the test file focused.

Suggested change
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

Copilot uses AI. Check for mistakes.
- DefaultRestClientFallback now throws SentinelRpcException for consistency with other client adapters (okhttp, apache-httpclient)
- SentinelClientHttpResponse uses text/plain instead of application/json since the body is plain text
- Update tests to reflect new exception-throwing behavior

Change-Id: I778bb9bba1bd24435e667f996ebbff19d734b14a
Co-developed-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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.

support Spring RestClient

3 participants