| Author |
lookup() in EJB3
|
Juan Handal
Greenhorn
Joined: Jan 25, 2005
Posts: 29
|
|
Hi I'm using GlassFish &NetBeans 5.5,no problems at all but when it comes to a SessionBean(that is the name of the Session Bean) with only one method public String Hello(){return "HelloWorld";} I tried the standalone client java class accessing public String Hello(){} ,but I can not get the Context. class Test{ public static void main(String [] args)throws NamingException{ Context ctx=new InitialContext(); SessionBeanLocal hello=SessionBeanLocal)ctx.lookup("ejb/SessionBean"); System.out.println(hello.Hello() ); } } I got NoContextException ,both the SessionBean ,SessionBeanLocal& class Test are in the same ejb directory.The problem is the lookup("What is the right JNDI name in here ???") I'd appreciate any help. JHandal
|
 |
Pradeep Settipalli
Greenhorn
Joined: Dec 15, 2006
Posts: 5
|
|
i do have a same problem so any one pls suggest me a solution The Bussiness interface package hai; public interface Hello { public String hello(); } The Bean class package hai; import javax.ejb.Remote; import javax.ejb.Stateless; @Stateless @Remote(hai.Hello.class) public class HelloBean implements Hello { public String hello(){ return "hai"; } } The client import javax.naming.*; public class HelloClient { public static void main(String[] args) { try{ Context ctx=new InitialContext(); Hello h=(Hello)ctx.lookup("hai.Hello"); System.out.println(h.hello()); } catch(Exception e){ e.printStackTrace(); } } } This is the error i get when i try to run 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 at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.lookup(Unknown Source) at hai.HelloClient.main(HelloClient.java:14) so pls suggest me a solution for this problem as this is my first ejb program Thanks in advance Regards Pradeep
|
 |
Joe Khan
Greenhorn
Joined: Aug 27, 2004
Posts: 11
|
|
Make two changes: (1)In the Bean class: @Stateless(mappedName="XYZ") (2)In the client code: Context ctx=new InitialContext(); Hello h=(Hello)ctx.lookup("XYZ"); [ May 21, 2007: Message edited by: Joe Khan ]
|
All things are difficult before they are easy...
|
 |
Oliver Kamps
Greenhorn
Joined: May 15, 2007
Posts: 18
|
|
Hi, I haven't used glassfish, so the following might be off the mark. I assume that you are running to run your code as stand-alone clients of that EJB. Looking at the exceptions, I'm not convinced that the JNDI name is the problem: it seems to me that JNDI doesn't know what initial context factory to use. Check out this GlassFish FAQ for more details. Cheers, Oliver
|
 |
alex Rozario
Greenhorn
Joined: May 15, 2007
Posts: 4
|
|
hi juan & pradeep, me too have an same error. just now i posted that. hi mr.joe i have tried your suggestion but still it shows me the same error can you help me further thank you
|
 |
Dave Michels
Greenhorn
Joined: Mar 29, 2007
Posts: 5
|
|
Pradeep, It apprears that your client doesn't have the correct IntialContextFactory configured for the JNDI environment based on the exception stack trace. See the following Glassfish Naming Factory Env and see if that helps.
|
 |
Juan Handal
Greenhorn
Joined: Jan 25, 2005
Posts: 29
|
|
Hi Dave You are right.I'm trying to get the right one setProperty: 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); Where can I get the appservrt.jar's jndi to look the right property? I'm using netbeans 5.5 & GlassFish Thanks a lot.
|
 |
 |
|
|
subject: lookup() in EJB3
|
|
|