wood burning stoves*
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
Author

RMI error: Name is not bound in this Context

Nathan Pruett
Bartender

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.


-Nate
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.

=================

Setup:
-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

jboss.xml:
<session>
<ejb-name>TestSession</ejb-name>
<jndi-name>TestSession</jndi-name>
<local-jndi-name>TestSessionLocal</local-jndi-name>
<resource-ref>
<res-ref-name>jdbc/test</res-ref-name>
<jndi-name>java:/test</jndi-name>
</resource-ref>
</session>

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


CLIENT CODE:

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.io.IOException;
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 {

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

//FAILS HERE
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(h.test("CHRIS"));
System.out.println("called business method on component interface");
}
catch(Exception ex)
{
System.out.println("Exception: " + ex.toString());
ex.printStackTrace();
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?

Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: RMI error: Name is not bound in this Context
 
Similar Threads
A naive JNDI question...
Troubles when try to lookup java:comp
rmi connection refused
A naive JNDI question...
Name TestSession is not bound in this Context