5 Replies Latest reply on Nov 25, 2005 6:48 PM by simonnunn

    Help with lookng up a bean

    simonnunn

      From a servlet, I am looking up a bean. I always get back a $proxy### object instead of the LocalHome interface. What am I doing wrong? The EJBs are deployed successfully, and so is the war. I just can't seem to get the localhome correctly.

        • 1. Re: Help with lookng up a bean
          radix_zero

          That Dynamic Proxy Class should implement the Local / LocalHome interface.

          just make sure you use the PortableRemoteObject.narrow and you should be fine

          • 2. Re: Help with lookng up a bean
            simonnunn

            Tried that...still didn't work. Is there something that I need to put into the WAR file? Some xml file?

            • 3. Re: Help with lookng up a bean
              darranl

              The PortableRemoteObject.narrow is only to be used for remote home interfaces. it should not be used for anything else.

              You have missed off important information such as JBoss version, stack traces and details of how your application is packaged.

              Can you execute the command 'jar -tf warname.war' against your war and post the output here.

              • 4. Re: Help with lookng up a bean
                simonnunn

                Jboss version is 4.0.3.

                I see the bean being bound:
                14:34:43,265 INFO [BaseLocalProxyFactory] Bound EJB LocalHome 'Stegiuser' to jndi 'stegi/StegiuserLocalHome'

                The following code always fails with a classcast exception in getLocalHome:


                public static com.cei.stegi.server.beans.interfaces.StegiuserLocalHome getLocalHome() throws javax.naming.NamingException
                {
                return (com.cei.stegi.server.beans.interfaces.StegiuserLocalHome) lookupHome(null, com.cei.stegi.server.beans.interfaces.StegiuserLocalHome.JNDI_NAME, com.cei.stegi.server.beans.interfaces.StegiuserLocalHome.class);
                }


                private static Object lookupHome(java.util.Hashtable environment, String jndiName, Class narrowTo) throws javax.naming.NamingException {
                // Obtain initial context
                javax.naming.InitialContext initialContext = new javax.naming.InitialContext(environment);
                try {
                Object objRef = initialContext.lookup(jndiName);
                // only narrow if necessary
                System.out.println("The object ref is: " + objRef);
                if (narrowTo.isInstance(java.rmi.Remote.class))
                {
                return javax.rmi.PortableRemoteObject.narrow(objRef, narrowTo);
                }
                else
                return objRef;
                } finally {
                initialContext.close();
                }
                }

                • 5. Re: Help with lookng up a bean
                  simonnunn

                  Problem solved. It was a classloader problem. I had the interfaces in the .war and the ejbs jar. Removed all interfaces from the war and it works now.