JNDI lookup
I have deployed ear file in Jboss and trying to run Java client as described in Sless example on one of the glassfish website. It's something like this:
Properties props = new Properties();
props.setProperty ("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
" com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
// optional. Defaults to localhost. Only needed if web server is running
// on a different host than the appserver
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
// optional. Defaults to 3700. Only needed if target orb port is not 3700.
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ic = new InitialContext(props);
Sless s = (Sless) ic.loopkup("com.abc.Sless");
-
But I am unable to get the reference to the Bean. I keep getting can't find serialIniticontextfactory. Do I need to include appserv-rt.jar in the ear file ? Could anybody explain how does this jndi lookup works.
# 3
The stand-alone client instructions in the EJB FAQ are for SUN's implementations only. As the
EJB FAQ states, a stand-alone java client that accesses EJBs is not portable. That's why we don't
recommend them. It's better to write an Application Client component. In that case, just like in
EJBs or web components, the container is required to bootstrap the naming provider with just
a no-arg InitialContext().See the EJB FAQ for more details.If you must write a stand-alone
java client with JBoss you'll need to consult their documentation for how to do it.
--ken
ksaksa at 2007-7-28 15:16:10 >

# 4
Use this code :
public static Context getInitialContext( )
throws javax.naming.NamingException {
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");
return new javax.naming.InitialContext(p);
}
# 5
I am having the same problem.
Since I wrote my simple stateless bean, I have not been able to access the bean via my application client. I did all the possible settingbut could still access my bean interface.
here is the code:
Hashtable env = new Hashtable();
//env.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
env.put("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
//env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
env.put("java.naming.factory.url.pkgs","com.sun.enterprise.naming");
env.put("java.naming.provider.url","localhost:8081");
env.put("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
// optional. Defaults to localhost. Only needed if web server is running
// on a different host than the appserver
env.put("org.omg.CORBA.ORBInitialHost", "localhost");
// optional. Defaults to 3700. Only needed if target orb port is not 3700.
env.put("org.omg.CORBA.ORBInitialPort", "3700");
Context ctx = new InitialContext(env);
System.out.println ("Trying to get the name of this context: " + ctx.getNameInNamespace());
System.out.println("Got initial context ... yeah ");
/*
* Get a reference to a bean instance, looked up by class name
*/
NamingEnumeration ne = ctx.list("");
System.out.println("Got list... ");
while(ne.hasMore())
{
NameClassPair nc = (NameClassPair)ne.next();
System.out.println("Entry is ... "+nc.getName()+" -- "+nc.getClassName());
}
Manager manager = (Manager) ctx.lookup("examples.session.stateless.Manager");
/*
* Call the helloManager() method on the bean.
* We then print the result to the screen.
*/
System.out.println(Manager.helloManager("Client"));
the error I am getting is
Exception in thread "main" javax.naming.CommunicationException: java.rmi.MarshalException: CORBA MARSHAL 1398079695 No; nested exception is:
org.omg.CORBA.MARSHAL:vmcid: SUN minor code: 207 completed: No
at com.sun.enterprise.naming.SerialContext.list(SerialContext.java:500)
at javax.naming.InitialContext.list(InitialContext.java:395)
at mn.EjbClient.main(EjbClient.java:59)
what can I do to get out of this.
# 6
replace your code uptill ctx.list with this:
Properties env = new Properties();
env.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
env.put("java.naming.provider.url","jnp://localhost:1099");
Context ctx = new InitialContext(env);
Make sure Jboss's jar file under client directory is in your classpath.