Make sure that your EJB is truly deployed. I'm not sure if JRun will deploy
an EJB just because it is sitting in the deploy directory or not. We always
explicitly deploy our beans. You can use the JMC to verify that your EJB is
deployed and available.
You also need to make sure that your client is given permission to use the
EJB. You can do this by adding the following line to your deploy.properties
file before you deploy your EJB.
ejb.allowedIdentities=all
Here is an example of some code that loads the remote interface for a bean
whose home interface is "OrgTreeHome" and whose remote interface is
"OrgTree". The implementation class is "OrgTreeBean". Since your bean
appears to be an entity bean, you will use findByPrimaryKey() instead of
create().
System.setSecurityManager( new RMISecurityManager() );
OrgTree returnTree = null;
try
{
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"allaire.ejipt.ContextFactory");
props.setProperty("java.naming.provider.url",
"ejipt://127.0.0.1:2323");
InitialContext ctx = new InitialContext( props );
OrgTreeHome home = (OrgTreeHome)ctx.lookup("OrgTreeBean");
returnTree = (OrgTree)home.create();
}
catch( Exception e )
{
System.out.println("Error retrieving org tree.");
returnTree = null;
}
Note that my experience is with JRun 3.0 sp2. A few things may be different
for JRun 3.1.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 10, 2001 10:53 AM
To: JRun-Talk
Subject: Servlet clients for EJBS
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>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Your ad could be here. Monies from ads go to support these lists and provide more
resources for the community. http://www.fusionauthority.com/ads.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists