RESTEasy 隐藏了真正的异常
我的代码抛出异常(由于错误)。在日志中,我看到:
org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:323)
at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:199)
at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:175)
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:529)
etc...
实际异常的堆栈未记录。如果我将代码包装在 try..catch 中并记录捕获的异常,我可以验证我的代码是否有错误。我的系统中没有其他库可以做到这一点,即使对于深度包装的异常也是如此,所以这一定是 RESTEasy 中的问题,也许是 UnhandledException
中的问题?
有没有办法绕过这种行为?我想不出它应该隐藏实际异常的充分理由。
- Jetty
- Java
- Spring 3.0.3
- RETEasy 2.0.1GA
My code is throwing an exception (due to a bug). In the log, I see:
org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:323)
at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:199)
at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:175)
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:529)
etc...
The stack of the actual exception is not logged. If I wrap my code in a try..catch
and log the caught exception I can verify that my code is at fault. No other library in my system does this, even for deeply-wrapped exceptions, so it must be a problem in RESTEasy, perhaps in UnhandledException
?
Is there a way to get around this behavior? I can't think of a good reason why it should be hiding the actual exception.
- Jetty
- Java
- Spring 3.0.3
- RESTEasy 2.0.1GA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你有异常映射器吗?请参阅 RESTEasy 文档中的第 27 章“异常处理”。
我使用 RESTEasy 将 REST 添加到现有系统,而现有系统有一种奇怪的方式将异常包装在异常中,因此我的 ExceptionMappers 做了很多解包工作。
Do you have an ExceptionMapper? See Chapter 27, Exception Handling, in the RESTEasy documentation.
I used RESTEasy to add REST to an existing system, and the existing system has a weird way of wrapping exceptions within exceptions, so my ExceptionMappers do a lot of unwrapping.
我不使用 RESTeasy,但它似乎是 RESTful Web 服务的调度机制。
假设是这种情况,那么它与其他库有不同的设计目标:它们是从您的应用程序调用的,但 RESTeasy 负责调用您的应用程序。因此,它必须保护自己免受编写不良的代码的影响。 “最后一搏”异常处理程序是执行此操作的常见方法;你会在 Swing 中看到同样的事情。
是否应该记录未捕获的异常是另一回事。也许有一个配置选项可以做到这一点。或者也许您需要添加几行代码。毕竟它是开源的,我相信维护者会欣赏一份写得很好的带有补丁的错误报告。
I don't use RESTeasy, but it appears to be a dispatch mechanism for RESTful web services.
Assuming this is the case, then it has different design goals from other libraries: they are invoked from your application, but RESTeasy is responsible for invoking your application. It therefore has to protect itself from poorly written code. A "last ditch" exception handler is a common way to do this; you'll see the same thing in Swing.
Whether or not it should log the uncaught exceptions is a different matter. Perhaps there's a configuration option to do this. Or perhaps you need to add a couple lines of code. It is open-source, after all, and I'm sure the maintainers would appreciate a well-written bug report with patch.
是的,您的异常被 RESTeasy 吞没,包装在 UnhandledException 中并记录下来。但是您的异常太深了,无法包含在堆栈跟踪中。
要将异常打印到控制台,您可以将以下内容附加到“WEB-INF/classes/logging.properties”
Yes, your exception is swallowed by RESTeasy, wrapped in UnhandledException and logged. But your exception lies too deep within to be included in the stacktracs.
To print out your exception to the console, you could append the following to 'WEB-INF/classes/logging.properties'