Two Laptop Bag
The moose likes Struts and the fly likes Calling EJB from action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Calling EJB from action class" Watch "Calling EJB from action class" New topic

Calling EJB from action class

Radhakrishnan Iyyengar

Joined: Jul 02, 2005
Posts: 2
Hello folks,

I am new to the Struts framework. I am facing a vexing problem - I am unable to access my session facade bean from the action class. The relevant portions of the xmls are attached below:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "">
<description>EJB JAR description</description>
<display-name>EJB JAR</display-name>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-j2ee-engine SYSTEM "ejb-j2ee-engine.dtd">

And the call is issued like this:
InitialContext ctx = new InitialContext();
SessionFacadeHome home = (SessionFacadeHome)ctx.lookup("ejb/facade");
SessionFacade remote = home.create();

//Call the method of the facade to retrieve the license names.
c = remote.GetAllLicenseNames(sClientID);

I am using NetWeaver Studio for development. Thanks for taking the time to read my post. Any help will be appreciated.
Jason Menard

Joined: Nov 09, 2000
Posts: 6450

Welcome to JavaRanch. We don't have many rules here, but we do have a naming policy that is presented to users upon registration and which we try to strictly enforce. Please re-read this document and edit your display name accordingly.

As for your question, what kind of errors are you getting?
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
As your Action cannot be an application client, I would expect environment properties (in a Hashtable) to be passed into the constructor of InitialContext. Check your EJB container's documentation for what you need to do.

SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Radhakrishnan Iyyengar

Joined: Jul 02, 2005
Posts: 2
Jason: profile updated per instructions.

I am getting a naming exception:


Object not found in lookup, the entire lookup is ejb/facade.

The problem persists even with lookups that specify java:comp/env/ejb/facade or java:/ejb/facade.

The problem goes away if I use the runtime JNDI assigned by the server from NetWeaver's visual admin tool.

My questions are:

1. If I add the target bean to web.xml, can I still not use the reference name to lookup the object from the struts controller (actionclass)?

2. If not, the java:comp/env/ lookup cannot ever be used from a struts controller? I will have to stick with the runtime JNDI assignment made by the EJB container to the bean? This would cause obvious problems since the JNDI has to be hard-coded within the actionclass, not to mention maintenance if my application has to be ported on a different app server.

Roger: I have not passed initialcontext() parameters, but I can access the facade bean using direct JNDI lookup.

Any insights/corrections will be appreciated.
[ July 04, 2005: Message edited by: Radhakrishnan Iyyengar ]
I agree. Here's the link:
subject: Calling EJB from action class
It's not a secret anymore!