Page 1 of 1

About Question enthuware.oce-ejbd.v6.2.548 :

Posted: Mon Apr 25, 2011 2:40 pm
by ETS User
The spec says:

12.3.1Exceptions
Business method interceptor methods may throw runtime exceptions or application exceptions that are allowed in the throws clause of the business method.

AroundInvoke methods are allowed to catch and suppress exceptions and recover by calling proceed(). AroundInvoke methods are allowed to throw runtime exceptions or any checked exceptions that the business method allows within its throws clause.

So why is it correct to declare Exception in the Interceptor?

I mean you cant cast An Object to an Integer if it holds a String.

Re: About Question enthuware.oce-ejbd.v6.2.548 :

Posted: Mon Apr 25, 2011 8:33 pm
by admin
It is correct because as per Interceptors specification 1.1 , Around-invoke methods have the following signature:

Object <METHOD>(InvocationContext) throws Exception

Re: About Question enthuware.oce-ejbd.v6.2.548 :

Posted: Fri Jun 03, 2016 10:41 am
by clhizerti
I am confused by the simple return type of the interceptor method and did not find any hint in the spec EJB 3.1.

The return type of the AroundInoke method is a simple type:
public double getBalance(int acctid) throws NoAccountException{...}

But the method signature of the AroundInvoke method is Object.
So a reasonable implementation looks like:

@AroundInvoke public Object myAround(InvocationContext ic) throws Exception {  
// do whatever before invoke...
Object obj = ic.proceed();
// do whatever after invoke...
// method returns Object
return obj;
 }

An so the return type of the interceptor method is Object which is not compatible with the declared simple return type double.

From the question it seams obvious that methods with simple types can be intercepted.
My question is why can methods with simple return type be intercepted?

Re: About Question enthuware.oce-ejbd.v6.2.548 :

Posted: Fri Jun 03, 2016 10:50 am
by admin
You can wrap a primitive into a wrapper object which is-a Object.

Re: About Question enthuware.oce-ejbd.v6.2.548 :

Posted: Mon Dec 26, 2016 11:40 am
by Gerardo
Hi,
I have the following doubt:

If for example "MyInterceptor" class is not annotated with @Interceptor and this class has an @AroundInvoke annotated method:
¿Is the "MyInterceptor" class considered an Interceptor without being annotated as @Interceptor?

Thanks in advance.

Re: About Question enthuware.oce-ejbd.v6.2.548 :

Posted: Wed Dec 28, 2016 8:07 am
by admin
@Interceptor annotation is optional if the Interceptors annotation or the EJB deployment descriptor are used to associate the interceptor with the target class.
That means, yes, it is possible for MyInterceptor to considered as an interceptor even without @Interceptor. But you have to associate it with a target bean.