Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReaderInterceptor不起作用 #30

Closed
kazaff opened this issue Mar 10, 2015 · 5 comments
Closed

ReaderInterceptor不起作用 #30

kazaff opened this issue Mar 10, 2015 · 5 comments

Comments

@kazaff
Copy link

kazaff commented Mar 10, 2015

@Priority(Priorities.USER)
public class DemoInterceptor implements ReaderInterceptor, WriterInterceptor {

    public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
        System.out.println("Reader interceptor invoked");

        return context.proceed();
    }

    public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
        System.out.println("Writer interceptor invoked");
        context.proceed();
    }
}

按照官方例子,却发现ReaderInterceptor不起作用,只打印出"Writer interceptor invoked",断点也无法捕获在对应位置,可以证明确实是没有调用。

请问如何解决?

@kazaff
Copy link
Author

kazaff commented Mar 12, 2015

这个bug还没空来看?你跑过demo吗,demo里面难道也调用不到?--- by @li-shen from QQ

是的,也调不到,我追源码,restprotocol是把extend的值统一交给RESTEasy框架来管理,应该是靠后者来实现jax-rs规范吧?也就是说问题不在dubbox,而是要从RESTEasy下手吧?

@kazaff
Copy link
Author

kazaff commented Mar 14, 2015

经过我自己的测试,发现单独使用resteasy,最新版本下也存在这个问题,不过目前看来,更换成官方提供的preProcessInterceptor是可以满足要求的,具体细节还需要看一下resteasy源码,不过该拦截器接口已经被官方提示不建议使用。如下代码

public class MyPreProcessInterceptor implements PreProcessInterceptor {
    public ServerResponse preProcess(HttpRequest request, ResourceMethodInvoker method) throws Failure, WebApplicationException{

        System.out.println("Reader interceptor invoked");
        return null;
    }
}

官方文档上解释的也很笼统,我在ResourceMethodInvoker源码中甚至根本就不没有找到对应的readerInterceptors声明(只有writerInterceptors),而且发现preProcessInterceptor被当做Filter来处理了,好乱啊~~

根据文档中下面这句话:

ReaderInterceptors wrap around the execution of MessageBodyReaders.

我还尝试了使用POST以表单形式提交参数,试图测试是否可以触发,结果也是徒劳的~

@li-shen
Copy link

li-shen commented Mar 25, 2015

我看了一下,这个不是bug。在不需要做反序列化的比如get场景,reader inteceptor肯定就不会被调用。

@li-shen li-shen closed this as completed Mar 25, 2015
@kazaff
Copy link
Author

kazaff commented Mar 25, 2015

如果做认证的话,就不能用这个拦截器了~
那一般都应该考虑如何做呢?

@li-shen
Copy link

li-shen commented Mar 26, 2015

用filter吧,不用interceptor。另外dubbo自己也有filter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants