Hey all,

I am getting an error when my serlvet accesses an EJB that in its code is
accessing another ejb. Below I am listing the error, the code and the
ejb-jar.xml file. I am using Orion 1.2.9. I am not sure if this is a bug
with 1.2.9, or why this would be happening. I took code snippets from an EJB
1.1 book and I have been looking over my code, xml, etc several times and it
all appears to be correct..so I am not sure why this is happening.

>From what I have read, it appears that when an EJB needs to use another,
whether its an entity or session, it does the same code that a servlet would
do to access an EJB..it does a JNDI lookup. IS this correct? Also, from what
I have read, it appears that when an ejb uses another, you need to set the
ejb-ref tags in the first ejb, so it can "see" the other ejb. Is this
correct? Did I do this correctly in my snippet below (ejb-jar.xml)? If I am
only referencing the Test ejb from the first ejb (Login), do I need to
define the Test ejb in the ejb-jar.xml as well, as I have done?

So my problem is..why am I getting a ClassCastException when trying to
execute the login() method? Oh..I did narrow down the line of code in the
EJB LoginBean to where it does the PortableRemoteObject.narrow() call on the
Test bean. The snippet line is:

TestHome th = (TestHome) PortableRemoteObject.narrow(ref, TestHome.class);

This is where the exception is thrown. If I comment out the few lines the
LoginBean does to get the Test..their is no exception thrown and the
LoginBean ejb works fine. So it is definitely with it trying to get the Test
EJB.

Thanks for any help..




/****************************
  Exception output
 ****************************/
Orion/1.2.9 initialized
com.evermind.server.rmi.OrionRemoteException: java.lang.ClassCastException
        at com.evermind.server.ejb.EJBUtils.getUserException(JAX)
        at
Login_StatelessSessionBeanWrapper0.login(Login_StatelessSessionBeanWr
apper0.java:60)
        at com.company.ui.actions.LoginAction.executeCommandDefault(LoginAc
tion.java:38)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.company.ui.actions.DefaultAction.perform(DefaultAction.java:
77)
        at
org.apache.struts.action.ActionServlet.processActionInstance(ActionSe
rvlet.java:794)
        at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:702
)
        at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:332)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at com.evermind.server.http.du.rr(JAX)
        at com.evermind.server.http.du.forward(JAX)
        at com.evermind.server.http.d5.rx(JAX)
        at com.evermind.server.http.d5.rw(JAX)
        at com.evermind.util.f.run(JAX)

        Nested exception is:
java.lang.ClassCastException
        at
com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Porta
bleRemoteObject.java:296)
        at
javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
        at com.company.ejb.session.login.LoginBean.login(LoginBean.java:36)

        at
Login_StatelessSessionBeanWrapper0.login(Login_StatelessSessionBeanWr
apper0.java:54)
        at com.company.ui.actions.LoginAction.executeCommandDefault(LoginAc
tion.java:38)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.company.ui.actions.DefaultAction.perform(DefaultAction.java:
77)
        at
org.apache.struts.action.ActionServlet.processActionInstance(ActionSe
rvlet.java:794)
        at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:702
)
        at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:332)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at com.evermind.server.http.du.rr(JAX)
        at com.evermind.server.http.du.forward(JAX)
        at com.evermind.server.http.d5.rx(JAX)
        at com.evermind.server.http.d5.rw(JAX)
        at com.evermind.util.f.run(JAX)


/*******************************
  EJB-JAR.XML
 ********************************/

<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 1.1//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd">

<ejb-jar>
        <description>Company ejbs</description>
        <display-name>Company EJB</display-name>
        <enterprise-beans>
                <session>
                        <description>Login bean for logging in
people</description>
        
<display-name>com.company.ejb.session.login.Login</display-name>
        
<ejb-name>com.company.ejb.session.login.Login</ejb-name>
                        <home>com.company.ejb.session.login.LoginHome</home>
                        <remote>com.company.ejb.session.login.Login</remote>
        
<ejb-class>com.company.ejb.session.login.LoginBean</ejb-class>
                        <session-type>Stateless</session-type>

                        <ejb-ref>
                                <ejb-ref-name>ejb/Test</ejb-ref-name>
                                <ejb-ref-type>Session</ejb-ref-type>
        
<home>com.company.ejb.session.test.TestHome</home>
        
<remote>com.company.ejb.session.test.Test</remote>
                        </ejb-ref>
                </session>
                <session>
                        <description>Test Bean</description>
        
<display-name>com.company.ejb.session.test.Test</display-name>
        
<ejb-name>com.company.ejb.session.test.Test</ejb-name>
                        <home>com.company.ejb.session.test.TestHome</home>
                        <remote>com.company.ejb.session.test.Test</remote>
        
<ejb-class>com.company.ejb.session.test.TestBean</ejb-class>
                        <session-type>Stateless</session-type>
                </session>
        </enterprise-beans>
</ejb-jar>


/*******************************************
  code snippet of servlet calling EJB Login
 *******************************************/

Context context = new InitialContext();
Object ref = context.lookup("java:comp/env/ejb/Login");
LoginHome lh = (LoginHome) PortableRemoteObject.narrow(ref,
LoginHome.class);
Login l = lh.create();
if( l.login("name", "password") )
{
  System.out.println("Login successful");
}
else
{
  System.out.println("Login failed.");
}


/************************************************
 code snippet in LoginBean code calling other EJB
 ************************************************/

Context context = new Context();
Object ref = context.lookup("java:comp/env/ejb/Test");
TestHome th = (TestHome) PortableRemoteObject.narrow(ref, TestHome.class);
Test t = th.create();
t.test();



Reply via email to