6 Replies Latest reply on Aug 17, 2007 2:00 PM by Andre Fernando Salvati

    Parameters by context

    Andre Fernando Salvati Novice


      I'm a beginner and my question is simple (i guess :) ).

      I need a language parameter in all my EJB methods, but I don't want to polute their signatures. Is there a way to pass it by context!? I spent the day reading documentation and found stuff about Interceptors and InvocationContext class. Am I in the right way?

      Can someone give an example!?


        • 1. Re: Parameters by context
          Andre Fernando Salvati Novice

          I've tried with...


          Properties properties = new Properties();
          Context c1 = new InitialContext(properties);

          EJB (Session Stateless):
          @Resource SessionContext ctx;
          String x = ctx.getEnvironment().getProperty("lingua");

          but getEnvironment() is deprecated...

          org.jboss.soa.esb.actions.ActionProcessingException: Unexpected invocation target exception from processor
           at org.jboss.soa.esb.listeners.message.ActionProcessorMethodInfo.processMethods(ActionProcessorMethodInfo.java:127)
           at org.jboss.soa.esb.listeners.message.OverriddenActionLifecycleProcessor.process(OverriddenActionLifecycleProcessor.java:74)
           at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.process(ActionProcessingPipeline.java:262)
           at org.jboss.soa.esb.listeners.message.MessageAwareListener$1.run(MessageAwareListener.java:297)
           at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
           at java.lang.Thread.run(Unknown Source)
          Caused by: javax.ejb.EJBException: Deprecated
           at org.jboss.ejb3.BaseSessionContext.getEnvironment(BaseSessionContext.java:265)
           at com.buscape.cep.facade.CepFACADEBean.persiste(CepFACADEBean.java:64)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)

          Any tip?

          • 2. Re: Parameters by context
            Andre Fernando Salvati Novice

            The API says about InvocationContext class:

            "Essentially we can carry ANYTHING from the client to the server, we keep a series of redifined variables and method calls to get at the pointers. But really it is just a repository of objects."


            How can I accomplish this!?

            Binding parameters into the context and adding an interceptor in order to inject the parameter!?

            context.bind("lingua", "portugues");

            • 3. Re: Parameters by context
              Bill Burke Master

              There is no standard way to pass contextual information. You would have to use JBoss proprietary client interceptors for remote invocations, or, if this is all local invocations, just use a java.lang.ThreadLocal.

              • 4. Re: Parameters by context
                Andre Fernando Salvati Novice

                Hi Bill,

                thanks for your reply.

                Today these EJBs are local, but in the future they can be remote.

                The big question is:
                How can I get a field's content from the calling instance (ESB) on my client interceptor and put it inside a Invocation object!?

                • 5. Re: Parameters by context
                  Bill Burke Master

                  look at how the client side security interceptor works. You'll have to put the field content in a ThreadLocal so that you can propagate it to the client side interceptor.

                  • 6. Re: Parameters by context
                    Andre Fernando Salvati Novice


                    org.jboss.proxy.SecurityInterceptor gets definitions from System, SecurityAssociation, etc...

                    How can I get a variable from a client who can be any class with a ThreadLocal attached to it!?

                    For example,


                    public static ThreadLocal<String> language = new ThreadLocal<String>();


                    public static ThreadLocal<String> language = new ThreadLocal<String>();


                    ctx.getContextData().put("lingua", ??????????.language);

                    How can discover the caller class?