Stateless Session Bean Methods from MDB

Hello Friends,I need to call methods of stateless session beans from my Message Driven Bean. Can anyone help me out?Example code would really be appreciated.Please reply back asap.
[208 byte] By [pn24256a] at [2007-10-3 3:22:55]
# 1

The easiest way is to just inject a reference the bean using EJB 3.0

@MessageDriven

public class FooMDB implements javax.jms.MessageListener {

@EJB

private BarLocal bar;

public void onMessage(Message m) {

...

bar.foobar();

}

See the Java EE 5 Tutorial for more examples :

http://java.sun.com/javaee/5/docs/tutorial/doc/

ksaksa at 2007-7-14 21:15:22 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
? MDBs often call session beans for business processing, and the code for that is the same as any other bean client.Did you run onto some specific problem(s)?
karma-9a at 2007-7-14 21:15:22 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

> The easiest way is to just inject a reference the

> bean using EJB 3.0

>

> @MessageDriven

> public class FooMDB implements

> javax.jms.MessageListener {

>

>@EJB

> private BarLocal bar;

>

>public void onMessage(Message m) {

>...

>

>bar.foobar();

>

> See the Java EE 5 Tutorial for more examples :

>

> http://java.sun.com/javaee/5/docs/tutorial/doc/

Thanks for your early reply.

But the problem with me is we are not using EJB3.0. I am totally new to EJB's and got assigned with this.

Please help me out.

Thanks,

Prakash

pn24256a at 2007-7-14 21:15:22 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Hi Prakash,

If you're using J2EE 1.4 you can use the J2EE 1.4 tutorial instead :

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/

The pre-EJB 3.0 approach for getting references to ejbs involves two things :

1) declaring the ejb-ref(for remote ejbs) or ejb-local-ref (for local ejbs) in the *client* component's deployment descriptor.

Here's an example :

<ejb-local-ref>

<ejb-ref-name>bar_ejbref</ejb-ref-name>

<ejb-ref-type>Session</ejb-ref-type>

<local-home>com.acme.BarLocalHome</local-home>

<local>com.acme.BarLocal</local>

<ejb-link>BarBean</ejb-link>

</ejb-local-ref>

2) looking up the dependency in the private component environment (java:comp/env)

InitialContext ic = new InitialContext();

BarLocalHome barLocalHome = (BarLocalHome) ic.lookup("java:comp/env/bar_ejbref");

Notice how the portion of the lookup string after "java:comp/env/" matches the name of the ejb-local-ref dependency (ejb-ref-name)

--ken

ksaksa at 2007-7-14 21:15:22 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...