从JAX-RS中的另一个ExceptionMapper调用ExceptionMapper [英] Call ExceptionMapper from another ExceptionMapper in JAX-RS

查看:236
本文介绍了从JAX-RS中的另一个ExceptionMapper调用ExceptionMapper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆