3 Replies Latest reply on Mar 4, 2016 1:54 PM by jfisherdev

    Migration Issue :: JBoss 4 with EJB 2.1 to JBoss 7.1

    Debashish Sahu Newbie

      Hi All,

       

      I am in the process of Migration of an Application which was developed in EJB 2.1 and was hosted in JBoss 4.

      We are moving to JBoss 7.1.

       

      I have below files for EJB.

      Remote 

      public interface Authenticator extends javax.ejb.EJBObject

      {

        public boolean validateUser(String loginId,String systemName,String password,Integer organizationId)throws RemoteException,java.sql.SQLException;

      }

       

      Home

      public interface AuthenticatorHome extends javax.ejb.EJBHome

      {

        public Authenticator create() throws CreateException,RemoteException;

      }

       

      Bean

      public boolean validateUser(String loginId,String systemName,String password,Integer organizationId)throws RemoteException,java.sql.SQLException

      {

        System.out.println("AuthenticatorBean::validateUser() method called");

        return true;

      }

       

      ejb-jar.xml

      <ejb-jar>

         <enterprise-beans>

            <session>

                <ejb-name>AuthenticatorSessionEJB</ejb-name>

                <home>com.myapp.authenticator.AuthenticatorHome</home>

                <remote>com.myapp.authenticator.Authenticator</remote>

                <ejb-class>com.myapp.authenticator.AuthenticatorBean</ejb-class>

             <session-type>Stateless</session-type>
             <transaction-type>Container</transaction-type>
            </session>

         </enterprise-beans>

      </ejb-jar>

       

      jboss.xml

      <jboss>

        <enterprise-beans>

            <session>

                 <ejb-name>AuthenticatorSessionEJB</ejb-name>

                 <jndi-name>AuthenticatorSessionJNDI</jndi-name>

            </session>

        </enterprise-beans>

      </jboss>

       

      EJB Client class

      final Hashtable<String, String> p = new Hashtable<String, String>();

      p.put( Context.PROVIDER_URL, "remote://127.0.0.1:4447" );

      p.put( Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming" );

      p.put( Context.SECURITY_PRINCIPAL, "appuser" );

      p.put( Context.SECURITY_CREDENTIALS, "appuser123" );

      p.put( Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory" );

      ctx =new javax.naming.InitialContext(p);

       

      String jndiString = "java:app/AuthenticatorSessionJNDI";

      ref = ctx.lookup(jndiString);

      Authenticator statelessAuthenticator = (Authenticator) ref;

      statelessAuthenticator.validateUser("1", "1", "1", 1);

       

      I have gone through some tutorials regarding the strict JNDI naming conventions used for JBoss 7.1. As per the link https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project

       

      I am unable to invoke the Bean. I guess this is due to the JNDI configuration which I have done in files ejb-jar.xml, jboss.xml and EJB Client class.

       

      Please let me know if anything else I have to do to make it work. This is a serious show stopper for me now and I am not able to proceed further because of this.

       

      Thank you and have a nice day

        • 1. Re: Migration Issue :: JBoss 4 with EJB 2.1 to JBoss 7.1
          jfisherdev Apprentice

          I am currently working on a somewhat similar migration--going from JBoss AS 4.2.2 to WildFly 9.0.2, using EJB 2.1, and traditional remote JNDI for EJB access (using remote-naming and not using the JBoss/WildFly EJB client). I am not sure that I can provide a solution to your issue, I do have a few suggestions based on what I have dealt with.

           

          Even though you may not be using EJB 3.1, with JBoss AS 7, the JNDI names for the EJBs need to comply with the EJB 3.1 specification.

           

          From what I have read, the jndi-name element in the jboss.xml descriptor that previously allowed you to set the jndi-name of the EJB is not supported in JBoss AS 7+. This means that the JNDI name used to lookup the EJB will almost certainly not be "AuthenticatorSessionJNDI" in this case.


          You will want to check the JNDI name the EJB is bound to when you deploy your EJB, and base the JNDI name used for the lookup on that. I believe this is usually recorded in the server.log or the management console may have a JNDI view that can be used to find this.


          I am not sure how you are packaging/deploying the EJB, but for the sake of example, let us suppose that the EJB resides in an EJB jar called, myAppEJB.jar, which is packaged in an EAR, called myApp.ear. We will also assume that the application and module names are not being overridden in any descriptors (a Java EE 6+ feature). This means that the app name will be myApp and the module name will be myAppEJB for the EJB component.


          In this case, the base JNDI name for the EJB would be myApp/myAppEJB/AuthenticatorSessionEJB!<bean-interface>, where <bean-interface> is the fully qualified class name of the interface that exposes the EJB to the client, which I suspect would be either the home or remote interface (in my case, it was the home interface, which was used to create an instance of the remote interface).


          Unlike JBoss 4, where the same JNDI name could be used regardless of what context the EJB was being accessed from, JNDI name used to lookup the EJB differs depending on if the EJB is being accessed from a remote client or locally. If you are looking up the EJB from a remote client, like it appears you are in your example, the base name of myApp/myAppEJB/AuthenticatorSessionEJB!<bean-interface> should work. If you are looking up the EJB locally--on the same server where the EJB is deployed--you will need to lookup the EJB under one of the EJB 3.1 portable namespaces. In my experience, looking it up under the java:global namespace has been the most reliable (the JNDI name would be java:global/myApp/myAppEJB/AuthenticatorSessionEJB!<bean-interface>).


          I hope that this is helpful.



          1 of 1 people found this helpful
          • 2. Re: Migration Issue :: JBoss 4 with EJB 2.1 to JBoss 7.1
            Debashish Sahu Newbie

            Hi jfisherdev,

             

            Thank you so much for the detailed explanation and it has helped me a lot to resolve my issue.

             

            As the Migration was from JBoss 4 on EJB 2.x to JBoss 7.1, which supports EJB 3X,  I have the major challenge of migration with least possible changes.

            Finally after going through all the references and your mail, I was able to invoke my session beans as follow,

             

            Step 1.

                 My EJB 2x has Home and Remore. and in traditional 2x we invoke Home first through lookup and then Remote.

                  However in EJB 3x, we invoke directly the Remote Interface and invoke the business logic on that.

             

                  As I had to minimize the code changes I did it in the below way,

                 String AuthenticatorSessionJNDI = "ejb:EARApplication/EJBModule/AuthenticatorSessionEJB!com.myapp.myapp123.authenticator.AuthenticatorHome";

                 Object ref = ctx.lookup(AuthenticatorSessionJNDI);

                 AuthenticatorHome authenticatorHome = AuthenticatorHome)javax.rmi.PortableRemoteObject.narrow(ref, AuthenticatorHome.class);

                 Authenticator authenticator = authenticatorHome.create();

                 authenticator.validateUser(loginId,systemName,password,orgId);

             

            ** I was not sure that I can invoke the Home object through JNDI lookup as we did in 2x , now in 3x. however we did it and it is working fine. :-)

             

            Step 2 .

                 Now the second challenge is that how to call the 2x Entity beans from the session bean. In JBoss 4, it was the normal way of jndi lookup from session bean. However with the

                  EJB 3.1 specification in place now, we need to have the jndi string as per below standard,

                 String JNDI = "ejb:EARApplication/EJBModule/BeanName!com.myapp.myapp123.authenticator.AuthenticatorHome";

             

                 However the Issue here is that Entity Beans are not exposed/mentioned in the application.xml file in the ear structure. However the session beans were declared there and

                 hence it was possible to have a lookup with the above string where as the entity beans are not declared over there.

                 As the entity beans are not mentioned in application.xml file, we are getting Name Not found Exception.

             

                 Please suggest me if you have encountered similar issue and how to resolve the same.

             

            Regards

            Debashish

            • 3. Re: Migration Issue :: JBoss 4 with EJB 2.1 to JBoss 7.1
              jfisherdev Apprentice

              I am glad that I was able to provide some useful information.

               

              Unfortunately, I will not be of much help with the entity bean issue(s), as the applications I am migrating do not use them and my knowledge of them is very limited. I do not know how you are running JBoss AS 7--standalone mode or domain mode (I have only dealt with standalone mode)--however, I seem to remember reading that EJB 2.1 entity beans are not supported by the default standalone configuration and that the standalone-full configuration is recommended (although, the default standalone configuration could probably be adjusted to support this).

               

              I will provide links to some resources that I have found useful and may be able to help you.

               

              You may have already looked at this, but this looks like it would be a good guide for an AS 4 to AS 7.1 migration. The rest of the AS 7.1 documentation is useful as well:

               

              How do I migrate my application from AS5 or AS6 to AS7 - JBoss AS 7.1 - Project Documentation Editor

               

              Even though this is a guide for JBoss EAP migration, I have found it useful:

               

              3.2.11. EJB 2.x Changes

               

              Here is a blog post by jsebfranck that provides an example of EJB 2.1 session and entity beans on JBoss AS 7.1. There is a link in the post to source code in the project I would recommend looking at if you are interested.

               

              Jean-Sébastien Franck Programming Blog: EJB 2 on Jboss 7.1 example

               

              I found the link to the blog post in this discussion:

               

              How to configure Ejb 2 entities on JBoss 7.1?

               

              I hope that this helps and that you are able to resolve these migration issues.