11 Replies Latest reply on Apr 12, 2013 5:06 AM by wdfink

    Jboss5.1 Migration to JBoss7.1 Custom-JNDI-Handling

    garydux
      Hello together,

      in our applications we used to define jndi-mappings in jboss.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <jboss>
         <enterprise-beans>
           <session>
             <ejb-name>ContractPortfolioProcessServiceBean</ejb-name>
             <jndi-name>com/fja/ipl/customer/ilis/contractportfolio/ContractPortfolioProcessService</jndi-name>
           </session>
         </enterprise-beans>
      </jboss>

      ithis jboss.xml was placed then in META-INF of that ejb-jar

      So it was easy to lookup for that bean like:

      public static ContractPortfolioProcessService lookupContractPortfolioProcessService()
                     throws NamingException {
                       final Context context = new InitialContext();
                return (ContractPortfolioProcessService ) context.lookup("com/fja/ipl/customer/ilis/contractportfolio/ContractPortfolioProcessService");
      }
      jndi.properties{
      #JBoss
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.provider.url=jnp://localhost:1099
      java.naming.factory.url.pkgs=org.jboss.namingrg.jnp.interfaces
      }

      How can it be made on JBOSS7?

      Due ejb3-spec  in JBOSS7 they can also define jboss-ejb3.xml like this:
      <jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
                      xmlns="http://java.sun.com/xml/ns/javaee"
                      xmlns:iiop="urn:iiop"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd
                         http://java.sun.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-spec-2_0.xsd
                         urn:iiop jboss-ejb-iiop_1_0.xsd"
                      version="3.1"
                      impl-version="2.0">
           <enterprise-beans>
                <session>
                   <ejb-name>CounterBean</ejb-name>
                   <mapped-name>org/jboss/as/quickstarts/ejb/remote/stateful/CounterBean</mapped-name>
                     </session>
           </enterprise-beans>

           <assembly-descriptor>
               <iiop:iiop>
                   <ejb-name>CounterBean</ejb-name>
                   <iiop:binding-name>org/jboss/as/quickstarts/ejb/remote/stateful/CounterBean</iiop:binding-name>
               </iiop:iiop>
           </assembly-descriptor>
      </jboss:ejb-jar>

      It deploys also errorless. But i did not find any dokumentation to lookup my ejb like in example above.

      Who can help me giving a hint in this case?

      How is the jndi.properties-Configuration would be in this case?
        • 1. Re: Jboss5.1 Migration to JBoss7.1 Custom-JNDI-Handling
          sfcoy

          Is lookupContractPortfolioProcessService executed from within the same application that is hosting the EJBs?

          • 2. Re: Jboss5.1 Migration to JBoss7.1 Custom-JNDI-Handling
            garydux

            Hi Stephen,

             

            the code should be client with dependency to JBOSS7_HOME\bin\client\jboss-client.jar.

             

            Thanks for your Question

            • 3. Re: Jboss5.1 Migration to JBoss7.1 Custom-JNDI-Handling
              sfcoy
              • 4. Re: Jboss5.1 Migration to JBoss7.1 Custom-JNDI-Handling
                wdfink

                Additional to the documentation you can find examples in this ejb-clients quickstart

                • 5. Re: Jboss5.1 Migration to JBoss7.1 Custom-JNDI-Handling
                  garydux

                  Thank you Stephen,

                   

                  yes i red it allredy and i know and knew this kind of lookup in JBOSS5.1(with some differences) but in JBOSS5.1 there was also another posibility to do that, just how i described above. Now it is very expensive to do it like default.

                  • 6. Re: Jboss5.1 Migration to JBoss7.1 Custom-JNDI-Handling
                    garydux

                    Hi Wolf-Dieter, thank you. Yes also in ejb-remote there are also examples, but not for my problem. I just want to know can i do it like in JBOSS5.1 by defining the jndi-name in jboss-ejb3.xml for JBOSS7.1? Definitely NO or defenitely Yes? That is my question.

                    • 7. Re: Jboss5.1 Migration to JBoss7.1 Custom-JNDI-Handling
                      wdfink

                      For the moment unfortunately NO, the JNDI name is standardized with the EJB3 spec.

                      I'm not sure whether it will be re-introduced later.

                       

                      I prefer the solution to encapsulate the InitialContext and lookup is a central application API class, so there is only one central point which need to be changed.

                      1 of 1 people found this helpful
                      • 8. Re: Jboss5.1 Migration to JBoss7.1 Custom-JNDI-Handling
                        sfcoy

                        Unfortunately, the direct lookup of global JNDI names has never been a portable operation.

                         

                        One of the original objectives of the JNDI ENC namespace was to alleviate this problem.

                         

                        ie. instead of looking up "com/fja/ipl/customer/ilis/contractportfolio/ContractPortfolioProcessService" in your code, you would lookup something like "java:comp/env/ejb/ContractPortfolioProcessService".

                        "ejb/ContractPortfolioProcessService" then gets mapped to the real global value in deployment descriptors (application-client.xml and jboss-client.xml).

                         

                        For your code migration you would then only need to update the deployment descriptors.

                         

                        Having done a few cross-platform migrations in the past, one of the first things I'd do would be to change any JNDI lookups that did not use the ENC namespace (java:comp/env/...) and then test it in the original environment.

                        • 9. Re: Jboss5.1 Migration to JBoss7.1 Custom-JNDI-Handling
                          garydux

                          Hi Stephen, hi Wolf-Dieter,

                           

                          thanks for the answers. "Unfortunately, the direct lookup of global JNDI names has never been a portable operation." what do you mean poartable operation? Currently we lookup all our ejb's like i described obove(lookup("com/fja/ipl/customer/ilis/contractportfolio/ContractPortfolioProcessService")) and so it run under JBoss5.1. We just define it in jboss.xml for each ejb.

                           

                          Can you give me examples of (application-client.xml and jboss-client.xml) please?

                           

                          Wolf-Dieter made allready a statement, we will probably not migrate to JBOSS7.1 because we have a lot of dynamic code wich based on Convention("com/fja/ipl/core/ilis/contractportfolio/ContractPortfolioProcessService" packagename-interfacename) and so it is deployed and callable on websphere. Further we have also customer-ejb's wich we dynamicaly guess by substitute "core" for "customer".

                           

                          So it seems to be sad.

                           

                          What is in fact with Example: https://github.com/jboss-jdf/jboss-as-quickstart/tree/master/jts/application-component-2
                          there is an jboss-ejb3.xml Definition:

                          <jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"

                                         xmlns="http://java.sun.com/xml/ns/javaee"

                                         xmlns:iiop="urn:iiop"

                                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                                         xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd

                                            http://java.sun.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-spec-2_0.xsd

                                            urn:iiop jboss-ejb-iiop_1_0.xsd"

                                         version="3.1"

                                         impl-version="2.0">

                              <assembly-descriptor>

                                  <iiop:iiop>

                                      <ejb-name>InvoiceManagerEJBImpl</ejb-name>

                                      <iiop:binding-name>jts-quickstart/InvoiceManagerEJBImpl</iiop:binding-name>

                                  </iiop:iiop>

                              </assembly-descriptor>

                          </jboss:ejb-jar>

                           

                          from ApplicationContainer you get this Bean like:

                          @Stateless

                          public class CustomerManagerEJB {

                           

                              @PersistenceContext

                              private EntityManager entityManager;

                           

                              @EJB(lookup = "corbaname:iiop:localhost:3628#jts-quickstart/InvoiceManagerEJBImpl")

                              private InvoiceManagerEJBHome invoiceManagerHome;

                           

                           

                          How would i reach this Bean per lookup() too only with default-name?


                           


                          • 10. Re: Jboss5.1 Migration to JBoss7.1 Custom-JNDI-Handling
                            sfcoy

                            Anything that must be defined in a jboss.xml file, a ibm-ejb-jar-bnd.xml file, weblogic-ejb-jar.xml file, etc is inherently non-portable.

                            1 of 1 people found this helpful
                            • 11. Re: Jboss5.1 Migration to JBoss7.1 Custom-JNDI-Handling
                              wdfink

                              In case of standalone clients I use a seperate API class to handle the IC and lookups. I initialize the class by constructor to decide which server and the parameter for it.

                               

                              If you are inside the server with the dynamic code you may have several options with the naming subsystem and ejb-jar.xml to map the (internal) name to a real one (which migth different for each AS).

                              I suppose that other AS might also change the strategy for JNDI naming according to the ejb3 spec change for standardized JNDI names. (I'm also not happy with the spec I think it will be better to have a standard how to access remote EJB/Transaction and such stuff to be able to run the same code with all different AS by changing some properties only )