从 EJB 拦截器抛出异常
假设我有一个看起来像这样的拦截器:
public class AuthorizationInterceptor {
Logger log = Logger.getLogger(getClass().getName());
@AroundInvoke
private Object authorize(InvocationContext ic) throws Exception{
// ... some other logic for authorization
if (!allowedMethods.contains(ic.getMethod().getName())){
log.info("Authorization failed. Preparing to throw exception");
throw new AuthException("Authorization failed for method " +
ic.getMethod().getName());
}
return ic.proceed();
}
}
它应用于与我的 EJB 不同的方法。
我通常希望将异常传递给调用客户端,就像所有正常的 EJB 异常一样。
显然,如果我从拦截器中抛出它,就不会发生这种情况......它甚至没有登录到服务器;就像它从未被抛出一样,尽管它是这样的 - return 语句从未被执行。
我做错了什么?
我用的是GF 3.0.1
Let's say I have an interceptor that looks smth like this:
public class AuthorizationInterceptor {
Logger log = Logger.getLogger(getClass().getName());
@AroundInvoke
private Object authorize(InvocationContext ic) throws Exception{
// ... some other logic for authorization
if (!allowedMethods.contains(ic.getMethod().getName())){
log.info("Authorization failed. Preparing to throw exception");
throw new AuthException("Authorization failed for method " +
ic.getMethod().getName());
}
return ic.proceed();
}
}
which is applied to different methods from my EJBs.
I would normally expect the exception throed to be passed to the invoking client, like all normal EJB exceptions.
Apparently this doesn't happen if I throw it from an Interceptor... It's not even logged on the server; like it's never thrown although it is - the return statement is never executed.
What am I doing wrong?
I'm using GF 3.0.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对这个问题进行一番搜索后,我发现 这篇 SO 帖子 几分钟前得到了答复。引用:
问题作者是回答并接受这个答案的同一个人,所以我猜他正在尝试解决与您相同的问题,并得出了无法完成的结论。
After searching a bit for this issue, I found this SO post which was answered a few minutes ago. Quote:
Question author is the same person who answered and accepted this answer, so I guess he was trying to solve the same issue as you and came to conclusion that it cannot be done.
这里有一些可以尝试的事情:
Here are a couple of things to try: