5 Replies Latest reply on Jan 24, 2015 11:55 AM by Wolf-Dieter Fink

    JNDI Names in auto-generated classes

    Haricharan Shetty Newbie

      Hi,  I am trying to migrate an application from weblogic 8 to jboss. I am getting the following error-

       

      12:28:22,666 SEVERE [xx.ks.inventory.web.SetupServlet] (Thread-164) xx.ks.inventory.web.SetupServlet#Setup failed: xx.devenv.exceptions.ServiceException: javax.naming.NameNotFoundException: java:comp/env/ejb/DLocal: xx.devenv.exceptions.ServiceException: javax.naming.NameNotFoundException: java:comp/env/ejb/DLocal        at packagexx.ejb.DEjbDelegate$DLocalProxy.<init>(DEjbDelegate.java:1870) [ks_inventory.jar:2] at xx.ks.inventory.ejb.DEjbDelegate.<init>(DEjbDelegate.java:42) [ks_inventory.jar:2.9.0]at xx.ks.inventory.web.SetupServlet$ActionThread.run(SetupServlet.java:67) [ks_inventory.jar:2]

      at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_60-ea]Caused by: javax.naming.NameNotFoundException: java:comp/env/ejb/DLocal at org.jboss.as.naming.InitialContext$DefaultInitialContext.findContext(InitialContext.java:195) at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:239

      at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:183)

      at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)

      at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_60-ea]

      at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_60-ea]

      at xx.ks.inventory.ejb.DUtil.lookupHome(DUtil.java:27) [ks_inventory.jar:2]

      at xx.ks.inventory.ejb.DUtil.getLocalHome(DUtil.java:69) [ks_inventory.jar:2]

      at xx.ks.inventory.ejb.DEjbDelegate$DLocalProxy.<init>(DEjbDelegate.java:1865) [ks_inventory.jar:2]

       

      Here every class is auto-generated. Could anyone please help me out here.

        • 1. Re: JNDI Names in auto-generated classes
          Wolf-Dieter Fink Master

          Which version of JBoss do you use?

          Also how are the classes generated? Maybe there is a jboss deployment descriptor missing to have the correct deployment.

          Could you show the relevant part of the implementation and descriptor?

          • 2. Re: JNDI Names in auto-generated classes
            Haricharan Shetty Newbie

            Thanks for the reply. I use JBoss EAP 6.3.0. Above mentioned classes are all auto-generated  from a java file. I have used the jndi-name's as suggested by the jboss console.

            JNDI_NAME="java:global/ks_inventory-2/ks_inventory.jar/D!xx.ks.inventory.ejb.D"

            LOCAL_JNDI_NAME="java:app/ks_inventory.jar/D!xx.ks.inventory.ejb.DLocal"

             

            However I have doubt about local-jndi-name.I think the error here is coming because of COMP_NAME in auto-generated DUtil.java as shown.

             

            public class DUtil

            {

                    public static final String COMP_NAME="java:comp/env/ejb/D";

                       public static final String JNDI_NAME="java:global/ks_inventory-2/ks_inventory.jar/D!xx.ks.inventory.ejb.D";

                    public static final String LOCAL_COMP_NAME="java:comp/env/ejb/DLocal";

                       public static final String LOCAL_JNDI_NAME="java:app/ks_inventory.jar/D!xx.ks.inventory.ejb.DLocal";

             

            In the above auto-generated class changes are reflected by making changes in the DEJB.java file as shown

             

            @ejb.bean name="D" jndi-name="java:global/ks_inventory-2/ks_inventory.jar/D!xx.ks.inventory.ejb.D" type="Stateless"

            *           description="Bean to access/update persistent objects" local-jndi-name="java:app/ks_inventory.jar/D!xx.ks.inventory.ejb.DLocal"

            *          

            *          

            *          

            * @weblogic.transaction-descriptor trans-timeout-seconds="300"   

            * @weblogic.enable-call-by-reference True

            * @weblogic.dispatch-policy xxxExecuteQueue

            * @devenv.util

            * @devenv.delegate

            */

             

             

            I am posting few lines as both are considerably big files.

            • 3. Re: JNDI Names in auto-generated classes
              Wolf-Dieter Fink Master

              I suppose the @ejb.name is XDoclet, right?

              So the annotation at bean level for JNDI does not have an effect to the descriptor (as jboss.xml is not used).

               

              If you use XDoclet to generate the Util class for Locator pattern you need to set <utilobject kind="physical" to use the full JNDI name.

              Also it depends how the IC is created. I'm not sure that "java:" prefix works maybe you need to drop it, it depends on the environment where you use the Util object.

              • 4. Re: JNDI Names in auto-generated classes
                Haricharan Shetty Newbie

                Yes...@ejb.name is XDoclet. I think the error here is EJB is looking up for comp_name instead of jndi_name.In order to rectify this, I have already tried using @ejb.util generate="physical" in xdoclet inside DEJB.java. Also in server configuration file (here standalone.xml) , after googling, I have changed use-java-context="false" right under <jndi-name> tag. Still the same problem persists.

                 

                   regarding the "java:" prefix in the jndi-name, once I have deployed the application Jboss console itself suggested those names and for comp_name it was there originally in the code.

                 

                Now, when I changed my jboss.xml which is as shown

                 

                <?xml version="1.0" encoding="UTF-8"?>

                <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN"

                                       "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">                                             

                <jboss>

                    <enterprise-beans>

                        <entity>

                            <ejb-name>D</ejb-name>

                            <local-jndi-name>java:ejb/D</local-jndi-name>

                            <resource-ref>

                                <res-ref-name>D</res-ref-name>

                                <jndi-name>ejb/D</jndi-name>

                            </resource-ref>

                        </entity>

                        <entity>

                            <ejb-name>JVTInventorySession</ejb-name>

                            <local-jndi-name>java:ejb/jvtnventorysession</local-jndi-name>

                            <resource-ref>

                                <res-ref-name>jvtnventorysession</res-ref-name>

                                <jndi-name>ejb/jvtnventorysession</jndi-name>

                            </resource-ref>

                        </entity>

                        <entity>

                            <ejb-name>XVTInventoryMDB</ejb-name>

                            <local-jndi-name>java:ejb/xvtinventorymdb</local-jndi-name>

                            <resource-ref>

                                <res-ref-name>xvtinventorymdb</res-ref-name>

                                <jndi-name>ejb/jvtnventorysession</jndi-name>

                            </resource-ref>

                        </entity>

                        <security-domain>SC</security-domain>

                       </enterprise-beans>

                </jboss>

                 

                 

                 

                I am getting the following error

                 

                18:16:25,494 SEVERE [xx.ks.inventory.web.SetupServlet] (Thread-171) xx.ks.inventory.web.SetupServlet#Setup failed: xx.devenv.exceptions.ServiceExcepti

                on: java.lang.ClassCastException: xx.ks.inventory.ejb.DLocal$$$view12 cannot be cast to xx.ks.inventory.ejb.DLocalHome: xx.devenv.except

                ions.ServiceException: java.lang.ClassCastException: xx.ks.inventory.ejb.DLocal$$$view12 cannot be cast to xx.ks.inventory.ejb.DLocalHome

                        at xx.ks.inventory.ejb.DEjbDelegate$DLocalProxy.<init>(DEjbDelegate.java:1870) [ks_inventory.jar:2]

                        at xx.ks.inventory.ejb.DEjbDelegate.<init>(DEjbDelegate.java:42) [ks_inventory.jar:2]

                        at xx.ks.inventory.web.SetupServlet$ActionThread.run(SetupServlet.java:67) [ks_inventory.jar:2]

                        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_60-ea]

                Caused by: java.lang.ClassCastException: xx.ks.inventory.ejb.DLocal$$$view12 cannot be cast to xx.ks.inventory.ejb.DLocalHome

                        at xx.ks.inventory.ejb.DUtil.getLocalHome(DUtil.java:69) [ks_inventory.jar:2]

                        at xx.ks.inventory.ejb.DEjbDelegate$DLocalProxy.<init>(DEjbDelegate.java:1865) [ks_inventory.jar:2]

                        ... 3 more

                 

                So I guess my jboss.xml is wrong and it needs to be fixed. Any suggestions would be highly appreciated.

                • 5. Re: JNDI Names in auto-generated classes
                  Wolf-Dieter Fink Master

                  The jboss.xml file is ignored since AS7, so it does not have any effect.

                  Could you share a simple project as example which show the EJB and the invocation?