Call ExceptionMapper from another ExceptionMapper in JAX-RS

元气小坏坏 提交于 2019-12-10 02:58:26

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3249495/call-exceptionmapper-from-another-exceptionmapper-in-jax-rs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!