5 Replies Latest reply on Apr 14, 2011 1:21 PM by Wolf-Dieter Fink

    Client for Ejb 3.1 session bean

    mcatalin23 Newbie

      I've created a stateless session bean by ejb 3.1 and deployed it into Jboss 6.

      Can anyone help me with a tutorial for creating a simple client to access the sessino bean?


      I've tried something following an example but it doesn't work.

      I get the following message and I don't know if this the right direction.


      Here is the exception I got for following line of code:

           EJBContainer container = EJBContainer.createEJBContainer();


      Exception in thread "main" javax.ejb.EJBException: Unable to instantiate container with factories []

          at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:97)

          at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:75)

          at com.creon.ejbclient.TestBeanClient.main(TestBeanClient.java:19)

        • 1. Client for Ejb 3.1 session bean
          Carlo de Wolf Master

          See EJB 3.1 Embeddable.


          I agree the error isn't really helpful, you can create a Jira for that bit. Basically it means that no EJB 3.1 Embeddable implementation was found on the class path.

          • 2. Re: Client for Ejb 3.1 session bean
            mcatalin23 Newbie

            Creating with ejb 3.1 and deploying into jboss 6 stateless session beans is pretty easy.

            In Jboss log I have:


            15:07:14,861 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:


                MyTestBean/remote - EJB3.x Default Remote Business Interface

                MyTestBean/remote-com.creon.ejb.TestBeanRemote - EJB3.x Remote Business Interface

                MyTestBean/local - EJB3.x Default Local Business Interface

                MyTestBean/local-com.creon.ejb.TestBeanLocal - EJB3.x Local Business Interface




            I'm trying to call methods using clients from the session bean deployed into jboss 6.0.0 final but with no success until now.


            Can someone recomands some documentation to help me create local and remote client to access the deployed sb?

            • 3. Client for Ejb 3.1 session bean
              Wolf-Dieter Fink Master

              From a plain (remote) Java app:

                Properties p = new Properties( );

                p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                p.put(Context.PROVIDER_URL, "jnp://localhost:1099");

                Context context = new InitialContext(p);

                MyTestRemote bean = context.lookup("<your EAR name>/MyTestBean/remote")


              Inside the container (e.g. other SLSB):


              MyTest bean;  //injected

              • 4. Re: Client for Ejb 3.1 session bean
                mcatalin23 Newbie

                This helps me go further but I have another issue now with the following line of code:


                MyTestRemote bean = context.lookup("<your EAR name>/MyTestBean/remote")


                In my client context.lookup returns Reference and I tryed the following instead of line above


                Object bean = context.lookup("<your EAR name>/MyTestBean/remote")

                MyTestRemote myTR = (MyTestRemote) PortableRemoteObject.narrow(bean , MyTestRemote.class);


                where MyTestRemote is the remote interface

                but I get following error:



                Exception in thread "main" java.lang.ClassCastException

                    at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)

                    at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)

                    at com.creon.ejbclient.TestBeanClient2.callSB(TestBeanClient2.java:90)

                    at com.creon.ejbclient.TestBeanClient2.main(TestBeanClient2.java:30)

                Caused by: java.lang.ClassCastException: javax.naming.Reference cannot be cast to org.omg.CORBA.Object

                    at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:212)

                    ... 3 more




                PS. I have found what the problem is

                jbossall-client.jar should be added to classpath from client folder

                • 5. Client for Ejb 3.1 session bean
                  Wolf-Dieter Fink Master

                  As you use EJB3 forget narrowing, you can use the remoteIF direct without this stuff


                  Does your example work?

                  If yes you should set the thread as 'answered'