Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@YvCeung
Copy link
Contributor

@YvCeung YvCeung commented Jun 10, 2025

  • I have registered the PR changes.

Ⅰ. 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:

private static void addPathMapping(Object httpController, List<String> prePaths, Method method, List<String> postPaths) {
        Class<?>[] parameterTypes = method.getParameterTypes();
        Annotation[][] parameterAnnotations = method.getParameterAnnotations();
        ParamMetaData[] paramMetaDatas = new ParamMetaData[parameterTypes.length];
        for (int i = 0; i < parameterTypes.length; i++) {
            Class<? extends Annotation> parameterAnnotationType = null;
            if (parameterAnnotations[i] != null && parameterAnnotations[i].length > 0) {
                parameterAnnotationType = parameterAnnotations[i][0].annotationType();
            }

            if (parameterAnnotationType == null) {
                parameterAnnotationType = RequestParam.class;
            }

now:

private static void addPathMapping(Object httpController, List<String> prePaths, Method method, List<String> postPaths) {
        Class<?>[] parameterTypes = method.getParameterTypes();
        Annotation[][] parameterAnnotations = method.getParameterAnnotations();
        ParamMetaData[] paramMetaDatas = new ParamMetaData[parameterTypes.length];
        Parameter[] parameters = method.getParameters();
        for (int i = 0; i < parameterTypes.length; i++) {
            Annotation matchedAnnotation = null;
            Class<? extends Annotation> parameterAnnotationType = null;
            if (parameterAnnotations[i] != null && parameterAnnotations[i].length > 0) {
                for (Annotation annotation : parameterAnnotations[i]) {
                    if (MAPPING_PARAM_TYPE.containsKey(annotation.annotationType())) {
                        parameterAnnotationType = annotation.annotationType();
                        matchedAnnotation = annotation;
                        break;
                    }
                }
            }

            if (parameterAnnotationType == null) {
                parameterAnnotationType = RequestParam.class;
            }

@codecov
Copy link

codecov bot commented Jun 10, 2025

Codecov Report

Attention: Patch coverage is 94.56522% with 5 lines in your changes missing coverage. Please review.

Project coverage is 59.53%. Comparing base (c82cdbb) to head (750e305).
Report is 1 commits behind head on 2.x.

Files with missing lines Patch % Lines
...onfigure/http/RestControllerBeanPostProcessor.java 95.58% 0 Missing and 3 partials ⚠️
...che/seata/core/rpc/netty/http/ParameterParser.java 85.71% 0 Missing and 2 partials ⚠️
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     
Files with missing lines Coverage Δ
...seata/core/rpc/netty/http/HttpDispatchHandler.java 70.12% <ø> (ø)
...pache/seata/core/rpc/netty/http/ParamMetaData.java 100.00% <100.00%> (ø)
...che/seata/server/controller/ClusterController.java 20.93% <100.00%> (-5.16%) ⬇️
...che/seata/core/rpc/netty/http/ParameterParser.java 75.80% <85.71%> (-1.75%) ⬇️
...onfigure/http/RestControllerBeanPostProcessor.java 88.88% <95.58%> (+9.20%) ⬆️

... and 7 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This comment was marked as outdated.

…/main/java/org/apache/seata/spring/boot/autoconfigure/http/RestControllerBeanPostProcessor.java

Co-authored-by: Copilot <[email protected]>
Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

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

LGTM

@funky-eyes funky-eyes changed the title Add support for parsing @RequestParam annotation in netty-http-server optimize: add support for parsing @RequestParam annotation in netty-http-server Jun 11, 2025
@funky-eyes
Copy link
Contributor

Can you delete lines 114-116 in the ClusterController code?

        if (timeout == null) {
            timeout = 28000;
        }

@YvCeung
Copy link
Contributor Author

YvCeung commented Jun 11, 2025

Can you delete lines 114-116 in the ClusterController code?

        if (timeout == null) {
            timeout = 28000;
        }

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

@funky-eyes
Copy link
Contributor

Can you delete lines 114-116 in the ClusterController code?

        if (timeout == null) {
            timeout = 28000;
        }

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

@YvCeung
Copy link
Contributor Author

YvCeung commented Jun 11, 2025

Can you delete lines 114-116 in the ClusterController code?

        if (timeout == null) {
            timeout = 28000;
        }

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

Copy link
Contributor

@funky-eyes funky-eyes left a 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

@YvCeung
Copy link
Contributor Author

YvCeung commented Jun 11, 2025

RestControllerBeanPostProcessorTest.setUp:53 UnfinishedVerification

done

@YvCeung YvCeung requested a review from funky-eyes June 11, 2025 13:09
@funky-eyes funky-eyes requested a review from Copilot June 12, 2025 02:20
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

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 RestControllerBeanPostProcessor to extract annotation matching into a new buildParamMetaData method and handle default annotation types.
  • Extended ParameterParser.getArgValue to implement REQUEST_PARAM handling with default‐value and required‐flag logic.
  • Added unit tests in both core and spring-autoconfigure modules to verify @RequestParam behavior 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

@funky-eyes funky-eyes merged commit 07f56b5 into apache:2.x Jun 14, 2025
12 of 13 checks passed
slievrly pushed a commit to slievrly/fescar that referenced this pull request Oct 21, 2025
YvCeung added a commit to YvCeung/incubator-seata that referenced this pull request Dec 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

supports configuration in @RequestParam

2 participants