users@glassfish.java.net

Re: an EJB2.1 stateless session bean with remote and local interface -- how

From: <glassfish_at_javadesktop.org>
Date: Fri, 11 Jan 2008 22:04:24 PST

Hi Dies

Here is the EAR file (attached)

I did not follow your other suggestions quite yet... I wanted you to see the EAR as is.

I did remove the "ejb-ref" tag from the ejb-jar.xml, because Marina seemed to indicate that the "sun-ejb-jar.xml" was what "controlled" the remote JNDI lookup.

I left the "ejb-local-ref" tag (containing an "ejb-link" sub-tag) in ejb-jar.xml.

[b]***ejb.jar.xml***[/b]
[code]
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="2.1" 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/ejb-jar_2_1.xsd">
    <display-name>dddEAR-ejb</display-name>
    <enterprise-beans>
        <session>
            <display-name>DddEJBSB</display-name>
            <ejb-name>DddEJBBean</ejb-name>
            <home>ddd.ejb.DddEJBRemoteHome</home>
            <remote>ddd.ejb.DddEJBRemote</remote>
            <local-home>ddd.ejb.DddEJBLocalHome</local-home>
            <local>ddd.ejb.DddEJBLocal</local>
            <ejb-class>ddd.ejb.DddEJBBean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>
            <ejb-local-ref>
                <ejb-ref-name>DddEJBLocalHome</ejb-ref-name>
                <ejb-ref-type>Session</ejb-ref-type>
                <local-home>ddd.ejb.DddEJBLocalHome</local-home>
                <local>ddd.ejb.DddEJBLocal</local>
                <ejb-link>dddEAR-ejb.jar#DddEJBBean</ejb-link>
            </ejb-local-ref>
        </session>
        </enterprise-beans>
    <assembly-descriptor>
        <container-transaction>
            <method>
                <ejb-name>DddEJBBean</ejb-name>
                <method-name>*</method-name>
            </method>
            <trans-attribute>Required</trans-attribute>
        </container-transaction>
        </assembly-descriptor>
    </ejb-jar>
[/code]

[b]***sun-ejb-jar.xml***[/b]
[code]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
<sun-ejb-jar>
  <enterprise-beans>
    <ejb>
      <ejb-name>DddEJBBean</ejb-name>
      <jndi-name>ejb/DddEJBBean</jndi-name>
    </ejb>
  </enterprise-beans>
</sun-ejb-jar>
[/code]

***DddHelper.java (POJO that performs the JNDI lookup)***
[code]
package ddd.ejb;

import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class DddHelper {

    private String field1 = "...value of field1 in DddHelper.java...";

    public String getField1()
    {
        return this.lookupDddEJBBean().getField1() + this.field1;
    }
    
    private DddEJBLocal lookupDddEJBBean() {
        try {
            Context c = new InitialContext();
            DddEJBLocalHome rv = (DddEJBLocalHome) c.lookup("java:comp/env/DddEJBLocalHome");
            return rv.create();
        } catch (NamingException ne) {
            java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        } catch (CreateException ce) {
            java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", ce);
            throw new RuntimeException(ce);
        }
    }
}
[/code]

BTW - The location of the sun-ejb-jar.xml in the directory structure of the "enterprise" project, etc, was been determine automatically by the NetBeans 6.0 IDE.
-- I did not consciously choose the location for these config files.

Let me know what you can tell from looking at the EAR...

Like I wrote earlier... I cant tell if the problem lies with the JNDI name I'm using when doing the lookup, or the configuration files, or both. If I could verify what one should be, then I could deduce the other.

NOTE: I had to remove the following files from the root of the EAR...
1. commons-beanutils.jar
2. commons-collections.jar
3. commons-digester.jar
4. commons-logging.jar
5. jsf-api.jar
6. jsr311-api.jar
7. jstl.jar
I removed the following files from the "lib" directory in the web piece
1. jsf-impl.jar
2. standard.jar

This was the only way java.net would allow me to attach the EAR(size restrictions)... the rest of the ear -- including the config files -- should be in tact.

Thanks again!

sd
[Message sent by forum member 'sairndain' (sairndain)]

http://forums.java.net/jive/thread.jspa?messageID=253528