Ok...I have the integration working, I think.  I can
test everything OK with the call to
"http://localhost:8080/openejb_loader-0.9.2/";.  I can
even lookup my bean.  Now when I try the JSP or
servlet I seem to be getting a JNDI NamingException,
"Naming Exception - Name "ejb/hello" not found". I
know that this might be a Tomcat JNDI question now,
but I thought that I would still post it here...


THE JSP:
<%@ page import="org.acme.HelloObject,
                 org.acme.HelloHome,
                 javax.naming.InitialContext,
                 javax.naming.Context"%>

<html>
<head>
        <title>OpenEJB -- EJB for Tomcat</title>
</head>

<body>
<%
    Context initCtx = new InitialContext();

    Object object =
initCtx.lookup("java:comp/env/ejb/hello");
        
        if (object != null) {
                HelloHome helloHome = (HelloHome)
        javax.rmi.PortableRemoteObject.narrow(object,
HelloHome.class);
        HelloObject bean = helloHome.create();
                out.println(bean.sayHello());
        }
    
%>
</body>
</html>

THE SERVER.XML ENTRY:
<Context docBase="${catalina.home}/webapps/EJB"
path="/EJB">

<Ejb name="ejb/hello"
             type="Session"
             home="org.acme.HelloHome"
             remote="org.acme.Hello"/>
        <ResourceParams name="ejb/hello">
            <parameter>
                <name>factory</name>
               
<value>org.openejb.client.TomcatEjbFactory</value>
            </parameter>
            <parameter>
               
<name>openejb.naming.factory.initial</name>
               
<value>org.openejb.client.LocalInitialContextFactory</value>
            </parameter>
            <parameter>
               
<name>openejb.naming.security.principal</name>
                <value>Admin</value>
            </parameter>
            <parameter>
               
<name>openejb.naming.security.credentials</name>
                <value>pass</value>
            </parameter>
            <parameter>
               
<name>openejb.naming.provider.url</name>
                <value>localhost:4201</value>
            </parameter>
            <parameter>
                <name>openejb.ejb-link</name>
                <value>Hello</value>
            </parameter>
        </ResourceParams>
  
  </Context>

The web.xml entry for the EJB webapp:
<ejb-ref>
      <description>
          EJB Reference to the bean deployed to
OpenEJB
      </description>
      <ejb-ref-name>ejb/hello</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      <home>org.acme.HelloHome</home>
      <remote>org.acme.Hello</remote>
  </ejb-ref>

The application xml entry in the EJB.xml in
$CATALINA_HOME/conf/catalina/localhost:
<?xml version='1.0' encoding='utf-8'?>
<Context crossContext="true" debug="9"
displayName="EJB" docBase="EJB" path="/EJB"
workDir="c:/tomcat-5.0.28/work/Catalina/localhost/EJB">
  <Logger
className="org.apache.catalina.logger.FileLogger"
directory="c:/tomcat-5.0.28/webapps/EJB/logs"
prefix="EJB_log." suffix=".txt" timestamp="true"
verbosity="4"/>
  <ResourceLink global="ejb/hello" name="ejb/hello"
type="org.acme.Hello"/>
</Context>

THE SERVLET:
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.acme.HelloHome;
import org.acme.HelloObject;

/*
 * Created on Jun 7, 2005
 */

/**
 * @author rayj
 * @version 1.0
 */
public class TestHelloEJBServlet extends HttpServlet {

    
    
    /** Processes requests for both HTTP
<code>GET</code> and <code>POST</code> methods.
     * All the real work happens here.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    protected void processRequest(HttpServletRequest
req,
            HttpServletResponse res) throws
ServletException, IOException {

        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet</title>");
        out.println("</head>"); 
        out.println("<body>");
               
        Properties p = new Properties();

        //The JNDI properties you set depend
        //on which server you are using.
        //These properties are for the Remote Server.
        /*p.put("java.naming.factory.initial",
               
"org.openejb.client.RemoteInitialContextFactory");
        p.put("java.naming.provider.url",
"127.0.0.1:4201");
        p.put("java.naming.security.principal",
"Admin");
        p.put("java.naming.security.credentials",
"pass");*/

        p.put("java.naming.factory.initial",
"org.openejb.client.LocalInitialContextFactory");
        p.put("openejb.home",
"C:\\Programs\\openejb-0.9.2");
        
        try {
//          Now use those properties to create
            //a JNDI InitialContext with the server.
            InitialContext ctx = new
InitialContext(p);
            
//          Lookup the bean using it's deployment id
            Object obj = ctx.lookup("ejb/hello");
            
//          Be good and use RMI remote object
narrowing
            //as required by the EJB specification.
            HelloHome ejbHome = (HelloHome)
PortableRemoteObject.narrow(obj,
                    HelloHome.class);

            //Use the HelloHome to create a
HelloObject
            HelloObject ejbObject = ejbHome.create();

            //The part we've all been wainting for...
            String message = ejbObject.sayHello();

            //A drum roll please.
            System.out.println(message);
            out.println(message);
            
        } catch (NamingException ne) {
            out.println("Naming Exception  -
"+ne.getMessage());
        } catch (Exception e) {
            out.println("Exception  -
"+e.getMessage());
        } finally {
            out.println("</body>");
            out.println("</html>");
            out.close();
         }
    }
    
    /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
        super.destroy(); // Just puts "destroy" string
in log
        // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag
value method equals to get.
     * 
     * @param request the request send by the client
to the server
     * @param response the response send by the server
to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request,
HttpServletResponse response)
            throws ServletException, IOException {

        processRequest(request, response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag
value method equals to post.
     * 
     * @param request the request send by the client
to the server
     * @param response the response send by the server
to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request,
HttpServletResponse response)
            throws ServletException, IOException {

        processRequest(request, response);
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occure
     */
    public void init(ServletConfig config) throws
ServletException {
        super.init(config);

    }
}


--- David Blevins <[EMAIL PROTECTED]> wrote:

> On Mon, Jun 06, 2005 at 11:37:27AM +0200, Jacek
> Laskowski wrote:
> > Jimmy Ray wrote:
> > >I was trying to follow the hello bean example.  I
> have
> > >openejb 0.9.2 deployed with Tomcat 5.0.28 On
> Win2k
> > >with Sun JDK 1.4.2.  I have tested the openejb
> config
> > >Ok and the bean is deployed OK with the "Hello"
> JNDI
> > >name.  This is running on my local desktop
> machine, so
> > >I am using the 127.0.0.1 IP.
> > >
> > >When I try to invoke it from a app executing in
> my
> > >Eclipse debugger, I get the error:
> > >
> > >javax.naming.NoInitialContextException: Cannot
> > >instantiate class:
> > >org.openejb.client.RemoteInitialContextFactory
> [Root
> > >exception is java.lang.ClassNotFoundException:
> > >org.openejb.client.RemoteInitialContextFactory]
> > 
> > Hi,
> > 
> > It happens when Tomcat (classloaders) can't access
> the class and load 
> > it. Since you're using the version that has some
> issues with 
> > classloading I'd recommend building OpenEJB from
> sources. See 
> > http://www.openejb.org/cvs.html for up-to-date
> information on how to 
> > check out the sources and build OpenEJB.
> > 
> 
> The 0.9.2 code should work fine with 5.0.28 as they
> didn't change the classloading structure in Tomcat
> till 5.5.x.  I think the 5.0.x branch is still the
> same as 4.x as far as classloading goes.
> 
> Try using the little openejb webapp to figure out
> what could be going wrong.  Go to this url and click
> the link to test the setup:
> 
>   http://localhost:8080/openejb-loader-0.9.2/
> 
> That will try setup by setup to varify that
> everything is setup correctly.  I swear we used to
> have this in the docs on the website, but I don't
> see it anymore.
> 
> We totally should cut a 1.0 and it's way past
> pathetic that we haven't, but at least give that a
> try for now.  The OpenEJB 0.9.2/Tomcat 4.x combo
> worked really well for a lot of people and still
> should till 5.5.x where they threw away their own
> class loader code and opted to go back to using
> Sun's URLClassLoader.
> 
> Anyway, give that a shot for now and we'll try to
> get a 1.0 out like in a couple days.  Jacek as
> volunteered to put one together.  I'll help out on
> that as well.  We'll need some people to pound on it
> too before we can call it good.
> 
> -David
> 



                
__________________________________ 
Discover Yahoo! 
Use Yahoo! to plan a weekend, have fun online and more. Check it out! 
http://discover.yahoo.com/

Reply via email to