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 2021/05/10 10:12:40 UTC

[GitHub] [servicecomb-java-chassis] SenixCoder opened a new issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

SenixCoder opened a new issue #2373:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2373


   问题现象:
   1. 使用@ModelAttribute及@ApiModel注解,将文件通过聚合对象进行传递。在实际传递时,其他参数是拼接在URI中进行传递的,这样会导致如果tomcat配置了maxHeaderSize,传递较大长度的参数时会报错:Request header is too large.
   
   如果想要将其他参数放在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.

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



[GitHub] [servicecomb-java-chassis] SenixCoder closed issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

Posted by GitBox <gi...@apache.org>.
SenixCoder closed issue #2373:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2373


   


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

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



[GitHub] [servicecomb-java-chassis] SenixCoder commented on issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

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


   > ModelAttribute没有RESTful语义
   > 试试JAX-RS规范的`@BeanParam`
   > BeanParam中可以混合放body以外的其他类型参数,body需要独立使用一个参数
   
   是否有具体的样例?我尝试使用@BeanParam替代@ModelAttribute,Bean中参数使用@FormParam标记,在实际传输中参数仍然被追加在了uri后面。


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

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



[GitHub] [servicecomb-java-chassis] SenixCoder commented on issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

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


   > 参考: http://servicecomb.gitee.io/servicecomb-java-chassis-doc/java-chassis/zh_CN/build-provider/jaxrs/
   > Query参数应该使用@QueryParam
   
   我想要实现的是参数能否放在body中而非拼接在uri后面,从而不被tomcat maxHeaderSize限制住,之前使用的@ModelAttribute无法做到,@QueryParam可以做到吗?


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

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



[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

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


   哦。 把你的意思理解反了。 
   \@FormParam就是从body的form里面提取参数的。 但是你的问题很奇怪, 如果是服务端接收\@FormParam, 那么客户端应该把参数使用form传输, 而客户如何构造请求,是客户端决定的。 不应该存在你说的问题。 
   
   所以没太明白你的问题的发生过程是怎么样的。 
   


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

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



[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

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


   参考: http://servicecomb.gitee.io/servicecomb-java-chassis-doc/java-chassis/zh_CN/build-provider/jaxrs/
   Query参数应该使用@QueryParam


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

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



[GitHub] [servicecomb-java-chassis] wujimin commented on issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

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


   ModelAttribute没有RESTful语义  
   试试JAX-RS规范的`@BeanParam`  
   BeanParam中可以混合放body以外的其他类型参数,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.

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



[GitHub] [servicecomb-java-chassis] SenixCoder edited a comment on issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

Posted by GitBox <gi...@apache.org>.
SenixCoder edited a comment on issue #2373:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2373#issuecomment-839587851


   > 哦。 把你的意思理解反了。
   > @FormParam就是从body的form里面提取参数的。 但是你的问题很奇怪, 如果是服务端接收@FormParam, 那么客户端应该把参数使用form传输, 而客户如何构造请求,是客户端决定的。 不应该存在你说的问题。
   > 
   > 所以没太明白你的问题的发生过程是怎么样的。
   
   api如下
   ```
   public interface EngineElementHotDeployService {
       EngineElementHotDeployResponse hotDeploy(
           @ModelAttribute @Valid @NotNull @ApiParam("request") EngineElementHotDeployRequest request);
   }
   ```
   EngineElementHotDeployRequest如下
   ```
   @ApiModel
   @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
   public class EngineElementHotDeployRequest {
       private String projectName;
   
       private String moduleName;
   
       private String engineName;
   
       private Part hotDeployFile;
   
       private String hotDeployDslContent;
   ...
   }
   ```
   
   服务端实现如下
   ```
   @RestSchema(schemaId = "StudioHotDeployRpcService")
   @RequestMapping(value = ServiceConstants.SERVICE_URL_PREFIX + "/v1/protected/studio/hot-deploy")
   public class StudioHotDeployRpcServiceImpl implements EngineElementHotDeployService {
       @Override
       @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
       public EngineElementHotDeployResponse hotDeploy(@ModelAttribute EngineElementHotDeployRequest request) {
           validate(request);
           return hotDeployEngine(request);
       }
   }
   ```
   
   客户端调用如下
   ```
   @RpcReference(microserviceName = "xxxx", schemaId = "StudioHotDeployRpcService")
   private ProjectHotDeployApiService hotDeployApiService;    
   
   private void hotDeploy(EngineElementHotDeployRequest request) {
           EngineElementHotDeployResponse response = hotDeployService.hotDeploy(request);
   }
   ```


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

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



[GitHub] [servicecomb-java-chassis] SenixCoder commented on issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

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


   > 哦。 把你的意思理解反了。
   > @FormParam就是从body的form里面提取参数的。 但是你的问题很奇怪, 如果是服务端接收@FormParam, 那么客户端应该把参数使用form传输, 而客户如何构造请求,是客户端决定的。 不应该存在你说的问题。
   > 
   > 所以没太明白你的问题的发生过程是怎么样的。
   
   api如下
   `public interface EngineElementHotDeployService {
       EngineElementHotDeployResponse hotDeploy(
           @ModelAttribute @Valid @NotNull @ApiParam("request") EngineElementHotDeployRequest request);
   }
   `
   服务端实现如下
   `@RestSchema(schemaId = "StudioHotDeployRpcService")
   @RequestMapping(value = ServiceConstants.SERVICE_URL_PREFIX + "/v1/protected/studio/hot-deploy")
   public class StudioHotDeployRpcServiceImpl implements EngineElementHotDeployService {
       @Override
       @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
       public EngineElementHotDeployResponse hotDeploy(@ModelAttribute EngineElementHotDeployRequest request) {
           validate(request);
           return hotDeployEngine(request);
       }
   }`
   
   客户端调用如下
   `
   @RpcReference(microserviceName = "xxxx", schemaId = "StudioHotDeployRpcService")
   private ProjectHotDeployApiService hotDeployApiService;    
   
   private void hotDeploy(EngineElementHotDeployRequest request) {
           EngineElementHotDeployResponse response = hotDeployService.hotDeploy(request);
   }`


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

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



[GitHub] [servicecomb-java-chassis] SenixCoder edited a comment on issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

Posted by GitBox <gi...@apache.org>.
SenixCoder edited a comment on issue #2373:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2373#issuecomment-839587851


   > 哦。 把你的意思理解反了。
   > @FormParam就是从body的form里面提取参数的。 但是你的问题很奇怪, 如果是服务端接收@FormParam, 那么客户端应该把参数使用form传输, 而客户如何构造请求,是客户端决定的。 不应该存在你说的问题。
   > 
   > 所以没太明白你的问题的发生过程是怎么样的。
   
   api如下
   ```
   public interface EngineElementHotDeployService {
       EngineElementHotDeployResponse hotDeploy(
           @ModelAttribute @Valid @NotNull @ApiParam("request") EngineElementHotDeployRequest request);
   }
   ```
   服务端实现如下
   ```@RestSchema(schemaId = "StudioHotDeployRpcService")
   @RequestMapping(value = ServiceConstants.SERVICE_URL_PREFIX + "/v1/protected/studio/hot-deploy")
   public class StudioHotDeployRpcServiceImpl implements EngineElementHotDeployService {
       @Override
       @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
       public EngineElementHotDeployResponse hotDeploy(@ModelAttribute EngineElementHotDeployRequest request) {
           validate(request);
           return hotDeployEngine(request);
       }
   }
   ```
   
   客户端调用如下
   ```
   @RpcReference(microserviceName = "xxxx", schemaId = "StudioHotDeployRpcService")
   private ProjectHotDeployApiService hotDeployApiService;    
   
   private void hotDeploy(EngineElementHotDeployRequest request) {
           EngineElementHotDeployResponse response = hotDeployService.hotDeploy(request);
   }
   ```


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

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



[GitHub] [servicecomb-java-chassis] SenixCoder edited a comment on issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

Posted by GitBox <gi...@apache.org>.
SenixCoder edited a comment on issue #2373:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2373#issuecomment-840436798


   > 我的写法:
   > 
   > * 参数类:
   > 
   > ```java
   > public class Person {
   >     private int age;
   > 
   >     private String name;
   > 
   >     public int getAge() {
   >         return age;
   >     }
   > 
   >     @FormParam("age")
   >     public void setAge(int age) {
   >         this.age = age;
   >     }
   > 
   >     public String getName() {
   >         return name;
   >     }
   > 
   >     @FormParam("name")
   >     public void setName(String name) {
   >         this.name = name;
   >     }
   > }
   > ```
   > 
   > * provider方的controller
   > 
   > ```java
   > @RestSchema(schemaId = "helloService")
   > @Path("/hello")
   > public class HelloService {
   > 
   >     @Path("/sayHello")
   >     @POST
   >     public String sayHello(@BeanParam Person person) {
   >         System.out.println("sayHello is called, and person is [" + person +"]");
   >         return "Hello, your name is " + person.getName() + ", and age is " + person.getAge();
   >     }
   > }
   > ```
   > 
   > * consumer方的controller
   > 
   > ```java
   > @RpcSchema(schemaId = "helloController")
   > public class HelloController {
   >     @RpcReference(microserviceName = "2373-server", schemaId = "helloService")
   >     private HelloServiceIntf hello;
   > 
   >     @Path("/test")
   >     @GET
   >     public String Hello() {
   >         return hello.sayHello("asd", 12);
   >     }
   > }
   > ```
   > 
   > * consumer 方rpc接口
   > 
   > ```java
   > package org.servicecomb.sample;public interface HelloServiceIntf {
   >     String sayHello(String name, int age);
   > }
   > ```
   > 
   > 最终实现的效果是参数被写进body
   > ![image](https://user-images.githubusercontent.com/22323152/118105863-868f9d00-b40f-11eb-823b-16b46eb74fd0.png)
   
   需要携带Part对象,普通的Bean是可以写进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.

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



[GitHub] [servicecomb-java-chassis] SenixCoder edited a comment on issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

Posted by GitBox <gi...@apache.org>.
SenixCoder edited a comment on issue #2373:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2373#issuecomment-839587851


   > 哦。 把你的意思理解反了。
   > @FormParam就是从body的form里面提取参数的。 但是你的问题很奇怪, 如果是服务端接收@FormParam, 那么客户端应该把参数使用form传输, 而客户如何构造请求,是客户端决定的。 不应该存在你说的问题。
   > 
   > 所以没太明白你的问题的发生过程是怎么样的。
   
   api如下
   ```public interface EngineElementHotDeployService {
       EngineElementHotDeployResponse hotDeploy(
           @ModelAttribute @Valid @NotNull @ApiParam("request") EngineElementHotDeployRequest request);
   }
   ```
   服务端实现如下
   ```@RestSchema(schemaId = "StudioHotDeployRpcService")
   @RequestMapping(value = ServiceConstants.SERVICE_URL_PREFIX + "/v1/protected/studio/hot-deploy")
   public class StudioHotDeployRpcServiceImpl implements EngineElementHotDeployService {
       @Override
       @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
       public EngineElementHotDeployResponse hotDeploy(@ModelAttribute EngineElementHotDeployRequest request) {
           validate(request);
           return hotDeployEngine(request);
       }
   }
   ```
   
   客户端调用如下
   ```
   @RpcReference(microserviceName = "xxxx", schemaId = "StudioHotDeployRpcService")
   private ProjectHotDeployApiService hotDeployApiService;    
   
   private void hotDeploy(EngineElementHotDeployRequest request) {
           EngineElementHotDeployResponse response = hotDeployService.hotDeploy(request);
   }
   ```


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

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



[GitHub] [servicecomb-java-chassis] SenixCoder commented on issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

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


   > 我的写法:
   > 
   > * 参数类:
   > 
   > ```java
   > public class Person {
   >     private int age;
   > 
   >     private String name;
   > 
   >     public int getAge() {
   >         return age;
   >     }
   > 
   >     @FormParam("age")
   >     public void setAge(int age) {
   >         this.age = age;
   >     }
   > 
   >     public String getName() {
   >         return name;
   >     }
   > 
   >     @FormParam("name")
   >     public void setName(String name) {
   >         this.name = name;
   >     }
   > }
   > ```
   > 
   > * provider方的controller
   > 
   > ```java
   > @RestSchema(schemaId = "helloService")
   > @Path("/hello")
   > public class HelloService {
   > 
   >     @Path("/sayHello")
   >     @POST
   >     public String sayHello(@BeanParam Person person) {
   >         System.out.println("sayHello is called, and person is [" + person +"]");
   >         return "Hello, your name is " + person.getName() + ", and age is " + person.getAge();
   >     }
   > }
   > ```
   > 
   > * consumer方的controller
   > 
   > ```java
   > @RpcSchema(schemaId = "helloController")
   > public class HelloController {
   >     @RpcReference(microserviceName = "2373-server", schemaId = "helloService")
   >     private HelloServiceIntf hello;
   > 
   >     @Path("/test")
   >     @GET
   >     public String Hello() {
   >         return hello.sayHello("asd", 12);
   >     }
   > }
   > ```
   > 
   > * consumer 方rpc接口
   > 
   > ```java
   > package org.servicecomb.sample;public interface HelloServiceIntf {
   >     String sayHello(String name, int age);
   > }
   > ```
   > 
   > 最终实现的效果是参数被写进body
   > ![image](https://user-images.githubusercontent.com/22323152/118105863-868f9d00-b40f-11eb-823b-16b46eb74fd0.png)
   
   需要携带Part对象,不同的Bean是可以写进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.

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



[GitHub] [servicecomb-java-chassis] kaister3 commented on issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

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


   我的写法:
   - 参数类:
   ```java
   public class Person {
       private int age;
   
       private String name;
   
       public int getAge() {
           return age;
       }
   
       @FormParam("age")
       public void setAge(int age) {
           this.age = age;
       }
   
       public String getName() {
           return name;
       }
   
       @FormParam("name")
       public void setName(String name) {
           this.name = name;
       }
   }
   ```  
   - provider方的controller
   ```java
   @RestSchema(schemaId = "helloService")
   @Path("/hello")
   public class HelloService {
   
       @Path("/sayHello")
       @POST
       public String sayHello(@BeanParam Person person) {
           System.out.println("sayHello is called, and person is [" + person +"]");
           return "Hello, your name is " + person.getName() + ", and age is " + person.getAge();
       }
   }
   ```  
   - consumer方的controller
   ```java
   @RpcSchema(schemaId = "helloController")
   public class HelloController {
       @RpcReference(microserviceName = "2373-server", schemaId = "helloService")
       private HelloServiceIntf hello;
   
       @Path("/test")
       @GET
       public String Hello() {
           return hello.sayHello("asd", 12);
       }
   }
   ```  
   - consumer 方rpc接口
   ```java
   package org.servicecomb.sample;public interface HelloServiceIntf {
       String sayHello(String name, int age);
   }
   ```  
   
   最终实现的效果是参数被写进body
   ![image](https://user-images.githubusercontent.com/22323152/118105863-868f9d00-b40f-11eb-823b-16b46eb74fd0.png)
   


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

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



[GitHub] [servicecomb-java-chassis] SenixCoder edited a comment on issue #2373: 通过@ModelAttribute注解传递文件聚合对象时,参数拼接在URI中导致header过长

Posted by GitBox <gi...@apache.org>.
SenixCoder edited a comment on issue #2373:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2373#issuecomment-839587851


   > 哦。 把你的意思理解反了。
   > @FormParam就是从body的form里面提取参数的。 但是你的问题很奇怪, 如果是服务端接收@FormParam, 那么客户端应该把参数使用form传输, 而客户如何构造请求,是客户端决定的。 不应该存在你说的问题。
   > 
   > 所以没太明白你的问题的发生过程是怎么样的。
   
   api如下
   ```
   public interface EngineElementHotDeployService {
       EngineElementHotDeployResponse hotDeploy(
           @ModelAttribute @Valid @NotNull @ApiParam("request") EngineElementHotDeployRequest request);
   }
   ```
   服务端实现如下
   ```
   @RestSchema(schemaId = "StudioHotDeployRpcService")
   @RequestMapping(value = ServiceConstants.SERVICE_URL_PREFIX + "/v1/protected/studio/hot-deploy")
   public class StudioHotDeployRpcServiceImpl implements EngineElementHotDeployService {
       @Override
       @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
       public EngineElementHotDeployResponse hotDeploy(@ModelAttribute EngineElementHotDeployRequest request) {
           validate(request);
           return hotDeployEngine(request);
       }
   }
   ```
   
   客户端调用如下
   ```
   @RpcReference(microserviceName = "xxxx", schemaId = "StudioHotDeployRpcService")
   private ProjectHotDeployApiService hotDeployApiService;    
   
   private void hotDeploy(EngineElementHotDeployRequest request) {
           EngineElementHotDeployResponse response = hotDeployService.hotDeploy(request);
   }
   ```


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

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