-
Notifications
You must be signed in to change notification settings - Fork 8.9k
optimize: add support for parsing @RequestParam annotation in netty-http-server #7430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
# Conflicts: # changes/en-us/2.x.md # changes/zh-cn/2.x.md
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 2.x #7430 +/- ##
============================================
+ Coverage 59.48% 59.53% +0.04%
+ Complexity 552 548 -4
============================================
Files 1281 1281
Lines 46191 46272 +81
Branches 5569 5580 +11
============================================
+ Hits 27476 27546 +70
- Misses 16142 16154 +12
+ Partials 2573 2572 -1
🚀 New features to boost your workflow:
|
…/main/java/org/apache/seata/spring/boot/autoconfigure/http/RestControllerBeanPostProcessor.java Co-authored-by: Copilot <[email protected]>
funky-eyes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Can you delete lines 114-116 in the ClusterController code? |
Ok. Besides, I have modified some of the code to accommodate the situation where the parameters were not annotated before. Don't merge them for now. I will resubmit them later |
OK |
done |
funky-eyes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RestControllerBeanPostProcessorTest.setUp:53 UnfinishedVerification
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the Netty HTTP server’s parameter parsing to fully support @RequestParam (including default values and required flags), refactors how parameter metadata is built, and adds tests covering the new parsing logic.
- Refactored
RestControllerBeanPostProcessorto extract annotation matching into a newbuildParamMetaDatamethod and handle default annotation types. - Extended
ParameterParser.getArgValueto implementREQUEST_PARAMhandling with default‐value and required‐flag logic. - Added unit tests in both core and spring-autoconfigure modules to verify
@RequestParambehavior and existing parsing. - Minor cleanup in
ClusterController(removed redundant null check) and documentation updates.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| server/src/main/java/org/apache/seata/server/controller/ClusterController.java | Removed redundant timeout == null check and simplified use of timeout in lambda |
| seata-spring-autoconfigure-core/src/main/java/.../RestControllerBeanPostProcessor.java | Added buildParamMetaData method and default‐annotation logic; introduced helper sets |
| seata-spring-autoconfigure-core/src/test/java/.../RestControllerBeanPostProcessorTest.java | Added tests to verify parsing of @RequestParam (name, defaultValue, required) |
| core/src/main/java/org/apache/seata/core/rpc/netty/http/ParameterParser.java | Implemented REQUEST_PARAM case in getArgValue; added class-level javadoc |
| core/src/main/java/org/apache/seata/core/rpc/netty/http/ParamMetaData.java | Added paramName, required, and defaultValue fields |
| core/src/test/java/org/apache/seata/core/rpc/netty/http/ParameterParserTest.java | Added tests for REQUEST_PARAM parsing (single value, default value, exceptions) |
| core/src/test/java/org/apache/seata/core/rpc/netty/http/HttpDispatchHandlerTest.java | Fixed missing paramName setup in REQUEST_PARAM test |
| core/src/main/java/org/apache/seata/core/rpc/netty/http/HttpDispatchHandler.java | Added class‐level javadoc |
| changes/zh-cn/2.x.md & changes/en-us/2.x.md | Updated release notes to include #7430 |
core/src/main/java/org/apache/seata/core/rpc/netty/http/ParameterParser.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/apache/seata/core/rpc/netty/http/ParameterParser.java
Show resolved
Hide resolved
…terParser.java Co-authored-by: Copilot <[email protected]>
Ⅰ. Describe what this PR did
Add support for parsing @RequestParam annotation in netty-http-server
Ⅱ. Does this pull request fix one issue?
fixes #7407
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Run
mvn clean testⅤ. Special notes for reviews
In the original ParamMetaData construction logic, the first annotation before the parameter is taken by default. In some cases, there may be two annotations before the parameter, such as
@NotBlank@RequestParam String name; In this case, it will cause the obtained ParamConvertType to be null, thereby triggering a bug where the subsequent parameter value binding fails.The current logic is to take the first annotation that conforms to the expected type from the for loop在原来的ParamMetaData构建的逻辑中,会默认取参数前的第一个注解,在某些场景下,参数前可能会有两个注解,比如
@NotBlank@RequestParam String name;这种情况下会导致获取到的ParamConvertType为null,从而引发后续的参数值绑定失败的bug。目前的逻辑为从for循环里面取第一个符合期望类型的注解origin:
now: