users@glassfish.java.net

How to look up local bean from servlet

From: <glassfish_at_javadesktop.org>
Date: Mon, 28 Sep 2009 07:53:31 PDT

Hi,

I am trying to get a reference of the local interface of a stateless session bean from a servlet.
The bean is in an ejb module, the servlet in an web module. Both are part of an ear.

Since they are in the same ear, it should be possible to access the local interfrace from the servlet. But I can't accomplish that.
It works fine when I'm using the Remote interface, but I want to use the Local for performance reasons.

Here are the interesting parts of the code:

/* TiccBean (in ejb module) */
@Stateless
@Local(Ticc.class)
public class TiccBean implements Ticc {
... }
// where Ticc is a simple interface with some methods
// sun-ejb-jar and ejb-jar files are empty, they only contain the xml prolog and root tag

/* lookup in the web module */
  InitialContext ctx = new InitialContext();
  ticc = (Ticc) ctx.lookup("java:comp/env/Ticc");
//ticc = (Ticc) ctx.lookup(Ticc.class.getName());
// the commented line works when I am using the remote interface

/* web.xml */
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        id="WebApp_ID" version="2.5">
...
        <ejb-local-ref>
                <ejb-ref-name>Ticc</ejb-ref-name>
                <ejb-ref-type>Session</ejb-ref-type>
                <local>com.ticc.beans.Ticc</local>
        </ejb-local-ref>
....
I've also tried to use "ejb/Ticc" as ejb-ref-name in ejb-local-ref and for the lookup, but that doesn't work either.
I've also tried all kinds of names and combinations for the lookup, or to use the name and mappedName attributes of the Stateless annotation, all with the same result.

The exception I get is just "Invocation Exception", no stack trace, no details, nothing.
I am using Glassfish v2.1.

I would appreciate if somebody could tell me what I am doing wrong, or to post a link to a working example.
Unfortunately, the Glassfish tutorial doesn't cover this problem. There are only sections for remote lookup or local lookup from within the ejb module... I can't believe that nobody has both ejb and web module within the same ear. There are many threads and listings in the web covering the same problem, all without a working solution...

Regards,
EnCey
[Message sent by forum member 'encey' (martin.enzelsberger_at_gmail.com)]

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