RestEasy Post Process Interceptor chain not traversed when response created by ExceptionMapper

霸气de小男生 提交于 2019-12-22 05:25:49

问题


I am using RestEasy to build up my Restful web services. I have implemented ExceptionMappers to prepare specific exception responses.

I have also implemented MessageBodyWriterInterceptors and a couple of PostProcessorInterceptors.

Issue: All works fine when any resource does not throw any exception. My implementation works as expected. All the post processor interceptors and the message body writer interceptors are called.

But when an exception is thrown from any of the resource methods, the registered ExceptionMappers are called and it is creating the response. But in this case the post processor interceptor chain is not traversed. They are not getting called.

What should I do in this case. Write that interceptor logic in my exception mapper or is there is solution available?


回答1:


Post processors do not get called if an exception is thrown. They are on different, parallel resolution paths:

           / 'Normal' JAX-RS response -> Post Processors -> Message Body Writers
Processing
           \  Exception -> Exception Mappers

If you have logic that needs to be run in both your post processors and exception mappers then you will need to incorporate it in both (preferably through a common, utility class).



来源:https://stackoverflow.com/questions/13937998/resteasy-post-process-interceptor-chain-not-traversed-when-response-created-by-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!