5 Replies Latest reply on Dec 24, 2008 1:46 AM by jaikiran pai

    EJB lookup failure in 5.0.0.GA

    John Singleton Newbie

      I have a jUnit test that worked under 5.0.0.CR2, but now fails under 5.0.0.GA

      The test does a standard lookup

      Properties props = new Properties();
      props.put(Context.INITIAL_CONTEXT_FACTORY,
       "org.jboss.security.jndi.JndiLoginInitialContextFactory");
      props.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
      props.put(Context.PROVIDER_URL, "blackbook21");
      props.put(Context.SECURITY_PRINCIPAL, "testuser");
      InitialContext ctx = new InitialContext(props);
      return (SecurityManagerRemote) ctx.lookup("usermgmt/SecurityManager/remote");
      

      but instead of returning my remote interface, it returns a javax.naming.Reference and I get a ClassCastException. If I print out the Reference, it is indeed a reference to my interface. I am compiling the test client with jbosssx-as-client.jar from the distribution client directory to be sure I am getting the latest JndiLoginInitialContextFactory. The server log seems to show that the EJB is being deployed and bound to the correct JNDI name:

      16:39:59,482 INFO [EJBContainer] STARTED EJB: security.ejb.server.SecurityManager ejbName: SecurityManager
      16:39:59,562 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

      usermgmt/SecurityManager/remote - EJB3.x Default Remote Business Interface
      usermgmt/SecurityManager/remote-security.ejb.client.SecurityManagerRemote - EJB3.x Remote Business Interface



      What server change could be causing this change in behavior?

        • 1. Re: EJB lookup failure in 5.0.0.GA
          jaikiran pai Master

          Please post the entire exception stacktrace. And also please ensure that your client uses the jbossall-client.jar (and other jar files listed in the META-INF/MANIFEST.MF of jbossall-client.jar) from the JBoss-5GA version. You can find these jars in the %JBOSS_HOME%/client folder.

          • 2. Re: EJB lookup failure in 5.0.0.GA
            John Singleton Newbie

            Here is the exception stacktrace:

            java.lang.ClassCastException: javax.naming.Reference
             at security.ejb.server.SecurityManagerRemoteFactory.createSecurityManangerRemote(SecurityManagerRemoteFactory.java:44)
             at security.ejb.server.SecurityManagerTest.cleanup(SecurityManagerTest.java:760)
             at security.ejb.server.SecurityManagerTest.setUp(SecurityManagerTest.java:742)
             at junit.framework.TestCase.runBare(TestCase.java:128)
             at junit.framework.TestResult$1.protect(TestResult.java:106)
             at junit.framework.TestResult.runProtected(TestResult.java:124)
             at junit.framework.TestResult.run(TestResult.java:109)
             at junit.framework.TestCase.run(TestCase.java:120)
             at junit.framework.TestSuite.runTest(TestSuite.java:230)
             at junit.framework.TestSuite.run(TestSuite.java:225)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
             at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
             at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
             at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
             at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
            


            Here is the toString of the object returned by the lookup:
            EJB lookup returned: Reference Class Name: Proxy for: security.ejb.client.SecurityManagerRemote
            Type: ProxyFactoryKey
            Content: ProxyFactory/SecurityManager/usermgmt/SecurityManager/remote
            Type: EJB Container Name
            Content: jboss.j2ee:ear=usermgmt.ear,jar=usermgmt-ejb-2.7.0.jar,name=SecurityManager,service=EJB3
            Type: Proxy Factory is Local
            Content: false
            Type: Remoting Host URL
            Content: socket://Macintosh.home:3873/?
            Type: Remote Business Interface
            Content: security.ejb.client.SecurityManagerRemote



            As far as using jbossall-client.jar from the distro client directory, there is a problem there. My client, a JUnit test, like everything else in our project uses a Maven2 build. So we don't point to any local directories, but rather our pom.xml file points to artifacts from networked maven repositories. I was unable to locate the client jar files in the current jboss maven repository (http://repository.jboss.org/maven2/) so for this test I loaded the jbosssx-as-client.jar from the distribution client directory into our local project maven repository. This raises two questions: (1) are the JBoss5 client jars available in any maven repository, and (2) given the indirect nature of jbossall-client.jar, will it even work with maven, or do I need to name all of the referenced jar files in my pom for this test?

            • 3. Re: EJB lookup failure in 5.0.0.GA
              jaikiran pai Master

              Going by the exception stacktrace, its definitely an issue with the client classpath not having the jboss jar file(s).

              This raises two questions: (1) are the JBoss5 client jars available in any maven repository, and


              Yes, they are.

              (2) given the indirect nature of jbossall-client.jar, will it even work with maven, or do I need to name all of the referenced jar files in my pom for this test?


              I guess you will have to name all the relevant referenced jar files in the pom.

              • 4. Re: EJB lookup failure in 5.0.0.GA
                John Singleton Newbie

                Thanks, using the correct dependency fixed it.

                Running security.ejb.server.SecurityManagerTest
                Tests run: 16, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.608 sec
                


                For those interested, I only needed to add a single "pom" dependency to my JUnit test pom.xml file and that brings in all the necessary client jars:
                 <dependency>
                 <groupId>org.jboss.jbossas</groupId>
                 <artifactId>jboss-as-client</artifactId>
                 <version>5.0.0.GA</version>
                 <type>pom</type>
                 </dependency>


                • 5. Re: EJB lookup failure in 5.0.0.GA
                  jaikiran pai Master

                   

                  "jhsingle" wrote:

                  For those interested, I only needed to add a single "pom" dependency to my JUnit test pom.xml file and that brings in all the necessary client jars:
                   <dependency>
                   <groupId>org.jboss.jbossas</groupId>
                   <artifactId>jboss-as-client</artifactId>
                   <version>5.0.0.GA</version>
                   <type>pom</type>
                   </dependency>


                  Thanks for letting us know, learnt something new today :-)