EJB invocation from remote client via JNDI
pi4630 Feb 13, 2012 7:50 AMHello,
I am doing EJB related concepts works on JBoss7.1.0CR1b.
I consulted Jaikiran's documentation here, but I get a
{noformat}
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial{noformat}
I have a HelloMessage.jar deployed. It contains the interface ITalkRemote (carries @Remote annotation) and a SLSB named Talker that implements it. The deployment is OK (I start the JBoss7.1 full config)
My client code is this:
{code}
private static ITalkRemote lookupService() throws NamingException {
ITalkRemote service = null;
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES,
"org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);
final String appName = "";
final String moduleName = "HelloMessage";
final String distinctName = "";
final String beanName = "Talker";
final String viewClassName = ITalkRemote.class.getName();
service = (ITalkRemote) context.lookup("ejb:" + appName + "/"
+ moduleName + "/" + distinctName + "/" + beanName + "!"
+ viewClassName);
return service;
}
{code}
On the package level of the client class, I've put a jboss-ejb-client.properties that carries the following elements:
{noformat}
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.two.host=localhost
remote.connection.two.port = 4447
remote.connection.two.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
{noformat}
The client's build path includes the libraries of the JBoss 7.1 Runtime (it's a JavaProject in eclipse).
If I set
{code}
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");{code}
I get a
{noformat}Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]{noformat}
Thanks for caring,