• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Calling EJB from action class

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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?
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Radhakrishnan Iyyengar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!