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/12/24 01:06:23 UTC

[GitHub] [servicecomb-java-chassis] liubao68 edited a comment on issue #1479: 在Controller类的方法中如何获得request header中的信息

liubao68 edited a comment on issue #1479: 在Controller类的方法中如何获得request header中的信息
URL: https://github.com/apache/servicecomb-java-chassis/issues/1479#issuecomment-568617502
 
 
   Find in [examples](https://github.com/apache/servicecomb-java-chassis/blob/master/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java)
   
   Using ApiImplicitParam and HttpServletRequest 
   
   ```
   
   @Path("/")
   @GET
   @Produces(MediaType.APPLICATION_JSON)
   @ApiOperation(value = "get all user informations", response = TenantResponse.class, responseContainer = "List")
   @ApiImplicitParams({@ApiImplicitParam(paramType = "header", value = "Authorization token", name = "Authorization",
       example = "Basic 18zgoYu4sSAP/RZ1lVrTVA==", dataType = "string", required = true)})
   public Response getUserAll(HttpServletRequest request) {
       request.getHeader("Authorization");
       return Response.ok().build();
   }
   
   ```
   
   
   Or you can using InvocationContext, first put header to context in HttpServerFilter and then get it using InvocationContext.  [java-chassis-fence](https://github.com/apache/servicecomb-fence) can be a project example. 
   
   

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