4 Replies Latest reply on Sep 13, 2012 3:46 AM by Tomasz Banas

    Passing data between ClientInterceptor and Interceptor

    Tomasz Banas Newbie

      Hi. I must pass some data between two ears.

      I have two Interceptors. ClientSideInterceptor class:


      public class ProxyInterceptor implements EJBClientInterceptor{
                private static Object testCtx;
                public void handleInvocation(EJBClientInvocationContext ctx) throws Exception {
                          ctx.getContextData().put("one", getSessionContext());
                public Object handleInvocationResult(EJBClientInvocationContext ctx) throws Exception {
                          return ctx.getResult();
                private Object getSessionContext() {
                          if (testCtx != null)
                                    return testCtx;
                          return "no working";
                 public static void setTestSessionContext(Object ctx){
                          testCtx = ctx;


      and ContainerInterceptor, which is getting data from ContextData.


      public class ContainerInterceptor{
                public Object invoke(InvocationContext inv) throws Exception {
                          Object ctx = inv.getContextData().get("one");
                          System.out.println("ContainerInterceptor" + "  " + ctx);
                          // put current context
                          return inv.proceed();


      I must pass ContextData between two ears. In first ear I have HelloWorldBean in which i lookup ClientBean from another ear. And my problem is that i must pass SessionContext(for simplicity String in this example) between this two ears.



      public class HelloWorldBean implements HelloWorld {
        public String sayHello() throws NamingException{
                          System.out.println("[HelloWorldBean hello]");
                          Properties props = new Properties();
                          props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
                          props.put(Context.PROVIDER_URL, "remote://localhost:11101");
                          Context context = new InitialContext(props);
                          EJBClientContext.requireCurrent().registerInterceptor(0x99999, new ProxyInterceptor());
                          ProxyInterceptor.setTestSessionContext("it's working");
                          Client client = (Client) context.lookup("Interceptor2/Client//ClientBean!client.Client");
                          return "HelloWorld";


      In ejb-jar i have:

      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"


      So, I'm registering ClientSideInterceptor and pass to him my String, then i lookup for ClientBean. The problem is when i run client.saySomething() and ContainerInterceptor is start, there is no String in Object ctx = inv.getContextData().get("one"); Where is the problem?