4 Replies Latest reply on Jun 15, 2012 2:31 AM by vedanth

    Invoke remote ejb's with additional custom properties

    vedanth

      Hi All

                I have deployed stateless beans in jboss as 7 and i use a remote ejb client to access the deployed ejb's every thing seems to work fine with the below code.

       

      Remote client code:

       

      Hashtable p = new Hashtable();

                              p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

                              p.put(Context.PROVIDER_URL, "remote://localhost:4547/");

                              p.put("jboss.naming.client.ejb.context", true);

                              p.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

                              p.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");

                              final Context context = new javax.naming.InitialContext(p);

       

      context.lookup("ejb:employee/employeeService//EmployeeManagementImpl!my.tests.EmployeeManagement");

       

      Now i want to set additional properties in the context and get the same properties in the deployed stateless beans.

       

      Set something like context.addToEnvironment("customDataKey", "customDataValue"); in client code

      and get the same properties in deployed beans like

       

      @Resource

      EJBContext ejbContext;

       

      ejbContext.getEnvironment();

      or

      ejbContext.getContextData()

       

      Is it possible to do this???? or any other alternative.....

      Am confused as to how to achieve this.

       

      Thanks in advance...


        • 1. Re: Invoke remote ejb's with additional custom properties
          sfcoy

          What's wrong with the obvious solution of adding method parameters?

          • 2. Re: Invoke remote ejb's with additional custom properties
            vedanth

            Thanks for the reply Stephen,

             

            Let me tell you the actual problem, i want to get the user name from remote client without using the security principal or configuring security domain in ejb using jboss-ejb3.xml.

             

            As you said i could have taken the user name from the method parameters, the problem is i need the user name for audit purpose and am using hibernate envers for that.

            The RevisionEntity class of hibernate envers should be able to get the same user name from the context.

             

            RevisionListener class which will be invoked by hibernate looks some thing like this:

             

            public class ExampleListener implements RevisionListener

            {

                   public void newRevision(Object revisionEntity)

                 {

                   ExampleRevEntity exampleRevEntity = (ExampleRevEntity) revisionEntity;

                   exampleRevEntity.setUsername(USER_FROM_REMOTE_CLIENT);

                 }

            }

             

            Can you please give me some idea on implementing this use case.

            • 3. Re: Invoke remote ejb's with additional custom properties
              sfcoy

              If it were me I'd configure security properly and then inject the current javax.security.Principal where needed.

               

              If you don't want to do this then you could still pass the username as a parameter and then stash it in a ThreadLocal in your session bean. The listener can subsequently recover it from the ThreadLocal. Don't forget to clear it in a finally block after stashing it!

              • 4. Re: Invoke remote ejb's with additional custom properties
                vedanth

                Thank u very much for the suggession stephen, the solution is perfectly working fine in my scenario.