Hi again,
First thing, thanks for your reply! Anyway, i made the changes you
said but the problem persists. Looks like the web app is able to
lookup the EJB through JNDI but then cannot reference the classes.
I built a sample JSP (see below), in which i now do the cast and
not the narrow:
<%@ page import="com.datacomp.am.ejb.RemoteOperationHome,
com.datacomp.am.ejb.RemoteOperation,
javax.naming.InitialContext,
javax.naming.Context"%>
<html>
<head>
<title>EJB SAMPLE</title>
</head>
<body>
<% String sJNDI = "java:comp/env/ejb/RemoteOperationEJB";
Context initCtx = new InitialContext();
RemoteOperationHome home = null;
try {
home = (RemoteOperationHome) initCtx.lookup(sJNDI);
} catch (Exception e) {
e.printStackTrace();
}
%>
<BR>CTX of <%= sJNDI %>
<% RemoteOperation oRemoteOper = home.create(); %>
<BR>CREATE
</body>
</html>
When i call it i have the following error in the home.create()
statement:
java.rmi.NoSuchObjectException:
geronimo.server:J2EEServer=geronimo,j2eeType=StatelessSessionBean,nam
e=RemoteOperationEJB
org.openejb.proxy.EJBMethodInterceptor.createEJBInvocation
(EJBMethodInterceptor.java:171)
org.openejb.proxy.EJBMethodInterceptor.intercept
(EJBMethodInterceptor.java:115)
org.openejb.proxy.SessionEJBHome$$EnhancerByCGLIB$$345b112d.create
(<generated>)
org.apache.jsp.teste_jsp._jspService(org.apache.jsp.teste_jsp:80)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
org.apache.jasper.servlet.JspServletWrapper.service
(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile
(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
In the servlet where i am still doing the narrow, the error is the
same as in my first email...(produced in the actual narrow
statement, the JNDI lookup passes through)
java.lang.NoClassDefFoundError
The only change to the XML descriptors was in the geronimo-web.xml
that now looks like:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.0"
xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.0"
configId="TestPunch">
<import><uri>RemoteOperationEJB</uri></import>
<naming:ejb-ref>
<naming:ref-name>ejb/RemoteOperationEJB</naming:ref-name>
<naming:target-
name>geronimo.server:J2EEServer=geronimo,j2eeType=StatelessSessionBea
n,name=RemoteOperationEJB</naming:target-name>
</naming:ejb-ref>
</web-app>
One doubt that i have, do i need to include in WEB-INF/lib a JAR
including any of the EJB classes, or does the web app gets all
from its classpath once it manages to see the EJB correctly?
thanks again.
Best regards,
Bruno
________________________________
De: [EMAIL PROTECTED] em nome de Aaron Mulder
Enviada: ter 14-03-2006 14:01
Para: [email protected]
Assunto: Re: Web App calling standalone EJB
Try adding this to your geronimo-web.xml (above the ejb-ref):
<import>RemoteOperationEJB</import>
That should add the EJB clases to the classpath of the web app. (In
JBoss, it tends to put all apps on the same class loader, but
Geronimo
doesn't work that way.)
Also, a couple of less important notes:
1) You may want to remove the parentId from your openejb-jar.xml --
it's not necessary to list the default one like you have, and it ties
you to Geronimo 1.0 since you have the "1.0" version string in there.
2) You don't actually need PortableRemoteObject.narrow unless you're
calling the remote EJB via CORBA, which you are not. A simple cast
will work. You won't be able to run this application under JDK 1.5
with Geronimo 1.0 if you continue to use PRO.narrow
Thanks,
Aaron
On 3/14/06, Bruno Custodio - Datacomp DSCB <[EMAIL PROTECTED]>
wrote:
Hi there,
I've recently installed Geronimo v1.0. I am still adapting, as i
was using
JBOSS previously.
In JBOSS i had a Web application (.war) and a separate EJB named
RemoteOperationEJB.jar. From the web application i was doing the
lookup of
the EJB with no problems, creating the object and calling its
methods.
Now in Geronimo i'm having problems to replicate the same
scenario. I was
able to deploy the EJB and the WAR files separately but when i
try to run
the web application and call the EJB i'm having a "NoClassDefFound"
exception in the narrow!
First of all, is this possible to do in Geronimo, having a web
app calling a
EJB that are NOT part of a EAR?
If so, then i mostly sure have an error in the XML descriptors.
Below i put
each of them:
EJB-JAR.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>RemoteOperationEJB</ejb-name>
<home>com.datacomp.am.ejb.RemoteOperationHome</home>
<remote>com.datacomp.am.ejb.RemoteOperation</remote>
<local-home>com.datacomp.am.ejb.RemoteOperationLocalHome</local-
home>
<local>com.datacomp.am.ejb.RemoteOperationLocal</local>
<ejb-class>com.datacomp.am.ejb.RemoteOperationBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
openejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar
xmlns="http://www.openejb.org/xml/ns/openejb-jar"
configId="RemoteOperationEJB"
parentId="geronimo/j2ee-server/1.0/car">
<enterprise-beans>
<session>
<ejb-name>RemoteOperationEJB</ejb-name>
<jndi-name>ejb/RemoteOperationEJB</jndi-name>
</session>
</enterprise-beans>
</openejb-jar>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.datacomp.tp.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<ejb-ref>
<description>EJB Reference to the bean deployed to
OpenEJB</description>
<ejb-ref-name>ejb/RemoteOperationEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.datacomp.am.ejb.RemoteOperationHome</home>
<remote>com.datacomp.am.ejb.RemoteOperation</remote>
</ejb-ref>
</web-app>
geronimo-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.0"
xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.0"
configId="TestPunch">
<naming:ejb-ref>
<naming:ref-name>ejb/RemoteOperationEJB</naming:ref-name>
<naming:target-
name>geronimo.server:J2EEModule=RemoteOperationEJB.jar,J2EEServer=ge
ronimo,j2eeType=StatelessSessionBean,name=RemoteOperationEJB</
naming:target-name>
</naming:ejb-ref>
</web-app>
In my JAVA code i'm doing the following:
//reference to the remote object
Object objref = null;
try {
//get initial context and lookup EJB
objref =
ictx.lookup("java:comp/env/ejb/RemoteOperationEJB");
} catch (NamingException e) {
//some problem looking up the remote object
e.printStackTrace();
return null;
}
RemoteOperationHome home = (RemoteOperationHome)
PortableRemoteObject.narrow(objref, RemoteOperationHome.class);
try {
return home.create();
} catch (javax.ejb.CreateException ec) {
ec.printStackTrace();
} catch (RemoteException re) {
re.printStackTrace();
}
return null;
}
And it gives that exception in the narrow command!
any possible help is welcome!
thanks in advance,
best regards,
Bruno Custódio