Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call ExceptionMapper from another ExceptionMapper in JAX-RS

In my RESTEasy application I'm getting a java.lang.reflect.UndeclaredThrowableException, because a checked exception is being thrown from a method that doesn't declare the exception in the throws clause.
So I'm writing an UndeclaredThrowableExceptionMapper. The UndeclaredThrowableException wraps the real exception; I call e.getCause() to retrieve it.
Can I then throw it or somehow look up the proper ExceptionMapper to handle it?

like image 819
Mark Lutton Avatar asked Jul 14 '10 18:07

Mark Lutton


1 Answers

You can try adding a @Context javax.ws.rs.ext.Providers field/property to your UndeclaredThrowableExceptionMapper class.
Then use Providers.getExceptionMapper(Class) to look up the real exception mapper you want to use.

like image 79
Bryant Luk Avatar answered Sep 20 '22 05:09

Bryant Luk