You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2022/11/01 07:51:52 UTC

[GitHub] [servicecomb-java-chassis] hypggg opened a new issue, #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

hypggg opened a new issue, #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354

   接口已经定义body体不能为空,但body请求体 什么也不传,参数校验拦截不了。
    parameters:
           - in: "body"
             name: "xxx "
             required: true
   servicecomb版本  2.7.4
   期待报4XX错误 。


-- 
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: commits-unsubscribe@servicecomb.apache.org.apache.org

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


[GitHub] [servicecomb-java-chassis] weinihaom commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
weinihaom commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1298106157

   > `@requestbody注解,就已经包含了非空的意思` 这个直观理解上不是很对。 body 参数还是允许传空。
   
   @Target(ElementType.PARAMETER)
   @Retention(RetentionPolicy.RUNTIME)
   @Documented
   public @interface RequestBody {
   
   	/**
   	 * Whether body content is required.
   	 * <p>Default is {@code true}, leading to an exception thrown in case
   	 * there is no body content. Switch this to {@code false} if you prefer
   	 * {@code null} to be passed when the body content is {@code null}.
   	 * @since 3.2
   	 */
   	boolean required() default true;
   }
   您看一下这个required(), 这个标明了请求体是否可以为空


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] weinihaom commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
weinihaom commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1293397626

   > 你直接在接口的参数声明上加一个@NotNull showMonthUsages(@requestbody @Valid @NotNull School requestbody)
   
   OK


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] weinihaom commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
weinihaom commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1298108030

   不填,默认是不可以为空


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] weinihaom commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
weinihaom commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1297973777

   > 
   
   > `showMonthUsages(@Requestbody @Valid @NotNull School requestbody)` 应该是正确的用法, 关闭问题。
   @Requestbody注解,就已经包含了非空的意思。再加一个@NotNull显得累赘。而且不兼容之前的版本,升级serviceComb需要开发者手动去给每个接口,手动增加一个@NotNull注解。这非常不合理
   


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] weinihaom commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
weinihaom commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1291423816

   搭配@NotNull使用,没有效果,还是会进入业务层


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] yanghao605 commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
yanghao605 commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1295688886

   > 
   
   Rest on Servelt应该用不到这个转换类吧


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] weinihaom commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
weinihaom commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1291426272

   > 我通过POSTMan调用是在body中输入一个null,会出现这种情况,可以把用户的定义也贴一下吗
   
       public class User implements Serializable {
           private static final long serialVersionUID = 1L;
           @Valid
           @NotNull
           private String name;
   
           @Valid
           @NotNull
           private Integer age;
   
           public String getName() {
               return name;
           }
   
           public void setName(String name) {
               this.name = name;
           }
   
           public Integer getAge() {
               return age;
           }
   
           public void setAge(Integer age) {
               this.age = age;
           }
       }


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1295860184

   `showMonthUsages(@Requestbody @Valid @NotNull School requestbody)` 应该是正确的用法, 关闭问题。 


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] yanghao605 commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
yanghao605 commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1284990612

   可以搭配@NotNull使用


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 closed issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
liubao68 closed issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] yanghao605 commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
yanghao605 commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1291651241

   我在2.6.0版本的chassis中在对象中使用@NotNull注解的时候,是把servicecomb中的hibernate-validator以及jakarta.validation-api排除,使用spring-boot-starter-validation,jakarta.validation-api 3.0
   <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-validation</artifactId>
               <version>2.6.7</version>
           </dependency>
           <dependency>
               <groupId>jakarta.validation</groupId>
               <artifactId>jakarta.validation-api</artifactId>
               <version>3.0.0</version>
           </dependency>


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] yanghao605 commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
yanghao605 commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1291644611

   你直接在接口的参数声明上加一个@NotNull
   showMonthUsages(@RequestBody @Valid @NotNull School requestbody)


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1299414414

   I add a fix https://github.com/apache/servicecomb-java-chassis/pull/3447. 


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] hypggg closed issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
hypggg closed issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] hypggg commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
hypggg commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1253708242

   和servicecomb无关


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1254929658

   可以贴一下接口定义吗?


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] Shoothzj commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1274595278

   Can you please provided a minimize demo?


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] weinihaom commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
weinihaom commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1275789025

   `@RestController
   @RequestMapping(value = {"/v3"}, produces = {"application/json;charset=UTF-8"})
   @Validated
   public class TestRequestBodyDemoController {
       private static final CMLogger logger = CMLoggerFactory.getLogger(TestRequestBodyDemoController.class);
   
       @RequestMapping(value = {"/test_requestbody"}, produces = {"application/json"}, method = {RequestMethod.POST})
       public ResponseEntity<User> showMonthUsages(@Valid @RequestBody User requestbody) {
           logger.info("requestbody is {}", requestbody);
           return new ResponseEntity<>(requestbody, HttpStatus.OK);
       }
   }`
   这个是最简单的案例,请求体为空,不拦截


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] hypggg commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
hypggg commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1274542359

   xxMethod (@Valid XXXQueryReq XXXQueryReq) 就是普通的post请求,生成的接口就是这样的


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] weinihaom commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
weinihaom commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1293248464

   servicecomb版本 2.1.5版本是没有问题的,对比新版本。发现是VertxServerRequestToHttpServletRequest这个类的ServletInputStream getInputStream()方法修改导致的


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1298078345

   `@requestbody注解,就已经包含了非空的意思`  这个直观理解上不是很对。 body 参数还是允许传空。 


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] yanghao605 commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
yanghao605 commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1284878419

   我通过POSTMan调用是在body中输入一个null,会出现你这种情况,能把User的定义也贴一下吗


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] liubao68 closed issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
liubao68 closed issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] weinihaom commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
weinihaom commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1297974500

   > 
   
   
   
   > > servicecomb版本 2.1.5版本是没有问题的,对比新版本。发现是VertxServerRequestToHttpServletRequest这个类的ServletInputStream getInputStream()方法修改导致的
   > 
   > Rest on Servelt应该用不到这个转换类吧
   
   本地debug是会的
   


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] weinihaom commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
weinihaom commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1291424283

   > 可以用来@NotNull使用
   这个试过没有用


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] hypggg closed issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
hypggg closed issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354


-- 
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: commits-unsubscribe@servicecomb.apache.org

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


[GitHub] [servicecomb-java-chassis] weinihaom commented on issue #3354: @RequestBody 传空,不能拦截,会将空对象传导到controller。

Posted by GitBox <gi...@apache.org>.
weinihaom commented on issue #3354:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3354#issuecomment-1275795122

   2022-10-12 08:32:48,002Z+0000|INFO|group0-1-thread-2|||||TID: N/A|*.*.controller.TestRequestBodyDemoController.showMonthUsages(TestRequestBodyDemoController.java:29)|requestbody is null
   2022-10-12 08:32:48,002Z+0000|INFO|group0-1-thread-2|||||TID: N/A|*.*..interceptor.aspect.LogAspect.doInterceptor(LogAspect.java:56)|===TestRequestBodyDemoController.showMonthUsages success! cost time: 0ms
   2022-10-12 08:32:48,003Z+0000|INFO|transport-vert.x-eventloop-thread-10|||||TID: N/A||0:0:0:0:0:0:0:1 - - Wed, 12 Oct 2022 08:32:48 UTC "POST /v3/test_requestbody HTTP/1.1" 200 0 2
   
   This is a test log, which should not be entered into the business method body.


-- 
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: commits-unsubscribe@servicecomb.apache.org

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