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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With