4 Replies Latest reply on Feb 12, 2005 7:50 AM by scooby

    Make EJB method available to remote java client

    scooby

      Hi,

      Been fighting with this all day, so i'll just cry uncle and see if anyone here can tell me what simple thing i'm overlooking. :o)

      It appears that the client code fails when trying to map a JNDI name to an actual object.

      Trying to create an EJB with a single business method "hello". While the module appears in the jmx-console mbean list, it never has anything but this listed underneath it:

      +- env (class: org.jnp.interfaces.NamingContext)


      Further down the page under "Global JNDI Namespace" there is:

      +- ejb (class: org.jnp.interfaces.NamingContext)
      | +- HelloWorld (proxy: $Proxy152 implements interface org.jboss.proxy.IClientContainer,interface hws.HelloWorldHome,interface javax.ejb.Handle)


      I've configured the class with:


      /**
      * @ejb.bean name="HelloWorld"
      * display-name="cant_take"
      * description="much_more"
      * jndi-name="ejb/HelloWorld"
      * type="Stateless"
      * view-type="remote"
      */
      public class HelloWorldBean implements SessionBean {

      ...

      with this member:

      /**
      * The method called to display the string "Hello World!" on the client.
      *
      * @ejb.interface-method view-type = "remote"
      */
      public String hello()
      {


      Xdoclet does indead create HelloWorld.java and HelloWorldHome.java based on the above annotations in HelloWorldBean.java. But the following client code always fails:

      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.put(Context.PROVIDER_URL, "localhost:1099");
      env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

      try {

      Context ctx = new InitialContext(env);
      Object obj = ctx.lookup( "ejb/HelloWorld" );

      with this trace:
      Exception in thread "main" java.lang.NoClassDefFoundError: javax/ejb/EJBObject
      at org.jboss.proxy.ejb.GenericEJBInterceptor.class$(GenericEJBInterceptor.java:52)
      at org.jboss.proxy.ejb.GenericEJBInterceptor.(GenericEJBInterceptor.java:59)
      at sun.misc.Unsafe.ensureClassInitialized(Native Method)
      at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:25)
      at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:122)
      at java.lang.reflect.Field.acquireFieldAccessor(Field.java:917)
      at java.lang.reflect.Field.getFieldAccessor(Field.java:898)
      at java.lang.reflect.Field.getLong(Field.java:527)
      at java.io.ObjectStreamClass.getDeclaredSUID(ObjectStreamClass.java:1559)
      at java.io.ObjectStreamClass.access$600(ObjectStreamClass.java:47)
      at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:381)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.io.ObjectStreamClass.(ObjectStreamClass.java:373)
      at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:268)
      at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:504)
      at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1546)
      at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1460)
      at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1546)
      at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1460)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1693)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
      at org.jboss.proxy.ClientContainer.readExternal(ClientContainer.java:147)
      at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1753)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1711)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
      at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
      at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:51)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:566)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:520)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)
      at cliside.HelloWorldClient.main(HelloWorldClient.java:21)


      Which suggests (maybe?) that it can't map the JNDI name to a EJB object, (which would explain why the jmx-console entry is empty). But i just can't figure out how to convince the jboss server to use the EJB.

      For good measure here is a snippet of the log when the EJB gets deployed:

      [org.jboss.deployment.MainDeployer] Begin deployment start file:/C:/jboss-4.0.1/server/default/deploy/HelloWorld.jar

      [org.jboss.ejb.EJBDeployer] start application, deploymentInfo: org.jboss.deployment.DeploymentInfo@6b6bf3ab { url=file:/C:/jboss-4.0.1/server/default/deploy/HelloWorld.jar }
      deployer: org.jboss.ejb.EJBDeployer@2d09e0
      status: Starting
      state: START_DEPLOYER
      watch: file:/C:/jboss-4.0.1/server/default/deploy/HelloWorld.jar
      altDD: null
      lastDeployed: 1108100828333
      lastModified: 1108100828313
      mbeans:
      jboss.j2ee:jndiName=ejb/HelloWorld,service=EJB state: Created
      , short name: HelloWorld.jar, parent short name: null

      [org.jboss.system.ServiceController] starting service jboss.j2ee:service=EjbModule,module=HelloWorld.jar

      [org.jboss.ejb.EjbModule] Starting jboss.j2ee:service=EjbModule,module=HelloWorld.jar

      [org.jboss.ejb.EjbModule] startService, starting container: HelloWorld

      [org.jboss.system.ServiceController] starting service jboss.j2ee:jndiName=ejb/HelloWorld,service=EJB

      [org.jboss.ejb.StatelessSessionContainer] Starting jboss.j2ee:jndiName=ejb/HelloWorld,service=EJB

      [org.jboss.ejb.StatelessSessionContainer] Begin java:comp/env for EJB: HelloWorld

      [org.jboss.ejb.StatelessSessionContainer] TCL: org.jboss.util.loading.DelegatingClassLoader@15e601

      [org.jboss.ejb.StatelessSessionContainer] Unable to retrieve orbjavax.management.InstanceNotFoundException: jboss:service=CorbaORB is not registered.

      [org.jboss.ejb.StatelessSessionContainer] End java:comp/env for EJB: HelloWorld

      [org.jboss.ejb.plugins.local.BaseLocalProxyFactory] HelloWorld cannot be Bound, doesn't have local and local home interfaces

      [org.jboss.proxy.ejb.ProxyFactory] (re-)Binding Home ejb/HelloWorld

      [org.jboss.proxy.ejb.ProxyFactory] Bound HelloWorld to ejb/HelloWorld

      [org.jboss.system.ServiceController] starting service jboss.j2ee:service=EJB,plugin=pool,jndiName=ejb/HelloWorld

      [org.jboss.ejb.plugins.StatelessSessionInstancePool] Starting jboss.j2ee:service=EJB,plugin=pool,jndiName=ejb/HelloWorld

      [org.jboss.ejb.plugins.StatelessSessionInstancePool] Started jboss.j2ee:service=EJB,plugin=pool,jndiName=ejb/HelloWorld

      [org.jboss.system.ServiceController] Starting dependent components for: jboss.j2ee:service=EJB,plugin=pool,jndiName=ejb/HelloWorld dependent components: []

      [org.jboss.resource.connectionmanager.CachedConnectionInterceptor] start called in CachedConnectionInterceptor

      [org.jboss.ejb.StatelessSessionContainer] Started jboss.j2ee:jndiName=ejb/HelloWorld,service=EJB

      [org.jboss.system.ServiceController] Starting dependent components for: jboss.j2ee:jndiName=ejb/HelloWorld,service=EJB dependent components: []

      [org.jboss.ejb.EjbModule] Started jboss.j2ee:service=EjbModule,module=HelloWorld.jar

      [org.jboss.system.ServiceController] Starting dependent components for: jboss.j2ee:service=EjbModule,module=HelloWorld.jar dependent components: []

      [org.jboss.ejb.EJBDeployer] Deployed: file:/C:/jboss-4.0.1/server/default/deploy/HelloWorld.jar


      Thanks for any help,
      Sean

        • 1. Re: Make EJB method available to remote java client

          @ejb.util generate="physical"

          add this tag at yr class level...
          below the @ej.bean tag and then deploy yr bean.

          Vishal

          • 2. Re: Make EJB method available to remote java client
            scooby

             

            "vashistvishal" wrote:
            @ejb.util generate="physical"

            add this tag at yr class level...
            below the @ej.bean tag and then deploy yr bean.



            Thanks Vishal, unfortunately the same error comes up afterward.
            I confess, that I really don't understand all of different namespace issues. Don't know where the package name gets used for instance, or if that's part of the problem here.

            Thanks again,
            Sean


            • 3. Re: Make EJB method available to remote java client

              Is yr client on the sam pc, if not then the you have to access the the name servers with its name in DNS as it is pointing to localhost if thats the case.

              1. If thats not the case do u get any erros while deploying the bean.
              If yes paste the stack trace.

              2.If its is deployed successfully, then paste stack trace of errors while connecting to the server.

              Also write what Platform, J2sdk and Jboss u are using.
              Also print yr Classpath as well.

              Vishal.

              • 4. Re: Make EJB method available to remote java client
                scooby

                 

                "vashistvishal" wrote:

                Also print yr Classpath as well.


                Vishal,

                Your question about the Classpath prompted me to try adding jbossall-client and that worked. I got sidetracked by the display in jmx-console not listing the remote interface. That made me focus on the server side rather than look at the client. Still don't know why it looks that way in jmx-console but at least the client code is working as expected.

                Thanks!
                Sean