Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tomcat JNDI calls to remote EJB

13 views
Skip to first unread message

Si Rodway

unread,
May 12, 2002, 9:48:03 AM5/12/02
to
I've spent the past few days trying to get Tomcat 4.0.3 to call a
remote EJB hosted on another server running in Orion. I've written a
test servlet, which contains a 'main' method so I can also run it from
the command line. The command line version works fine, but when
calling the servlet from Tomcat I get: -

Unable to find EjbDetails javax.naming.NameNotFoundException: Name
EjbDetails is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:811)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:183)
at javax.naming.InitialContext.lookup(InitialContext.java:350)
at EjbCaller.getBeanDetails(EjbCaller.java:119)
at EjbCaller.doGet(EjbCaller.java:45)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServl

One thing I have noticed is that the env values from Tomcat report as:
-

Apache Tomcat/4.0.3

java.naming.factory.initial VALUE
org.apache.naming.java.javaURLContextFactory
java.naming.provider.url=ormi://remoteMachine/ejbData
java.naming.factory.url.pkgs VALUE org.apache.naming
java.naming.security.principal=admin
java.naming.security.credentials=xxx

But the command line parameters report as: -

java.naming.factory.initial=com.evermind.server.rmi.RMIInitialContextFactory
java.naming.provider.url=ormi://remoteMachine/ejbData
java.naming.security.principal=admin
java.naming.security.credentials=xxx

Now both the command line and the Tomcat servlet are using the same
jndi properties file, this contains: -

java.naming.factory.initial=com.evermind.server.rmi.RMIInitialContextFactory
java.naming.provider.url=ormi://remoteMachine/ejbData
java.naming.security.principal=admin
java.naming.security.credentials=xxx

So then why does Tomcat use it's own Context Factory and not the one I
tell it to, and is this where the problem of not being able to bind to
the EJB exists?

The servlet code is listed here just to give you any additional
information: -


import javax.servlet.*;
import javax.servlet.*;
import java.io.*;

import java.util.*;

import javax.naming.*;

import remote.beans.EjbRemote;
import remote.beans..EjbHome;


public class EjbCaller extends HttpServlet {
private static final String CONTENT_TYPE = "text/html;
charset=windows-1252";

public void init(ServletConfig config) throws ServletException {
super.init(config);
}

/**
* Process the HTTP doGet request.
*/
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {

response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>EjbCaller</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a request.</p>");
out.println("<p><b>Calling the bean was ...
"+getBeanDetails()+"</b></p>");
out.println("</body></html>");
out.close();

}//doGet

/**
* Process the HTTP doPost request.
*/
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
doGet(request, response);
}//doPost


boolean getBeanDetails() {

try {
Context initCtx = new InitialContext();

displayEnv(initCtx);

EjbHome ejbHome = (EjbHome)initCtx.lookup("EjbDetails");

EjbRemote ejbDetails;

// Use one of the create() methods below to create a new
instance
ejbDetails = ejbHome.create( );

System.out.println("Got ejb detail");

return true;
}
catch(Throwable ex) {
ex.printStackTrace();
}

return false;
}

protected static void displayEnv(Context ctx)
throws NamingException {
Hashtable env = ctx.getEnvironment();
Enumeration enum = env.keys();

System.out.println("displayEnv number of keys "+env.size());

while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
Object value = env.get(key);
System.out.println(key+"="+value);
}
}//displayEnv

public static void main(String[] args) {

EjbCaller ejb = new EjbCaller();

System.out.println("Calling EJB was "+ejb.getBeanDetails());

}
}//class EjbCaller


Other things I've tried include editting the web.xml file to include
the EJB reference details, adding the beans 'ear' file to the library
path and a number of other things. So if anyone can help I would
greatly appreciate it, many thanks in advance.

Si.

0 new messages