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
Does anyone know how to install an EJB in the deploy directory and access
it from the default-app? How do you set the _context variable?
What, specifically, goes into an ejb-jar.xml file? What , specifically,
goes into a deploy.properties file?
Here is the structure of my ejb.jar file:
C:\projects\mathexp>jar cvf mathexp_ejb.jar ejbeans/*.class
META-INF/ejb-jar.xml
added manifest
adding: ejbeans/MathExp.class(in = 350) (out= 219)(deflated 37%)
adding: ejbeans/MathExpBean.class(in = 4712) (out= 2395)(deflated 49%)
adding: ejbeans/MathExpHome.class(in = 407) (out= 244)(deflated 40%)
adding: ejbeans/MathExpPK.class(in = 753) (out= 452)(deflated 39%)
adding: META-INF/ejb-jar.xml(in = 890) (out= 372)(deflated 58%)
Here is 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>
Here is my deploy.properties file:
#
#Tue Oct 23 16:21:51 CDT 2001
ejb.homeInterfaceClassName=ejbeans.MathExpHome
ejb.enterpriseBeanClassName=ejbeans.MathExpBean
orcl.ejipt.minFreeConnections=5
ejb.primaryKeyClassName=ejbeans.MathExpPK
orcl.ejipt.sourceURL=jdbc\:oracle\:thin\:@127.0.0.1\:1521\:orcl
ejb.ejipt.classServer.port=2323
ejipt.jdbcSources=orcl
ejipt.logStackTrace=true
orcl.ejipt.sourcePassword=maxalex
orcl.ejipt.sourceDriverClassName=oracle.jdbc.driver.OracleDriver
ejb.remoteInterfaceClassName=ejbeans.MathExp
ejb.ejipt.home.port=2323
orcl.ejipt.maxConnections=30
orcl.ejipt.maxFreeConnections=10
orcl.ejipt.sourceUser=jack
ejipt.ejbJars=mathexp_ejb.jar,
ejb.ejipt.classServer.host=martin
Here is my MathExpServlet:
import java.io.*;
import java.rmi.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import javax.servlet.*;
import javax.servlet.http.*;
import ejbeans.*;
import java.security.Principal;
public class MathExpServlet extends HttpServlet {
protected void service(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
String expid = null;
String expression = null;
try {
final HttpSession session = req.getSession(true);
expid = req.getParameter("expidfield");
expression = req.getParameter("expressionfield");
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
("ejbeans.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
}//end try
catch (NamingException ne) {
throw new ServletException(ne);
}//end catch
catch (CreateException ce) {
throw new ServletException(ce);
}//end catch
super.service(req, res);
}//end method - service
public void doGet(final HttpServletRequest req, final HttpServletResponse
res) throws IOException, ServletException {
final HttpSession session = req.getSession(true);
final MathExp mathexp = (MathExp) session.getAttribute("MathExpBean");
try {
//initialize the expression as a req variable which can be displayed
by the JSP
req.setAttribute("expid", new String(mathexp.get_expID()));
req.setAttribute("expression", new String(mathexp.get_expression()));
}//end try
catch (final RemoteException server) {
if (server.detail instanceof SecurityException)
req.setAttribute("SecurityError", "Set MathExp");
else
throw new ServletException(server);
}//end catch
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println(req.getAttribute("expid"));
out.println("<hr>");
out.println(req.getAttribute("expression"));
//req.getRequestDispatcher("MathExpDisplay.jsp").forward(req, res);
//use a JSP page to display the MathExp
}//end method - doGet
}//end class - MathExpServlet
My enterprise Java Bean is located in: C:\JRun\servers\default\deploy
My MathExpServlet is located in: C:
\JRun\servers\default\default-app\WEB-INF\classes
Here is my error:
servlet/MathExpServlet:
ejbeans.MathExpHome not found
javax.naming.NameNotFoundException: ejbeans.MathExpHome not found
at allaire.ejipt.
_NamingContext.lookup(allaire/ejipt/_NamingContext.java:115)
at allaire.ejipt.
_ClientContext.lookup(allaire/ejipt/_ClientContext.java:147)
at javax.naming.InitialContext.lookup(InitialContext.java:350)
at MathExpServlet.service(MathExpServlet.java:25)
I am going insane trying to figure this out!! Someone help me, please!!!!!
Jack D. Martin
(312)606-2319
[EMAIL PROTECTED]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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