Does anyone know the correct way to get a Servlet to talk to an EJB using
JRun?
I placed my EJB in the C:\JRun\servers\default\deploy directory. I placed
my Servlet in the C:\JRun\servers\default\default-app\WEB-INF\classes
directory. Here is the snippet of code that I use for retrieving the EJB
through a JNDI context:
if (session.getAttribute("MathExpBean") == null) {
Properties properties = new Properties();
properties.setProperty("java.naming.factory.initial",
"allaire.ejipt.ContextFactory");
properties.setProperty(Context.PROVIDER_URL,
"ejipt://martin:2323");
Context context = new InitialContext(properties);
MathExpHome home =
(MathExpHome)javax.rmi.PortableRemoteObject.narrow(context.lookup
("MathExpHome"), MathExpHome.class);
MathExp mathexp;
try {
mathexp = (MathExp) home.findByPrimaryKey(expid);
}//end try
catch(FinderException fe) {
mathexp = home.create(expid, expression); // not found, so
create it
}//end catch
// cache the ejb in the session so we don't have to create it every
time
session.setAttribute("MathExpBean", mathexp);
context.close();
}//end if
Here is the contents of my ejb-jar.xml file:
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD
EnterpriseJavaBeans 1.1//EN"
"http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd">
<ejb-jar>
<description>Mathematical Expression Bean</description>
<display-name>Mathematical Expression Bean</display-name>
<enterprise-beans>
<entity>
<display-name>MathExpBean</display-name>
<ejb-name>MathExpHome</ejb-name>
<home>ejbeans.MathExpHome</home>
<remote>ejbeans.MathExp</remote>
<ejb-class>ejbeans.MathExpBean</ejb-class>
<prim-key-class>ejbeans.MathExpPK</prim-key-class>
<persistence-type>Bean</persistence-type>
<reentrant>False</reentrant>
<env-entry>
<env-entry-name>ejb.allowedIdentities</env-entry-name>
<env-entry-value>all</env-entry-value>
</env-entry>
</entity>
</enterprise-beans>
</ejb-jar>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get the mailserver that powers this list at http://www.coolfusion.com
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists