permaculture playing cards*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Calling EJB from action class" Watch "Calling EJB from action class" New topic
Author

Calling EJB from action class

Radhakrishnan Iyyengar
Greenhorn

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:

ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<description>EJB JAR description</description>
<display-name>EJB JAR</display-name>
<enterprise-beans>
<session>
<ejb-name>SessionFacadeBean</ejb-name>
<home>licenseModule.SessionFacadeHome</home>
<remote>licenseModule.SessionFacade</remote>
<ejb-class>licenseModule.SessionFacadeBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-local-ref>
<ejb-ref-name>ejb/declarationBean</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>licenseModule.LicenseDeclarationBMPLocalHome</local-home>
<local>licenseModule.LicenseDeclarationBMPLocal</local>
<ejb-link>LicenseDeclarationBMPBean</ejb-link>
</ejb-local-ref>
</session>
</enterprise-beans>
</ejb-jar>


ejb-j2ee-engine.jar
ejb-j2ee-engine.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-j2ee-engine SYSTEM "ejb-j2ee-engine.dtd">
<ejb-j2ee-engine>
<enterprise-beans>
<enterprise-bean>
<ejb-name>SessionFacadeBean</ejb-name>
<jndi-name>ejb/facade</jndi-name>
<session-props/>
</enterprise-bean>
<enterprise-bean>
<ejb-name>LicenseDeclarationBMPBean</ejb-name>
<entity-props/>
</enterprise-bean>
<enterprise-bean>
<ejb-name>AccessSAPBean</ejb-name>
<session-props/>
</enterprise-bean>
<enterprise-bean>
<ejb-name>LicenseMasterBMPBean</ejb-name>
<entity-props/>
</enterprise-bean>
</enterprise-beans>
</ejb-j2ee-engine>

And the call is issued like this:
try
{
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
Sheriff

Joined: Nov 09, 2000
Posts: 6450
"Radhakrishnan",

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
Greenhorn

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

I am getting a naming exception:

java.lang.Exception: com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException

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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Calling EJB from action class
 
Similar Threads
NameNotFoundException in EJB? could anyone tell me?
NameNotFoundException in EJB? could anyone tell me?
JNDI Name not found error in SUN ONE SERVER
InitialContext for EJB 2.x JNDI on Glassfish v2ur2 under Windows Vista
How to get the datasource from Bean through deployment descriptor