geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <david_jen...@yahoo.com>
Subject Re: AW: AW: Accessing the local interface of an Session EJB from a WAR
Date Tue, 27 Feb 2007 18:05:50 GMT

On Feb 27, 2007, at 7:59 AM, Norbert Rieger wrote:

> Hi Mark,
>
> maybe my question was not exactly enough (my EJB learning curve is  
> still in it's infancy).
>
> The EJB is already running in Geronimo, the remote interface works  
> fine for client applications (java) and web applications.
>
> Due to performance issues I would like to use the local interface  
> within my web application, which is running in the same Geronimo  
> instance.
>
> The EJB and the web application are deployed separately (EAR and WAR).

According to the j2ee specs you can't do this, the war and ejb app  
have to be in the same ear to use local interfaces.

In geronimo we make this work as long as the war has the ejb app as a  
parent (or ancestor) which is pretty much necessary anyway so the ejb  
interface classes get loaded in the same classloader for both apps.

So, you need a geronimo-web.xml plan and you need to include the ejb  
app as a dependency in the environment section.  You should use a  
plan for the ejb app as well so you are sure what it's module Id is.

You definitely need an <ejb-local-ref> element in your web.xml.

As long as there is only one ejb with this localhome and local  
interface, you shouldn't need anything in the geronimo-web.xml  
related to this ejb-ref: geronimo will look for a unique ejb with the  
interfaces specified in the web.xml ejb-local-ref and hook up to it  
if found: if there's 0 or more than 1 matches it will complain.

Hope this helps
david jencks


>
> Regards,
>
> Norbert
> -----Urspr√ľngliche Nachricht-----
> Von: Mark Aufdencamp [mailto:mark@aufdencamp.com]
> Gesendet: Dienstag, 27. Februar 2007 16:34
> An: user@geronimo.apache.org
> Betreff: RE: AW: Accessing the local interface of an Session EJB  
> from a WAR
>
> I'm not sure about the answer to your question.  I was under the  
> impression that an EAR had to be in place for a local definition  
> and subsequent invocation, but haven't gotten that far in my  
> learning curve yet.
>
> My approach to learning EJB's on Geronimo was to:
>
> 1. Build a simple stateless session bean with a method that  
> returned a String and manage to get it deployed.  I'm using  
> MyEclipse, and it along with their tutorials on EJB and XDoclet  
> helped immensely.  They also have a tutorial on EAR's that I'm just  
> starting to work through.
>
> 2. Call the EJB from an Eclipse Debug session as a remote object.   
> This is standard J2EE stuff that required the right JNDI lookup  
> information and the proper client libraries to be defined in the  
> classpath
>
> 3. Make the same call from inside a webapp JSP.  I did this with a  
> remote lookup, as most of the examples I viewed did this.  I  
> finally found the <pattern> info for the <ejb-ref> component  
> documented in the 1.2 documentation yesterday and got my sample going.
>
> I would guess that you'll want/need an ejb-jar.xml, and an openejb- 
> jar.xml in your EJB deployment.
> -------- Original Message --------
> Subject: AW: Accessing the local interface of an Session EJB from a  
> WAR
> From: "Norbert Rieger" <nrieger@lplusr.de>
> Date: Tue, February 27, 2007 8:23 am
> To: <user@geronimo.apache.org>
>
> Hi Mark,
>
> thanks a lot for your detailed explanations.
>
> 1. I thought <ejb-ref> is used for accessing the remote interface,  
> for the local interface <ejb-local-ref> with children <local> and  
> <local-home> must be used. Isn't this correct ?
>
> I've neither an openejb-jar.xml nor an ejb-jar.xml in my war file,  
> only web.xml and geronimo-web.xml. If it's necessary the have them  
> in the web app, I'll added them....
>
> regards,
>
> Norbert
> -----Urspr√ľngliche Nachricht-----
> Von: Mark Aufdencamp [mailto:mark@aufdencamp.com]
> Gesendet: Dienstag, 27. Februar 2007 16:01
> An: user@geronimo.apache.org
> Betreff: RE: Accessing the local interface of an Session EJB from a  
> WAR
>
>
> Hi Norbert,
>
> I'm no expert here, but just got done working on a similar learning  
> curve.  I believe that local can only be defined if an EAR/ 
> application.xml/ geronimo-application.xml file exist, defining an  
> enterprise application project.  I'm using a remote rather than  
> local session bean and managed to get it to work. Your problem is  
> most likely all about deployment descripitors and package  
> dependencies.
>
> So here goes:
>
> 1. web.xml - This should have an <ejb-ref> component.  It should  
> contain a <ejb-ref-name> which serves as the local JNDI lookup  
> suffix.  It will serve as the lookup string for the Context.lookup 
> ("java:comp/env/ejb/MfcSessionEJB").  It also serves as the linkage  
> to the <ref-name> in the geronimo-web.xml.  This will factory a  
> MfcSessionEJBHome object for       creation of a reference to a  
> MfcSessionEJB.  It should also contain a <ejb-ref-type> along with  
> a <home> and <remote>, which serves as the link to the EJB  
> definition in the geronimo deployment descripitor for the webapp  
> (geronimo-web.xml)
>
>
> ...
> <ejb-ref>
>      <ejb-ref-name>ejb/MfcSessionEJB</ejb-ref-name>
>      <ejb-ref-type>Session</ejb-ref-type>
>      <home>gltd.domain.app.interfaces.MfcSessionEJBHome</home>
>      <remote>gltd.domain.app.interfaces.MfcSessionEJB</remote>
> </ejb-ref>
> ...
>
>
> Servlet/JSP code snippet:
>
> Context ctx = new InitialContext();
> MfcSessionEJBHome mfcSessionHome = (MfcSessionEJBHome) ctx.lookup 
> ("java:comp/env/ejb/MfcSessionEJB");
> MfcSessionEJB mfcSession = mfcSessionHome.create();
>
>
> 2. geronimo-web.xml - This deployment descriptor needs two  
> components.  It needs an <ejb-ref> that matches the web.xml <ejb- 
> ref-name>  and defines the deployed EJB module as a pattern(module  
> group/artifact/version/type).  This serves as the linkage between  
> the web.xml and the container for name service purposes.  Second it  
> needs to define the EJB module as a dependency for the webapp with  
> a <dependencies><dependency> in the <environment> section.  This  
> allows access for the webapp Classloader to the EJB module.
>
> ...
> <environment>
>      <moduleId>
>      ...
>      </moduleId>
>      <dependencies>
>           <dependency>
>                <groupId>default</groupId>
>                <artifactId>MfcSessionEJB</artifactId>
>                <version>1.0</version>
>                <type>car</type>
>           </dependency>
>      </dependencies>
> </environment>
> <ejb-ref>
>      <!-- geronimo-web.xml.<ref-name> == web.xml.<ejb-ref-name> -->
>      <ref-name>ejb/MfcSessionEJB</ref-name>
>      <pattern>
>           <groupId>default</groupId>
>           <artifactId>MfcSessionEJB</artifactId>
>           <version>1.0</version>
>           <type>car</type>
>      </pattern>
> </ejb-ref>
> 3. ejb-jar.xml  - Needs a <enterprise-bean><session> entry which  
> can be generated by XDoclet.  The <ejb-name> here needs to match  
> the <ejb-name> defined in the openejb-jar.xml.  The webapp  
> appaerntly also uses the <home> and <remote> values here to  
> validate the EJB signature at webapp deployment time.
>
> ...
> <enterprise-beans>
>      <session>
>           <description>My MFC Session EJB</description>
>           <display-name>MFC Session EJB</display-name>
>           <ejb-name>MfcSessionEJB</ejb-name>
>           <home>gltd.domain.app.interfaces.MfcSessionEJBHome</home>
>           <remote>gltd.domain.app.interfaces.MfcSessionEJB</remote>
>           <ejb-class>gtld.domain.app.ejb.MfcSessionEJB</ejb-class>
>           <session-type>Stateless</session-type>
>           <transaction-type>Container</transaction-type>
>     </session>
> </enterprise-beans>
> ...
>
>
> 4. openejb-jar.xml - This needs a <enterprise-beans><session>  
> component.  The <ejb-name> needs to match the ej-jar.xml <ejb-name>  
> as previously stated.  The <jndi-name> does not appear to be used  
> for referenc within the container but would be required for a stand  
> alone app call to the EJB.
>
> ...
> <enterprise-beans>
>      <session>
>           <ejb-name>MfcSessionEJB</ejb-name>
>           <jndi-name>ejb/MfcSessionEJB</jndi-name>
>     </session>
> </enterprise-beans>
> ...
>
>
> 5. No additional libraries needed to be deployed with the WAR to  
> make the EJB lookup and method invocations.
>
>
> Hope this helps.  I spent a week and a half figuring this out on my  
> own.  If you'ld like to try calling the EJB from a app client,  I  
> can help with that as well.
>
> Mark Aufdencamp
> Mark@Aufdencamp.com
>
>
>
> -------- Original Message --------
> Subject: Accessing the local interface of an Session EJB from a WAR
> From: "Norbert Rieger" <nrieger@lplusr.de>
> Date: Tue, February 27, 2007 4:08 am
> To: <user@geronimo.apache.org>
>
> Hello,
>
> I try to connect from my web application to an existing Session EJB
> (MfcSession) thru it's local interface.
> Both, the WAR and the EJB, are running within the same geronimo
> installation. When installing the web app I get the following message:
>
> Deployer operation failed: Could not find an EJB for reference  
> MfcSession to
> a local session bean that has the home interface
> de.lplusr.module.mfc.ejb.MfcSessionLocalHome and the local interface
> de.lplusr.module.mfc.ejb.MfcSessionLocal
> org.apache.geronimo.common.UnresolvedEJBRefException: Could not  
> find an EJB
> for reference MfcSession to a local session bean that has the home  
> interface
> de.lplusr.module.mfc.ejb.MfcSessionLocalHome and the local interface
> de.lplusr.module.mfc.ejb.MfcSessionLocal
>
> How do I connect to an EJB thru it's local interface, what's wrong  
> with my
> configuration ?
>
> Any help or advice is appreciated, thanks a lot in advance.
>
> Norbert
>
>
> This is my configuration:
>
> Geronimo 1.1.1
> JDK 1.5.0_10
> Windows XP Prof
>
>
> web.xml:
>
> <ejb-local-ref>
>        <ejb-ref-name>MfcSession</ejb-ref-name>
>        <ejb-ref-type>Session</ejb-ref-type>
>        <local-home>de.lplusr.module.mfc.ejb.MfcSessionLocalHome</ 
> local-home
> >
>        <local>de.lplusr.module.mfc.ejb.MfcSessionLocal</local>
>        <ejb-link>MfcSession</ejb-link>
> </ejb-local-ref>
>
> geronimo-web.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <web-app
> xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1"
>   xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1"
>   xmlns:naming="http://geronimo.apa che.org/xml/ns/naming-1.1"
>   xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1">
> <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
>   <moduleId>
>     <groupId>lplusr</groupId>
>     <artifactId>sys</artifactId>
>     <version>1.0</version>
>   </moduleId>
>   <dependencies>
>   <dependency>
>   <groupId>ejb</groupId>
>                  <artifactId>mfc-ejb</artifactId>
>                  <version>1.0</version>
>                  <type>jar</type>
>            </dependency>
>   </dependencies>
> </environment>
> <context-root>/sys</context-root>
> &l t; ;ejb-local-ref>
> <ref-name>MfcSession</ref-name>
> <ejb-link>MfcSession</ejb-link>
> </ejb-local-ref>
> </web-app>
>
>
> The EJB descriptor is:
>
> <?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 id="ejb-jar_1">
>
>   <description><![CDATA[mfc-ejb-1.0 generated by eclipse wtp xdoclet
> extension.]]></description>
>   <display-name>mfc-ejb-1.0</display-name>
>
>   <enterprise-beans>
>
>      <!-- Session Beans -->
>      <session id="Session_MfcSession">
>         <description><![CDATA[An EJB for remote access of
> MFC]]></description>
>         <display-name>MfcSession</display-name>
>
>         <ejb-name>MfcSession</ejb-name>
>
>         <home>de.lplusr.module.mfc.ejb.MfcSessionHome</home>
>         <remote>de.lplusr.module.mfc.ejb.MfcSession</remote>
>         <local-home>de.lplusr.module.mfc.ejb.MfcSessionLocalHome</ 
> local-hom
> e>
>         <local>de.lplusr.module.mfc.ejb.MfcSessionLocal</local>
>         <ejb-class>de.lplusr.module.mfc.ejb.MfcSessionSession</ejb- 
> class>
>         <session-type>Stateful</session-type>
>         <transaction-type>Container</transaction-type>
>
>      </session>
>
> </ejb-jar>


Mime
View raw message