Java – the resteasy post process interceptor chain is not traversed when the exception mapper creates a response

I am using resteasy to build my restful web service I have implemented exception mappers to prepare specific exception responses

I also implemented messagebodywriterinterceptors and some postprocessorinterceptors

Problem: when any resource does not throw any exception, everything is normal My achievement works as expected Call all post processor interceptors and message body writer interceptors

However, when an exception is thrown from any resource method, the registered exceptionmappers are called and a response is created In this case, however, the post processor interceptor chain is not traversed They were not called

What should I do in this case, write the interceptor logic in my exception mapper, or is there a solution available?

Solution

If an exception is thrown, the postprocessor is not called They are located on different parallel parsing paths:

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

If your logic needs to run in the postprocessor and exception mapper, you need to combine it into both (preferably through a common utility class)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>