File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Distributed Java and the fly likes RMI error: Name is not bound in this Context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Reply locked New topic

RMI error: Name is not bound in this Context

Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Sorry, this post really does belong in the EJB forum, as the problem is with the JNDI lookup. You should be looking up "java:comp/env/TestSession", not just "TestSession". JNDI contains data in a hierarchy, and "java:comp/env" is the root of this hierarchy.

Closing this post, since it belongs in EJB instead.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Chris Montgomery
Ranch Hand

Joined: Jan 14, 2004
Posts: 141
I initially had this post in the EJB section, but just noticed this group and decided it would be better off here.... sorry for the dup.


-EJB running in JBoss - client test code doing same thing works great.
-Struts running OUTSIDE of JBoss.
-Struts Action class (in Tomcat) is trying to connect to EJB (in JBoss) using RMI.

code is failing here:
-Object o = initial.lookup("TestSession"); (client code below)
-ERROR: Name TestSession is not bound in this Context


JNDIView Service List:
Global JNDI Namespace
+- TestSession (proxy: $Proxy53 implements interface com.test.TestSessionHome,interface javax.ejb.Handle)


import com.test.*;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.ejb.CreateException;

import java.rmi.RemoteException;
import java.util.Hashtable;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class testing extends Action{

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception, RemoteException {

System.out.println("Adding properties");
Context initial = new InitialContext();
System.out.println("Got initial context!");

Object o = initial.lookup("TestSession");

System.out.println("got object from lookup");
com.test.TestSessionHome home = (com.test.TestSessionHome)PortableRemoteObject.narrow(o, com.test.TestSessionHome.class);

System.out.println("got home object back and did remote narrow cast");
com.test.TestSession h = home.create();
System.out.println("got component interface");
System.out.println("called business method on component interface");
catch(Exception ex)
System.out.println("Exception: " + ex.toString());
return mapping.findForward("fail");

System.out.println("test = " + myBean.test("CHRIS"));

return mapping.findForward("success");



Everything *appears* to be okay, but I'm still quite new to this, so I really can't say.

Any ideas?

I agree. Here's the link:
subject: RMI error: Name is not bound in this Context
It's not a secret anymore!