0

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??

LAC
  • 852
  • 4
  • 11
  • 31
  • I imagine it has to do with where the exception is being thrown. Have to tested with throwing from different locations. If it works being thrown from different locations, then let us know the location it's being thrown from, and the response you are getting. – Paul Samsotha Nov 24 '15 at 02:11
  • @peeskillet actually I found out last night that the exceptions are caught by my mapper and it is working but it does not work in this case because Spring swallows my exception and throws it's own exception because of the rollback and this is the reason why my fallback catches them. I made another post here http://stackoverflow.com/questions/33881648/springs-transactioninterceptor-overrides-my-exception – LAC Nov 24 '15 at 18:54

0 Answers0