bert82503 commented on issue #11716:
URL: https://github.com/apache/dubbo/issues/11716#issuecomment-1918689160

   【背景】业务应用中会自定义`Filter`,里面会使用`RpcContext.getServiceContext().isConsumerSide()`。
   
   
`dubbo-3.2.10`还有出现这个异常,原因是`RpcContext.getServiceContext().getUrl()`返回是null,所以调用`RpcContext.getServiceContext().isConsumerSide()`报NPE。
   
   根因是`context=ContextFilter`没有最先执行,`dubbo-3.2.10.jar`好像不会自动加载这些`Filter`。
   
   <img width="892" alt="image" 
src="https://github.com/apache/dubbo/assets/1811851/13e2d80b-64ff-463b-b274-26ac9b9f819d";>
   
   <img width="1023" alt="image" 
src="https://github.com/apache/dubbo/assets/1811851/fa6ef112-3a8e-41f1-b437-6d4403621580";>
   
   ```java
   @Activate(group = {CommonConstants.PROVIDER, CommonConstants.CONSUMER}, 
order = -1)
   public class DubboAccessLogFilter implements Filter {
   
       @Trace
       public Result invoke(Invoker<?> invoker, Invocation invocation) throws 
RpcException {
   
           RpcContext rpcContext = RpcContext.getServiceContext();
   
           try {
               // ...
               if (rpcContext.isProviderSide()) {
                   // ...
               } else {
                   // ...
               }
   
           } catch (Throwable e) {
               // ...
           }
           Result result = invoker.invoke(invocation);
           return result;
       }
   
   }
   ```
   


-- 
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-unsubscr...@dubbo.apache.org

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


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

Reply via email to