Reputation: 5406
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
Upvotes: 5
Views: 3251
Reputation: 47183
After searching a bit for this issue, I found this SO post which was answered a few minutes ago. Quote:
I don't think there is a correct way to do that. Methods should throw only the exceptions they declared, and an interceptor shouldn't add a new one. My personal case got fixed by adding an error code to our default exception which is thrown by all methods.
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.
Upvotes: 2
Reputation: 7529
Here are a couple of things to try:
1. Check that the authorize(...) method is called.
2. Try making the authorize(...) method public instead of private.
3. Check that the EJB has an annotation like this:
@Interceptors(AuthorizationInterceptor.class)
Upvotes: 1