2 Replies Latest reply on Jun 7, 2012 4:25 AM by dahm

    How do tell if code is executing inside the app server?

    dabramov

      Hi,

       

      We have some utilty code which returns JNDI Contexts to the applications which need one, say to lookup the JMS ConnectionFactory. If the code is executing inside the app server all I would need to do is create a new InitialContext(). If the utility is executing out of process it needs to set the factory, provider URL, etc.

       

      I've tweaked the JNDI named of the ConnectionFactory/RemoteConnectionFactory so they can be looked using the same names whether the Context is local or remote. However, I'm not sure how to have the utlity class determine the appropriate way to create the Context - and therefore hide this from the application code.

       

      Is there something I can check to figure this out? The less hackish the better, but at least is will be contained inside the utility class.

       

      Thanks,

      -Dan

        • 1. Re: How do tell if code is executing inside the app server?
          raydecampo

          Isn't this what the property system InitialContext is set up to use is for?  What I'm getting at is, is there some reason not to use the built in mechanisms in InitialContext to get the right InitialContext for well, the right context?

          • 2. Re: How do tell if code is executing inside the app server?
            dahm

            Hi,

             

            we have similar code and the simplest way is to refactor your class so that the InitialContext is injected upon construction. I.e., pass it in the constructor.

            The client determines then how to create the context.

             

            a) Either you call your utility class from a Session Bean: use new InitialContext()

            b) From some remote client: Have a jndi.properties file or use new InitialContext(props)

             

            Cheers

               Markus