-
1. Re: lookup remote ejb using java:global/as7project/SampleBeanRemoteImpl
wdfink Oct 12, 2013 11:40 AM (in response to mschwery)What kind of client do you use?
If you run a remote standalone application you should read Remote EJB invocations via JNDI - EJB client API or remote-naming project
But this is not the recommended approach to invoke EJB's.
Try this approach EJB invocations from a remote client using JNDI
-
2. Re: lookup remote ejb using java:global/as7project/SampleBeanRemoteImpl
mschwery Oct 16, 2013 8:22 PM (in response to wdfink)My lookup code in a war on server a is the following.
try {
Logger.getLogger("org.jboss").setLevel(Level.OFF);
Logger.getLogger("org.xnio").setLevel(Level.OFF);
final Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProps.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED","false");
jndiProps.put("remote.connection.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS","false");
jndiProps.put("java.naming.factory.url.pkgs","org.jboss.ejb.client.naming");
jndiProps.put("java.naming.factory.initial","org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,"remote://localhost:4547");
Context ctx = new InitialContext(jndiProps);Object obj = ctx.lookup("as7project/SampleBeanRemoteImpl!com.sample.ejb.SampleBeanRemote");
SampleBeanRemoteImpl service = (SampleBeanRemoteImpl)obj;
service.echo("This is a test");ctx.close();
} catch (Throwable t) {
t.printStackTrace();
}The EJB is the following.
package com.sample.ejb;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Stateless
@Remote(SampleBeanRemote.class)
public class SampleBeanRemoteImpl implements SampleBeanRemote {@Override
public String echo(String s) {return "Hello "+s;
}
}The server says at startup.
java:global/as7project/SampleBeanRemoteImpl!com.sample.ejb.SampleBeanRemote
java:app/as7project/SampleBeanRemoteImpl!com.sample.ejb.SampleBeanRemotejava:module/SampleBeanRemoteImpl!com.sample.ejb.SampleBeanRemote
java:jboss/exported/as7project/SampleBeanRemoteImpl!com.sample.ejb.SampleBeanRemote
java:global/as7project/SampleBeanRemoteImpl
java:app/as7project/SampleBeanRemoteImpl
java:module/SampleBeanRemoteImplThe lookup code is in a war on one server and the ejb is in a war on another server.
I want the client war to go to the other server to get the ejb, there is no ejb on the server with the look code.
We are not using security on the ejb.
-
3. Re: lookup remote ejb using java:global/as7project/SampleBeanRemoteImpl
wdfink Oct 18, 2013 2:34 PM (in response to mschwery)As you use EJB3 there is no need to use narrow().
Also you can not cast to the implementation, the client should not have the *Impl class in the classpath, you should use this instead:
Object obj = ctx.lookup("as7project/SampleBeanRemoteImpl!com.sample.ejb.SampleBeanRemote");
SampleBeanRemote service = (SampleBeanRemote)obj;
service.echo("This is a test");
-
4. Re: lookup remote ejb using java:global/as7project/SampleBeanRemoteImpl
mschwery Oct 22, 2013 10:52 AM (in response to wdfink)It ended up being that when I started the client and remote server I didn't assign node names.
It works now.