You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/10/11 03:13:38 UTC
[GitHub] [dubbo] yanan-wyze opened a new issue, #10731: 自定义dubbo filter 不生效
yanan-wyze opened a new issue, #10731:
URL: https://github.com/apache/dubbo/issues/10731
<!-- If you need to report a security issue please visit https://github.com/apache/dubbo/security/policy -->
- [x] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
## Ask your question here
### Environment
* Dubbo version: 3.1.0
* Operating System version: xxx
* Java version: 1.8
### Steps to reproduce this issue
1. 使用Spring boot 2.7.4 整合Dubbo 3.1.0
2. 想在调用端 自定义filter 实现每个请求的隐式参数传递
3. 在服务端自定义filter 实现自定义的权限认证
#### 自定义的filter 内容如下
```java
package io.wxx.appapi.infrastructure.filter;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.BaseFilter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
/**
* @version 1.0
* @classname DubboFilter
* @description 实现调用dubbo 服务时隐式参数的传递
* 参考 https://dubbo.apache.org/zh/docs3-v2/java-sdk/concepts-and-architecture/service-invocation/
*/
@Activate(group = CommonConstants.CONSUMER ,order = 1)
public class DubboFilter implements ClusterFilter {
/**
* Always call invoker.invoke() in the implementation to hand over the request to the next filter node.
*
* @param invoker
* @param invocation
*/
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
SessionObject sessionObject = SessionUtil.getInstance().getSessionObject();
RpcContext.getClientAttachment()
.setAttachment("session", sessionObject)
.setAttachment("trace_id", sessionObject.getTraceId());
return invoker.invoke(invocation);
}
}
```
#### spi 配置文件入下
```
目录 src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter
内容:xxx=io.wxx.appapi.infrastructure.filter.DubboFilter
编译后classes 目录也正确
```
项目正常启动,使用@DubboReference 注解 声明服务,并进行调用,始终无法进入自定义filter;
--
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] yanan-wyze commented on issue #10731: 自定义dubbo filter 不生效
Posted by GitBox <gi...@apache.org>.
yanan-wyze commented on issue #10731:
URL: https://github.com/apache/dubbo/issues/10731#issuecomment-1274170166
找到原因了,被自己蠢哭:
> **注意事项**:如果自定义Filte实现的ClusterFilter ,需要在 META-INF/dubbo/org.apache.dubbo.rpc.cluster.filter.ClusterFilter文件中声明,在META-INF/dubbo/org.apache.dubbo.rpc.Filter 声明是不生效的;
> 若自定义实现的是Filter 需要在 META-INF/dubbo/org.apache.dubbo.rpc.Filter 文件中声明
> 自定义Filter 不能继承BaseFilter,否则在上述两种文件种均不生效(-_-)
--
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] yanan-wyze closed issue #10731: 自定义dubbo filter 不生效
Posted by GitBox <gi...@apache.org>.
yanan-wyze closed issue #10731: 自定义dubbo filter 不生效
URL: https://github.com/apache/dubbo/issues/10731
--
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