File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Need Help in understanding the ctx.lookup for looking up a ejb Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Need Help in understanding the ctx.lookup for looking up a ejb" Watch "Need Help in understanding the ctx.lookup for looking up a ejb" New topic
Author

Need Help in understanding the ctx.lookup for looking up a ejb

Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 573
I am trying to call a EJB from a servlet, but not sure what string I need to pass in:

I have noticed lots of different examples:

I understand it starts with java:comp/

I see that some have added env or ejb or env/ejb followed by a name.

In my web.xml and weblogic.xml

<ejb-ref-name> <ejb-link> are set to TradeObject
<jndi-name> is set to BrokerEJB/TradeObject

BrokerEJB is the name of the jar that the TradeBean sits in.

My question is

after java:comp do I need the string env, do I need the string ejb and the string after does it refer to the <ejb-ref-name> the <ejb-link> the <jndi-name> in the WAR xml files.

or does it refer to the <ejb-name> or <jndi-name> in the weblogic-ejb-jar.xml which is also set to TradeObject.

Thanks for any help

Tony
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10093
    
164

Can you post the entire contents inside the ejb-ref tag, so that i can tell you the exact name to lookup?


[My Blog] [JavaRanch Journal]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10093
    
164

In general, if you have your:



Then the bean will be bound to the java:comp/env/someReferenceNameToTheEJB

So your lookup code will be:



Here's an extract from the web.xml dtd which has an explanation for the same:

The ejb-ref-name element contains the name of an EJB reference. The
EJB reference is an entry in the web application's environment and is
relative to the java:comp/env context. The name must be unique
within the web application.

[ July 26, 2006: Message edited by: jaikiran pai ]
Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 573
Thanks for replying:

My web.xml is


<ejb-ref>
<ejb-ref-name>TradeObject</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>mbrokearage.broker.co.sessionBean.stateless.trades.TradesHome</home>
<remote>brokearage.broker.co.sessionBean.stateless.trades.Trades</remote>
<ejb-link>TradeObject</ejb-link>
</ejb-ref>

my weblogic.xml is:

ejb-ref-description>
<ejb-ref-name>TradeObject</ejb-ref-name>
<jndi-name>BrokerEJB/TradeObject</jndi-name>
</ejb-ref-description>

in the servlet I have:

ejbObject = ctx.lookup("java:comp/env/TradeObject");

Thanks for any help

Tony
Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 573
soz its

<ejb-ref>
<ejb-ref-name>TradeObject</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>brokearage.broker.co.sessionBean.stateless.trades.TradesHome</home>
<remote>brokearage.broker.co.sessionBean.stateless.trades.Trades</remote>
<ejb-link>TradeObject</ejb-link>
</ejb-ref>

I added a m by mistake when typing it in: it still not working.

Thanks for any help

Tony
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10093
    
164

Do you have an entry of ejb-ref in weblogic.xml as well? If yes, then going by your previous post, the jndi-name that you have given there is BrokerEJB/TradeObject.

Your lookup in that case should look like:



By the way, what is it that is not working? Are you seeing any exceptions when doing a lookup?
Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 573
Thanks it is up and running, thanks again you have been a real help

Tony
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Help in understanding the ctx.lookup for looking up a ejb