从JAX-RS中的另一个ExceptionMapper调用ExceptionMapper [英] Call ExceptionMapper from another ExceptionMapper in JAX-RS
问题描述
在我的RESTEasy应用程序中,我得到一个java.lang.reflect.UndeclaredThrowableException
,因为正在从一个未在throws子句中声明该异常的方法中抛出一个检查异常.
所以我在写UndeclaredThrowableExceptionMapper
. UndeclaredThrowableException
包装了真正的异常;我调用e.getCause()
进行检索.
然后可以扔掉它还是以某种方式查找适当的ExceptionMapper
来处理它?</p>
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?
推荐答案
您可以尝试在UndeclaredThrowableExceptionMapper
类中添加@Context javax.ws.rs.ext.Providers
字段/属性.
然后使用Providers.getExceptionMapper(Class)
查找要使用的真实异常映射器.
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.
这篇关于从JAX-RS中的另一个ExceptionMapper调用ExceptionMapper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!