You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "soiz-tor (via GitHub)" <gi...@apache.org> on 2023/03/05 02:21:37 UTC

[GitHub] [dubbo] soiz-tor opened a new issue, #11725: 为什么两次同样的请求,协议却不一样

soiz-tor opened a new issue, #11725:
URL: https://github.com/apache/dubbo/issues/11725

   ```
   环境:
   jdk:19
   dubbo:3.2.0.beta-5
   ```
   
   ```
   这是我的dubbo过滤器
   @Activate(group = CommonConstants.CONSUMER, value = "cookieValidationFilter")
   public class CookieValidationFilter implements Filter {
       @Override
       public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
           RpcContext context = RpcContext.getServerContext();
           return invoker.invoke(invocation);
       }
   }
   ```
   
   ```
   这是我的controller:
   @DubboReference(protocol = "tri")
       UserService userService;
   
       @PostMapping(value = "/sign_in", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
       public ServerResponseEntity<Object> loginController(ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
           RpcContext context = RpcContext.getServerContext();
           System.out.println("rest接口");
           System.out.println(context.getProtocol());
           System.out.println(context.getRemoteAddressString());
           System.out.println("-----------------------------------------");
           String userInfo = serverHttpRequest.getHeaders().getFirst(USERINFO);
           ServerResponseEntity<Object> responseEntity = userService.loginService(userInfo);
           serverHttpResponse.addCookie(ResponseCookie.from("COOKIE_ID", String.valueOf(responseEntity.getData())).build());
           return responseEntity;
       }
   ```
   
   ```
   这是我的service:
   @Override
       public ServerResponseEntity<Object> loginService(String userInfo) {
           try {
               responseEntity = new ServerResponseEntity<>(0, "login success!", Decryptor.decrypt(userInfo));
           } catch (Exception e) {
               logger.info(e.toString());
           }
           return responseEntity;
       }
   ```
   
   ```
   这是打印结果:
   这是客户端连续两次调用/sign_in的打印结果
   rest接口
   null
   null:0
   -----------------------------------------
   rest接口
   tri
   null:0
   -----------------------------------------
   ```
   
   问:为什么前后两次协议打印结果不一样,第一次null,第二次是tri


-- 
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: notifications-unsubscribe@dubbo.apache.org.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] AlbumenJ commented on issue #11725: 为什么两次同样的请求,协议却不一样

Posted by "AlbumenJ (via GitHub)" <gi...@apache.org>.
AlbumenJ commented on issue #11725:
URL: https://github.com/apache/dubbo/issues/11725#issuecomment-1456021690

   @aamingaa PTAL


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] aamingaa commented on issue #11725: 为什么两次同样的请求,协议却不一样

Posted by "aamingaa (via GitHub)" <gi...@apache.org>.
aamingaa commented on issue #11725:
URL: https://github.com/apache/dubbo/issues/11725#issuecomment-1462282529

   > 
   
   因为这个protocol是从consumerUrl里取的,当没有进行远程调用时,consumerUrl不会进行设置,所以第一次getServerContext取到的protocol为空。你可以这样调整下顺序,第一次就不为空了:
   
       userService.loginService(userInfo)
       RpcContext context = RpcContext.getServerContext();
       System.out.println("rest接口");
       System.out.println(context.getProtocol());
       System.out.println(context.getRemoteAddressString());
       System.out.println("-----------------------------------------");
       String userInfo = serverHttpRequest.getHeaders().getFirst(USERINFO);
       return userService.loginService(userInfo);


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] soiz-tor commented on issue #11725: 为什么两次同样的请求,协议却不一样

Posted by "soiz-tor (via GitHub)" <gi...@apache.org>.
soiz-tor commented on issue #11725:
URL: https://github.com/apache/dubbo/issues/11725#issuecomment-1462412065

   > > 
   > 
   > 因为这个protocol是从consumerUrl里取的,当没有进行远程调用时,consumerUrl不会进行设置,所以第一次getServerContext取到的protocol为空。你可以这样调整下顺序,第一次就不为空了:
   > 
   > ```
   > userService.loginService(userInfo)
   > RpcContext context = RpcContext.getServerContext();
   > System.out.println("rest接口");
   > System.out.println(context.getProtocol());
   > System.out.println(context.getRemoteAddressString());
   > System.out.println("-----------------------------------------");
   > String userInfo = serverHttpRequest.getHeaders().getFirst(USERINFO);
   > return userService.loginService(userInfo);
   > ```
   
   好的  谢谢


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] soiz-tor commented on issue #11725: 为什么两次同样的请求,协议却不一样

Posted by "soiz-tor (via GitHub)" <gi...@apache.org>.
soiz-tor commented on issue #11725:
URL: https://github.com/apache/dubbo/issues/11725#issuecomment-1461136323

   > ![image](https://user-images.githubusercontent.com/49740762/223889704-e8e663a2-6731-40eb-976a-4dae22560250.png) 貌似并没有复现这个问题呢
   
   你好,你的第一个打印rest接口下面不就是null吗,第一次的,后面才打印的是consumer
   我的问题就是为什么第一次打印的是null


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] aamingaa commented on issue #11725: 为什么两次同样的请求,协议却不一样

Posted by "aamingaa (via GitHub)" <gi...@apache.org>.
aamingaa commented on issue #11725:
URL: https://github.com/apache/dubbo/issues/11725#issuecomment-1458442760

   Let me see see


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] aamingaa commented on issue #11725: 为什么两次同样的请求,协议却不一样

Posted by "aamingaa (via GitHub)" <gi...@apache.org>.
aamingaa commented on issue #11725:
URL: https://github.com/apache/dubbo/issues/11725#issuecomment-1461115050

   ![image](https://user-images.githubusercontent.com/49740762/223889704-e8e663a2-6731-40eb-976a-4dae22560250.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.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] soiz-tor closed issue #11725: 为什么两次同样的请求,协议却不一样

Posted by "soiz-tor (via GitHub)" <gi...@apache.org>.
soiz-tor closed issue #11725: 为什么两次同样的请求,协议却不一样
URL: https://github.com/apache/dubbo/issues/11725


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org