YvCeung opened a new pull request, #7430:
URL: https://github.com/apache/incubator-seata/pull/7430

   <!--
       Licensed to the Apache Software Foundation (ASF) under one or more
       contributor license agreements.  See the NOTICE file distributed with
       this work for additional information regarding copyright ownership.
       The ASF licenses this file to You under the Apache License, Version 2.0
       (the "License"); you may not use this file except in compliance with
       the License.  You may obtain a copy of the License at
   
       http://www.apache.org/licenses/LICENSE-2.0
       
       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.
   -->
   <!-- Please make sure you have read and understood the contributing 
guidelines -->
   
   - [ ] I have registered the PR [changes](../changes).
   
   ### Ⅰ. Describe what this PR did
   Add support for parsing @RequestParam annotation in netty-http-server
   
   ### Ⅱ. Does this pull request fix one issue?
   <!-- If that, add "fixes #xxx" below in the next line, for example, fixes 
#97. -->
   
   fix #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:
   ```java
   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:
   ```java
   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;
               }
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org
For additional commands, e-mail: notifications-h...@seata.apache.org

Reply via email to