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/09/24 09:56:22 UTC

[GitHub] [servicecomb-java-chassis] fanjiwang1992 edited a comment on issue #2596: InvocationContext传递的参数 服务端如何获取

fanjiwang1992 edited a comment on issue #2596:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2596#issuecomment-926500593


   客户端设置方式:
   第一种:  通过ContextUtils直接获取invocationContext
        InvocationContext invocationContext = ContextUtils.getInvocationContext();
        invocationContext.addContext("csefjw", "ddddd");
   第二种: 直接new InvocationContext() 放进CseHttpEntity中
    InvocationContext invocationContext = new InvocationContext();
    CseHttpEntity<?> entity = new CseHttpEntity<>(null)
   entity.setContext(invocationContext);
   
   服务端获取方式:
   第一种: 通过ContextUtils直接获取invocationContext
   InvocationContext invocationContext = ContextUtils.getInvocationContext()
   invocationContext .getContext()或者指定具体的key 
   第二种: 在接口参数中添加 InvocationContext invocationContext
   public String sayHello(@PathVariable("name") @Length String name, InvocationContext invocationContext) throws InterruptedException {
   System.out.println(invocationContext.getContext().get("aaa"));
   System.out.println(formatter.format(new Date())+ " " +name);
   return name+", hello";
   }
   
   
   
   
   


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