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

Moderator: admin

Post Reply
ETS User

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

Post 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.

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

It is correct because as per Interceptors specification 1.1 , Around-invoke methods have the following signature:

Object <METHOD>(InvocationContext) throws Exception
If you like our products and services, please help us by posting your review here.

clhizerti
Posts: 2
Joined: Thu Oct 01, 2015 10:20 am
Contact:

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

Post 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?

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

You can wrap a primitive into a wrapper object which is-a Object.
If you like our products and services, please help us by posting your review here.

Gerardo
Posts: 16
Joined: Tue Nov 08, 2016 9:39 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests