Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 934
Bhaskar Avatar asked Dec 18 '12 17:12

Bhaskar


1 Answers

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).

like image 157
Perception Avatar answered Nov 14 '22 22:11

Perception