Can I pass data in invocation context via remote method calls?
I have two stateless session beans
BeanA and BeanB
I have an interceptor for each bean
BeanAInterceptor for BeanA.methodA
BeanBInterceptor for BeanB.methodB
In BeanAInterceptor, I set some context data.
In BeanA.methodA, I get an handle to BeanB and call BeanB.methodB
In the process, BeanBInterceptor gets called and I want to read the context data
that I set in BeanAInterceptor, but I get null.
Is there any way to pass data via InvocationContext across remote calls if BeanA
and BeanB are deployed in
a. same jvm
b. different jvm
c. in a clustered environment.
In short I want to send data across ejbs, but via interceptors and not
as parameters to method calls.
I am pasting the relevant code below.
@Stateless
public class BeanA {
@Resource
SessionContext ctx;
@Interceptors(BeanAInterceptor.class)
public void methodA() {
BeanBRemote bRemote = ctx
.getBusinessObject(BeanB.class);
bRemote.methodB();
}
}
public class BeanAInterceptor {
@AroundInvoke
public Object interceptA(InvocationContext ctx) throws Exception {
Map<String, Object> ctxData = ctx.getContextData();
ctxData.put("key", "value");
return ctx.proceed();
}
}
@Stateless
public class BeanB {
@Interceptors(BeanBInterceptor.class)
public void methodB() {
//do something
return;
}
}
public class BeanBInterceptor {
@AroundInvoke
public Object interceptB(InvocationContext ctx) throws Exception {
Map<String, Object> ctxData = ctx.getContextData();
Object val = ctxData.get("key"); //I get val as null here
return ctx.proceed();
}
}
Thanks
Arjun