如何对 EJB 客户端隐藏 RuntimeException 详细信息?
我有一个 JEE5 应用程序,它使用(本地)会话 bean 公开服务。
当服务执行期间发生内部错误时,JBoss(5.0.1) 将抛出 RuntimeException 并将其封装在 javax.ejb.EJBTransactionRolledbackException 中。
问题是接收此 EJBTransactionRolledbackException 的客户端应用程序可以访问有关导致运行时异常的详细信息,从而暴露我的应用程序的内部体系结构。 我不想要这样。
相反,我希望 JBoss 始终将公开的会话 bean 抛出的 RuntimeException 封装到单个(简单的)TechnicalException(没有原因)中。
实现这一目标的最佳方法是什么? (使用拦截器?使用 JBoss 配置?)
I have a JEE5 application that exposes services using (local) session beans.
When an internal fault occurs during service execution, a RuntimeException is thrown and encapsulated by JBoss(5.0.1) in a javax.ejb.EJBTransactionRolledbackException.
The problem is that client applications receiving this EJBTransactionRolledbackException can access detailled informations about the cause runtime exception, exposing internal architecture of my application. And I don't want that.
Instead, I would like JBoss to always encapsulate RuntimeException thrown by exposed session beans into a single (and simple) TechnicalException (with no cause).
What's the best way to achieve this ? (Using interceptors ? Using JBoss configuration ?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后,根据之前的回答和我个人的研究,我保留了以下解决方案。
我创建了一个专门用于管理服务器故障的拦截器:
抛出的技术异常扩展了 EJBException 并且不公开原因 RuntimeException:
我在所有公共服务中使用此拦截器:
这是 故障屏障模式。
任何运行时异常都会被捕获、记录,并使用 TechnicalException 向客户端发出故障信号(没有内部详细信息)。 检查的异常将被忽略。
RuntimeException 处理是集中的,并且与任何业务方法分离。
Finally, based on previous answer and my personal researches, I retained the folowing solution.
I've created an interceptor dedicated to manage server faults :
The thrown technical exception extends EJBException and does not expose the cause RuntimeException:
I use this interceptor in all public services :
This is an implementation of the Fault Barrier pattern.
Any runtime exception is catched, logged and a fault is signaled to the client (without internal details) using a TechnicalException. Checked exceptions are ignored.
RuntimeException handling is centralized and separated from any business methods.
任何 RuntimeException 都会扩展 java.lang.Exception。
EJB 规范提供了对 2 种类型的异常(应用程序和系统)的处理。
如果您想抛出系统异常,通常会这样做:
要隐藏系统异常的内部详细信息,只需将: 替换
为:
Hope这就是您正在寻找的。
干杯
Any RuntimeException extends java.lang.Exception.
The EJB spec provides handling for 2 types of exceptions (Application and System)
If you'd like to throw a System Exception, you would usually do it like so:
To hide the internal details of your system exception, simply replace:
with:
Hope this is what you were looking for.
Cheers