users@glassfish.java.net

Re: How to access local interface from MDB?

From: <glassfish_at_javadesktop.org>
Date: Wed, 10 Dec 2008 11:24:04 PST

Let me clarify a couple of the restrictions in play here.

1. The Local EJB view can only portably be accessed by other EJBs/web components within the same application.

2. There are no portable *global* JNDI names associated with Local EJB references. Local EJB
references can be looked up. It's just that the lookup names only exist when declared as part of
either an ejb-local-ref or @EJB annotation.

So, the only portable way to add some kind of dynamic lookup of any of the Local EJBs in the
app from the MDB is to define an ejb-local-ref or @EJB for every one of them. Then, just pick
amongst those names for the actual lookup.

E.g., put the following at the class level of the MDB class :

@EJB(name="Local1Ref", beanInterface="Local1.class")
@EJB(name="Local2Ref", beanInterface="Local2.class")

...

Then in the message listener method :

  String target = .... ; // set to "Local1Ref", "Local2Ref", etc.
  Local1 local1Ref = (Local1) new InitialContext().lookup("java:comp/env/" + target);
[Message sent by forum member 'ksak' (ksak)]

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