Make EJB method available to remote java client
scooby Feb 11, 2005 1:04 AMHi,
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