6 Replies Latest reply on Aug 17, 2007 2:00 PM by andre1001

    Parameters by context

    andre1001

      Hi,

      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!?

      Thanks.

        • 1. Re: Parameters by context
          andre1001

          I've tried with...

          Client:

          Properties properties = new Properties();
          properties.put("lingua","portugues");
          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
            andre1001

            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."

            http://docs.huihoo.com/javadoc/jboss/4.0.1-sp1/server/org/jboss/invocation/InvocationContext.html

            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

              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
                andre1001

                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

                  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
                    andre1001

                    Ok,

                    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,

                    ESBClient1:

                    public static ThreadLocal<String> language = new ThreadLocal<String>();
                    language.set("pt");
                    


                    ESBClient2:

                    public static ThreadLocal<String> language = new ThreadLocal<String>();
                    language.set("en");
                    


                    LanguageInterceptor:

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


                    How can discover the caller class?