Consider the following code for an AroundInvoke method of an interceptor InterceptorA class:
@AroundInvoke
public Object iam1(InvocationContext ic) throws Exception{
System.out.println("In iam1");
Object obj = ic.proceed();
return obj;
}
This interceptor is applied to the following bean :
public class CountryCodeBean implements CountryCodeBeanLocal {
@Interceptors({InterceptorA.class})
@ExcludeClassInterceptors
@ExcludeDefaultInterceptors
public String getCode(String country){
return country+"_CODE";
}
@AroundInvoke
public Object selfAround(InvocationContext ic) throws Exception{
System.out.println("In selfAround");
return ic.proceed();
}
}
can you explain please way the selfAround interceptor is call?
About Question enthuware.oce-ejbd.v6.2.397 :
Moderator: admin
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.397 :
I am not sure if I understand your question but basically, whenever any method of the bean is called by a client, the container will actually call the selfAround() method of the bean instance. Within this method, you can put statements that you want to execute before the call is transferred to the actual method that we called by the client and then transfer the call using ic.proceed(). Once the ic.proceed() call returns, you can put whatever statements you want to execute after the actual method execution.
Thus, it gives you an ability to execute code before as well as after the actual bean method is executed. Hence the name aroundInvoke.
HTH,
Paul.
Thus, it gives you an ability to execute code before as well as after the actual bean method is executed. Hence the name aroundInvoke.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Fri Sep 28, 2012 12:56 am
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.397 :
Could you please give clarifications regarding followings.
1. If the bean provider wants to exclude executing @AroundInvoke interceptor method defined in the bean class itself(selfAround() method) but not the interceptor method defined in InterceptorA, for a certain business method (Lets say getCode() method in here). how can he do it?
2. What about the other way round? Can we just annotated with @Interceptors without interceptor class to get only the bean defined @AroundInvoke method executed?
Thanks in advance,
1. If the bean provider wants to exclude executing @AroundInvoke interceptor method defined in the bean class itself(selfAround() method) but not the interceptor method defined in InterceptorA, for a certain business method (Lets say getCode() method in here). how can he do it?
2. What about the other way round? Can we just annotated with @Interceptors without interceptor class to get only the bean defined @AroundInvoke method executed?
Thanks in advance,
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.397 :
I don't think it is possible to do what you are asking. The whole point of declaring a general class interceptor method for the whole class is to make it execute for all the methods. If you want a particular interceptor to execute for all except one method, you can use @Interceptors annotation for the methods for which you want to execute it.weera.zap wrote:Could you please give clarifications regarding followings.
1. If the bean provider wants to exclude executing @AroundInvoke interceptor method defined in the bean class itself(selfAround() method) but not the interceptor method defined in InterceptorA, for a certain business method (Lets say getCode() method in here). how can he do it?
If you use @Interceptors, the @AroundInvoke of that interceptor class will be invoked. It is independent of the method annotated with @AroundInvoke of the bean class itself.2. What about the other way round? Can we just annotated with @Interceptors without interceptor class to get only the bean defined @AroundInvoke method executed?
Thanks in advance,
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 358
- Joined: Fri Nov 29, 2013 8:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.397 :
In the previous explanation for question v6.2.2.395, it says the return type of the interceptor method must match with the return type of the method being intercepted.
For example, the interceptor returns an Integer while the method being intercepted returns a String.
This is not a valid example.
But in this question, the interceptors return object type while the getCode return a string type.
Why this is still valid?
For example, the interceptor returns an Integer while the method being intercepted returns a String.
This is not a valid example.
But in this question, the interceptors return object type while the getCode return a string type.
Why this is still valid?
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.397 :
Actually, instead of "must match", it should says must be compatible. Interceptor specification (page 5 under title Method Interceptors) says:
Paul.
HTH,Around-invoke methods have the following signature: Object <METHOD>(InvocationContext) throws Exception
Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 31 guests