JAX-RS ExceptionMapper does not work for any Exception other than java.lang.Exception

1k Views Asked by At

I am using spring boot along with JAX-RS and Jersey. I have defined different kinds of ExceptionMappers for different types of Exceptions and one ExceptionMapper as the Fallback mapper just to log the exception properly and send back the correct response to clients. On unit test level everything works fine and the the proper ExceptionMapper is called for its corresponding Exception using the

<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-inmemory</artifactId>

However on the running application (embedded in Jetty) only the Fallback mapper which catches the java.lang.Exception is called and all others are ignored. I am using annotation scanning for everything and the FallbackExceptionMapper and MyCustomExceptionMapper are both in the same package and annotated with @Provider. Any idea why other exception mappers like MyCustomExceptionMapper do not work?

Update: I changed the type of the Exception from java.lang.Exception in my FallbackExceptionMapper to MyCustomException and this also is not called. Seems like that no other Exception other than the root Exception (java.lang) is caught by the mapper.

Update2: by defining the @Context javax.ws.rs.ext.Providers providers in my FallbackExceptionMapper and the method providers.getExceptionMapper(MyCustomException.class) I do see that it returns an instance of MyCustomExceptionMapper but I'm wondering why Jersey does not call it! Any idea??

0

There are 0 best solutions below