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 2019/07/27 01:07:19 UTC

[GitHub] [servicecomb-java-chassis] liubao68 edited a comment on issue #1278: cse 下载的sdk demo怎么用responseEntity返回自定义的headers和httpstatus

liubao68 edited a comment on issue #1278: cse 下载的sdk demo怎么用responseEntity返回自定义的headers和httpstatus
URL: https://github.com/apache/servicecomb-java-chassis/issues/1278#issuecomment-515639201
 
 
   可以的
   ```
     @ResponseHeaders({@ResponseHeader(name = "h1", response = String.class),
         @ResponseHeader(name = "h2", response = String.class)})
     @RequestMapping(path = "/responseEntity", method = RequestMethod.POST)
     public ResponseEntity<Date> responseEntity(InvocationContext c1, @RequestAttribute("date") Date date) {
       HttpHeaders headers = new HttpHeaders();
       headers.add("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE));
   
       InvocationContext c2 = ContextUtils.getInvocationContext();
       headers.add("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE));
   
       return new ResponseEntity<>(date, headers, HttpStatus.ACCEPTED);
     }
   ```
   
   需要注意ServiceComb是“编译时语义”, 即接口声明的时候,需要明确其语义。 和Spring MVC是有些差异的。
   
   相关例子:
   https://docs.servicecomb.io/java-chassis/zh_CN/general-development/error-handling.html
   https://github.com/apache/servicecomb-java-chassis/blob/master/integration-tests/
   
   与Spring MVC的差异说明:
   https://docs.servicecomb.io/java-chassis/zh_CN/build-provider/springmvc.html
   https://docs.servicecomb.io/java-chassis/zh_CN/build-provider/interface-constraints.html
   
   编译时语义的一些背景:
   https://zhuanlan.zhihu.com/p/75348817

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


With regards,
Apache Git Services