This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB and other Java EE Technologies and the fly likes Geting exeption in JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Geting exeption in JNDI" Watch "Geting exeption in JNDI" New topic
Author

Geting exeption in JNDI

rohit nabh
Greenhorn

Joined: Jan 13, 2004
Posts: 8
I am caling a Enity Bean through a simple java class.i developed all the code in the WSAD5.0 and deploed it in the test enviorment of the WSAD5.0 using WSA4.0 server.
when i am calling the EJB through java class i am getting the following error
javax.naming.ServiceUnavailableException: Caught exception when resolving initial reference=NameService. Root exception is org.omg.CORBA.TRANSIENT: Connection refused: connect:host=192.168.100.84,port=2809 minor code: 4942F301 completed: No
at com.ibm.CORBA.transport.TransportConnectionBase.connect(TransportConnectionBase.java:300)
at com.ibm.rmi.transport.TCPTransport.getConnection(TCPTransport.java:177)
at com.ibm.rmi.iiop.TransportManager.get(TransportManager.java:82)
at com.ibm.rmi.iiop.GIOPImpl.createRequest(GIOPImpl.java:131)
at com.ibm.rmi.iiop.GIOPImpl.createRequest(GIOPImpl.java:99)
at com.ibm.CORBA.iiop.ClientDelegate._createRequest(ClientDelegate.java:2360)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1263)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1167)
at com.ibm.rmi.corba.InitialNamingClient.resolve(InitialNamingClient.java:255)
at com.ibm.rmi.corba.InitialNamingClient.cachedInitialReferences(InitialNamingClient.java:333)
at com.ibm.rmi.corba.InitialNamingClient.resolve_initial_references(InitialNamingClient.java:241)
at com.ibm.rmi.corba.InitialReferenceClient.resolve_initial_references(InitialReferenceClient.java:175)
at com.ibm.rmi.corba.ORB.resolve_initial_references(ORB.java:3073)
at com.ibm.rmi.iiop.ORB.resolve_initial_references(ORB.java:527)
at com.ibm.CORBA.iiop.ORB.resolve_initial_references(ORB.java:2883)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getCosRootContext(WsnInitCtxFactory.java:437)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootJndiContext(WsnInitCtxFactory.java:363)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:229)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:98)
at com.ibm.ws.naming.util.WsnInitCtx.<init>(WsnInitCtx.java:79)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContext(WsnInitCtxFactory.java:137)
at com.ibm.websphere.naming.WsnInitialContextFactory.getInitialContext(WsnInitialContextFactory.java:80)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:255)
at javax.naming.InitialContext.init(InitialContext.java:231)
at javax.naming.InitialContext.<init>(InitialContext.java:187)
at testpack.Client.main(Client.java:31)
my client program is like this:-----------
public class Client {
public static void main(String[] args) {
try{
InitialContext ctx=new InitialContext();
Object ob=ctx.lookup("jndi");
SampleHome ahome = (SampleHome)ob;
Sample aRemote = ahome.create("1004","doot",28);
}
catch(Exception e){
e.printStackTrace();
}
}
}
Sergiu Truta
Ranch Hand

Joined: Dec 16, 2003
Posts: 121
Unless you are running your client inside the applications server, you cannot use this code. I mean you cannot use
InitialContext ctx=new InitialContext();
Object ob=ctx.lookup("jndi");
unless this class is loaded inside the application server.
If you want to use a client that runs outside the application server you have to set up the context for the application server and only then you can use that context.
For a related discussion you can read the "JNDI Appserver problem" topic in this forum. For example, I am using JBoss and inside my test classes I use something like this:
Hashtable JNDIParm = new java.util.Hashtable();
JNDIParm.put(Context.PROVIDER_URL, "localhost");
JNDIParm.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
context = new InitialContext(JNDIParm);
You also have to add the class and JNDI name for the Remote interface you want to get through lookup. For example:
JNDIParm.put("org.pack1.pack2.SessionBeanRemoteHome","Session");



...watch me...as I'm walking the path...
Anand Srinivas
Greenhorn

Joined: Dec 30, 2003
Posts: 8
hi rohit,
I think you should set up the initial context like:
--------
java.util.Properties props=System.getProperties();
props.put(javax.naming.Context.PROVIDER_URL,"iiop://localhost:900");
props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx=new InitialContext(props);
Object obj=ctx.lookup(" ");//put ur JNDI name inside the quotes
--------
Regards,
Anand Srinivas
rohit nabh
Greenhorn

Joined: Jan 13, 2004
Posts: 8
Originally posted by Anand Srinivas:
hi rohit,
I think you should set up the initial context like:
--------
java.util.Properties props=System.getProperties();
props.put(javax.naming.Context.PROVIDER_URL,"iiop://localhost:900");
props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx=new InitialContext(props);
Object obj=ctx.lookup(" ");//put ur JNDI name inside the quotes
--------
Regards,
Anand Srinivas
rohit nabh
Greenhorn

Joined: Jan 13, 2004
Posts: 8
Originally posted by Anand Srinivas:
hi rohit,
I think you should set up the initial context like:
--------
java.util.Properties props=System.getProperties();
props.put(javax.naming.Context.PROVIDER_URL,"iiop://localhost:900");
props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx=new InitialContext(props);
Object obj=ctx.lookup(" ");//put ur JNDI name inside the quotes
--------
Regards,
Anand Srinivas

hi Anand,
i have to put context factory and url only if my jndi server was on different machine.but i am testing my program on the test enviorment provided by WSAD5.0(was4.0).Means my jndi server was on same machine.
with regards,
rohit
Anand Srinivas
Greenhorn

Joined: Dec 30, 2003
Posts: 8
hi rohit,

hi Anand,
i have to put context factory and url only if my jndi server was on different machine.but i am testing my program on the test enviorment provided by WSAD5.0(was4.0).Means my jndi server was on same machine.
with regards,
rohit

I know that it is not necessary to provide those details when the JNDI server is available in the same machine.
But i encountered a similar exception in WSAD 4.0 and I then specified the context factory and url and then it worked.
So give a try and if it still doesn't works, then may be some geeks here can help
-------
Regards,
Anand Srinivas
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by rohit nabh:
i have to put context factory and url only if my jndi server was on different machine.

There are other cases, too. Our dev box has two Ethernet cards and thus two IP addresses. So we cannot let it assume "t3://localhost/" (WebLogic) and expect it to guess right. Maybe there are other cases as well?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Geting exeption in JNDI