3 Replies Latest reply on Jun 19, 2012 12:16 AM by jaikiran pai

    JNDI lookups in AS7 vs JBoss 4.2.3

    Mike Miller Newbie

      Hi,

       

      I am trying to research and size the changes that would be required for us to move from 4.2.3.GA up to AS7.   In looking at the quick start examples and reading some of the docs

       

      I am a bit confused.  Previously, we set the <jndi-name> in the jboss.xml file to "ejb/<service-name>" for all of our EJB2.1 SLSBs.  Now, after reading some of these articles, I am not quite sure how to proceed.   In our application.xml, (for one of our servers) we have 20 ejb jars and 8 wars.  The JNDI string was easy to determine, we just slapped "ejb/" on the front of the remote service name and that was it.   With AS7, when I need to lookup a remote service interface on a remote client, do I have to know exactly which jar the service was deployed from in order to create the correct jndi name, or is there some other (easier) way to generate these strings programmatically at runtime?    Is there another, better way?

       

      Is this part of what the 'distinct name' supposed to do?    If so, then why would that be part of this 'formula' for creating the jndi string?

       

      formula: 'ejb:<appname>/<moduleName>/<distinctName>/<beanName>!<viewClassName>

       

      Additionally, I understand the differences between the remote JNDI lookup and the new ejb client lookup.   What I am trying to find is some documentation that explicitly shows these two approaches and exactly which values need to be in the jndi properities (either the file or added as properties to the InitialContext() constructor).   I will create a small piece of documentation or sample code, if I can get it all down to

       

      • Remote JNDI
        • required properties
      • EJB client lookup
        • required properties
        • 1. Re: JNDI lookups in AS7 vs JBoss 4.2.3
          jaikiran pai Master

          Mike Miller wrote:

           

           

          I am a bit confused.  Previously, we set the <jndi-name> in the jboss.xml file to "ejb/<service-name>" for all of our EJB2.1 SLSBs. 

          AS7 just binds the beans to the EJB 3.1 spec specified JNDI names (even for EJB2.x beans). The spec mandates binding in java:global/ java:module/ java:app/ namespaces. The EJB 3.1 spec has the exact syntax, if you want to take a look. The server even logs these JNDI names when your application is deploying.

           

           

          Mike Miller wrote:

           

          With AS7, when I need to lookup a remote service interface on a remote client, do I have to know exactly which jar the service was deployed from in order to create the correct jndi name, or is there some other (easier) way to generate these strings programmatically at runtime?    Is there another, better way?

          You don't need to know the jar file name nor war file name nor ear file name. Those are just the defaults. Each of which you can override in the appropriate spec/portable deployment descriptors. See the https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI documentation, the section where it explains each of the parts of the JNDI name (i.e. app-name, module-name etc...)

           

           

          Mike Miller wrote:

           

          Additionally, I understand the differences between the remote JNDI lookup and the new ejb client lookup.   What I am trying to find is some documentation that explicitly shows these two approaches and exactly which values need to be in the jndi properities (either the file or added as properties to the InitialContext() constructor).   I will create a small piece of documentation or sample code, if I can get it all down to

           

          • Remote JNDI
            • required properties
          • EJB client lookup
            • required properties

          See https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project

          • 2. Re: JNDI lookups in AS7 vs JBoss 4.2.3
            Mike Miller Newbie

            Okay, after reading some of these pages a 2nd and 3rd time I think I am getting closer to understanding the differences between the remote naming vs the EJB client api as far as programmatically doing the lookup (main piece appears to be the Context.URL_PKG_PREFIXES property set to "org.jboss.ejb.client.naming" and using the "ejb:" namespace.

             

            I reviewed the links you provided but still didn't find anything specific to 'assigning' a jndi name for a deployed ejb.   Are you saying that in order for me to continue the doing naming lookups the way we currently do (slap "ejb/" on the front of the remote service name to create the JNDI name), that I need to use the deployment descriptors?  

             

            If so, then I guess we need to make a tradeoff of keeping that code the same and continue using a deployment descriptor that we shouldn't need if we used whatever is defined in the spec?   As I mentioned before, we have 20 ejb jars and 8 wars and the jars may have many ejbs within the jar - so knowing the 'module' name for every remote service/view is not a good approach for us.

             

            I have not downloaded the EJB 3.1 spec yet to see what it says.

             

            I will test tonight or tomorrow using a deployment descriptor to see if I can get our current approach working.

            • 3. Re: JNDI lookups in AS7 vs JBoss 4.2.3
              jaikiran pai Master

              Mike Miller wrote:

               

              I reviewed the links you provided but still didn't find anything specific to 'assigning' a jndi name for a deployed ejb.

              That's actually a (slightly) different question and isn't actually related to EJB invocations. Previous versions of JBoss AS allowed you to assign arbitrary JNDI names to your EJBs. That's no longer possible in AS7. AS7 only binds to the spec specified JNDI names for beans and that JNDI name follows a specific format. Within that format, there are multiple different "parts" - app name, module name, bean name and bean interface fully qualified name. The app name, module name and bean name all have default values and each of them can be overridden in appropriate spec specified deployment descriptors. So ultimately, you can control parts of the JNDI name, but not the entire JNDI name or it's namespace.