📄 ejb.xtp
字号:
<s1 title="EJB Clients"><s2 title="Resin-EJB"><p>Configuring with Resin-EJB as a client uses theBurlapContextFactory as a JNDI link. The client will useJNDI to lookup the EJB home interfaces.</p><example title="Resin-EJB with Burlap"><web-app> <jndi-link> <jndi-name>java:comp/env/ejb</jndi-name> <jndi-factory>com.caucho.burlap.BurlapContextFactory</jndi-factory> <init-param java.naming.provider.url="http://host.com/burlap"/> </jndi-link></web-app></example><p>Sample client code follows. The EJBHome lookup is in the <code/init()/>method for efficiency.</p><example title="Client Servlet">import javax.servlet.*;import javax.namingdservlet.*;public class ClientServlet extends GenericServlet { TestHome home; public void init() throws ServletException { try { Context env = (Context) new InitialContext().lookup("java:comp/env"); home = (TestHome) env.lookup("ejb/test"); } catch (Exception e) { throw new ServletException(e); } } public void service(ServletRequest req, ServletResponse res) throws IOException ServletException { try { PrintWriter out = res.getWriter(); Test test = home.findByPrimaryKey("test"); out.println("test:" + test.hello()); } catch (Exception e) { throw new ServletException(e); } }}</example><p>Configuring with Resin-EJB and Hessian is the same as withBurlap. Only the names change.</p><example title="Resin-EJB with Hessian"><web-app> <jndi-link> <jndi-name>java:comp/env/ejb</jndi-name> <jndi-factory>com.caucho.hessian.HessianContextFactory</jndi-factory> <init-param java.naming.provider.url="http://host.com/hessian"/> </jndi-link></web-app></example></s2><s2 title="WebLogic"><example title="Sample WebLogic Configuration"><web-app> <classpath id='/usr/local/weblogic/myserver/clientclasses'/> <classpath id='/usr/local/weblogic/lib/weblogicaux.jar'/> <classpath id='/usr/local/weblogic/classes'/> <jndi-link> <jndi-name>java:comp/env/ejb/traderHome</jndi-name> <jndi-factory>weblogic.jndi.WLInitialContextFactory</jndi-factory> <init-param java.naming.provider.url="t3://localhost:7001"/> <jndi-lookup>statelessSession.TraderHome</jndi-lookup> </jndi-link></web-app></example><example title="Sample Use"><%@ page import='javax.naming.*' %><%@ page import='examples.ejb.basic.statelessSession.*' %><%@ page import='javax.rmi.*' %><%Context ic = new InitialContext();Object homeObj = ic.lookup("java:comp/env/ejb/traderHome");TraderHome home;home = (TraderHome) PortableRemoteObject.narrow(homeObj, TraderHome.class);Trader trader;trader = (Trader) PortableRemoteObject.narrow(home.create(), Trader.class);String stock = request.getParameter("stock");int shares = Integer.parseInt(request.getParameter("shares"));TradeResult result = trader.buy(stock, shares);%>Bought <%= result.getNumberTraded() %> <%= result.getStockSymbol() %><br><%trader.remove();%></example></s2><s2 title="Inprise Application Server"><p>From Damon Maria:</p><p>Got Resin 1.2 talking to IAS 4.1 the other day and just thought I'd share myexperiences to save someone else some time. </p><p>Here's what to do:</p><ol><li>Copy vbjorb.jar and vbejb.jar from AppServer/lib into resin/lib. Just addingthese into the <classpath .../> in resin.conf doesn't work.<li>Add the path to your beans into resin.conf:<example> <classpath id='c:/development/classes'/></example><li>Add the JNDI link from resin to the app server in resin.conf:<example><jndi-link> <jndi-name>java:comp/env/ejb</jndi-name> <jndi-factory>com.inprise.j2ee.jndi.CtxFactory</jndi-factory></jndi-link></example><li>Then connect to your beans in servlets/JSP, simply add "java:comp/env/ejb/"onto any JNDI paths you use to find your beans. Eg. if I have a bean at the appserver JNDI path of "TestSession" then in my servlet I use:<example>javax.naming.Context context = new javax.naming.InitialContext();Object ref = context.lookup("java:comp/env/ejb/TestSession");home = (TestSessionHome) javax.rmi.PortableRemoteObject.narrow(ref, TestSessionHome.class);</example></ol></s2><s2 title="Orion"><p>From Luciano Montebove:</p><p>To use Resin as an EJB client with Orion follow these steps:</p><ol><li>Under Orion do nothing :)<li>In Resin add orion.jar, ejb.jar, mail.jar (from orion) in your appWEB-INF/classes dir<li>In Resin in your app web.xml add these lines:<def><classpath id='WEB-INF/classes/orion.jar'/><classpath id='WEB-INF/classes/mail.jar'/><classpath id='WEB-INF/classes/ejb.jar'/><jndi-link> <jndi-name>java:comp/env/ejb</jndi-name> <jndi-factory>com.evermind.server.rmi.RMIInitialContextFactory </jndi-factory> <init-param java.naming.provider.url="ormi://myOrionHost/MyApp"/> <init-param java.naming.security.principal="admin"/> <init-param java.naming.security.credentials="xxx"/></jndi-link></def><li>Write your servlet/JSP as you would in Orion so for example if you have aSessionBean called MyBean (in your ejb-jar.xml) your lookup should use thisstring ("java:comp/env/ejb/MyBean")<li>It's all</ol></s2><s2 title="jBoss"><p>From Dave Dribin:</p><p>To have a Resin web application use jBoss, do the following:</p><ol><li>Copy "ejb.jar", "jboss-client.jar", and "jnp-client.jar" from$JBOSS_HOME/client into WEB-INF/lib.<li>Copy the EJB jar file that you put in $JBOSS_HOME/deploy intoWEB-INF/lib.<li>Put the following <web-app> into resin.conf:<example><web-app id='/web-app-path' app-dir='/real/path/of/web-app'> <jndi-link> <jndi-name>java:comp/env/ejb</jndi-name> <jndi-factory>org.jnp.interfaces.NamingContextFactory</jndi-factory> <init-param java.naming.provider.url="localhost:1099"/> </jndi-link></web-app></example><p>Of course change the JNDI URL if you're running jBoss on a differentmachine.</p><li>Make sure you map all of your EJBs to the "ejb/" JNDIcontext. For example, I have this in my jboss.xml:<example><enterprise-beans> <entity> <ejb-name>UserBean</ejb-name> <jndi-name>ejb/UserHome</jndi-name> </entity> .... other beans ....</enterprise-beans></example>This way you can lookup all the Home interfaces in the"java:comp/env/ejb/" context.</ol><p>I've attached a simple JSP that shows how to access the User EJB.</p><p>And don't forget that if you re-deploy your beans to jBoss, you shouldcopy over the jar file into WEB-INF and restart Resin.</p><p>Hope that helps!</p><p>-Dave</p><example><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>EJB Test</title> </head> <body bgcolor="#FFFFFF"> <%@ page import='javax.naming.*' %> <%@ page import='ejbeans.*' %> <%@ page import='javax.rmi.*' %> <h1 align=center>EJB Test</h1> <% // Get a naming context InitialContext jndiContext; Object ref; // Get a reference to a UserHome Bean jndiContext = new InitialContext(); ref = jndiContext.lookup("java:comp/env/ejb/UserHome"); int userPK; UserHome userHome; User user; userHome = (UserHome) PortableRemoteObject.narrow (ref, UserHome.class); userPK = Integer.parseInt(request.getParameter("pk")); user = userHome.findByPrimaryKey(new UserPK(userPK)); %> <table border="3" width="100%"> <tr> <th> ID </th> <th> First Name </th> <th> Last Name </th> </tr> <tr> <th> <%= user.getId() %> </th> <th> <%= user.getFirstName() %> </th> <th> <%= user.getLastName() %> </th> </tr> </table> </body></html></example></s2><s2 title="JOnAS"><p>From Pedro Costa:</p><p>To use Resin as an EJB client with JOnAS or Enhydra Enterprise follow these steps:</p><ol><li>Under JOnAS or Enhydra do nothing<li>Copy JEREMIE_jonas.jar (RMI_jonas.jar if you are using rmi and notjeremie) into WEB-INF/lib or resin1.2/lib.<p>If you are using JOnAS on the same machine as Resin you can do the sameby adding the following line to your app on resin.conf (assuming JOnAS is installed on \JONAS)</p><example><classpath id='/JONAS/lib/JEREMIE_jonas.jar'/></example><li>Copy the EJB jar's file containing your beans to WEB-INF/libIf you are using JOnAS on the same machine as Resin you can do the sameby adding the following line to your app on resin.conf (assuming JOnAS is installed on \JONAS and your beans are on a dir called \JONAS\mybeans)<example><classpath id='/JONAS/mybeans' source='/JONAS/mybeans' compile='false'/></example> <li>In resin.conf add these lines to your app (assuming you are using jeremie):<example><jndi-link> <jndi-name>java:comp/env/ejb</jndi-name> <jndi-factory> org.objectweb.jeremie.libs.services.registry.jndi.JRMIInitialContextFactory </jndi-factory> <init-param java.naming.provider.url="jrmi://YOUR_HOST:12340"/> <init-param java.naming.factory.url.pkgs="org.objectweb.jonas.naming"/></jndi-link></example><li>Don't forget to change YOUR_HOST to your hostname...</ol><example title="Sample JSP showing how to access your beans"><!DOCTYPE html public "-//W3C//DTD HTML 4.0 Transitional//EN"><%@ page language="java"%><%@ page import="javax.naming.InitialContext" %><%@ page import="javax.naming.Context" %><%@ page import="javax.rmi.PortableRemoteObject" %><%@ page import="YOUR_BEANS_PACKAGE.*" %><html><head><title>Test</title></head><body><% Context initialContext = new InitialContext(); Object ref = initialContext.lookup("java:comp/env/ejb/ExpHome"); ExpHome home = (ExpHome) PortableRemoteObject.narrow(ref, ExpHome.class); Exp t1 = home.create(); %>dummy result value = <%=t1.dummyMethod()%><% t1.remove(); %></body></html></example></s2><s2 title="CORBA (J2EE Reference Implementation)"><ul><li>Copy the client class jar and the j2ee.jar file to theWEB-INF/classes directory of your web application.<li>Add the following to your web application configuration in theresin.conf file:<example><classpath id='WEB-INF/classes/j2ee.jar'/><classpath id='WEB-INF/classes/{your client class jar}'/></example><li>In your class, explicitly create the environment for theInitialContext:<example>Hashtable vEnv = new Hashtable();vEnv.put("org.omg.CORBA.ORBInitialHost", "{your server host}");vEnv.put("org.omg.CORBA.ORBInitialPort", "{your server port}");vEnv.put("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");</example>Or create a <a href="jndi.xtp#jndi-link">jndi-link</a>:<example><jndi-link> <jndi-name>java:comp/env/ejb</jndi-name> <jndi-factory>com.sun.enterprise.naming.SerialInitContextFactory</jndi-factory> <init-param org.omg.CORBA.ORBInitialHost="{your server host}"/> <init-param org.omg.CORBA.ORBInitialPort="{your server port}"/></jndi-link></example> <li>Make sure the InitialContext is initialised using the environmentset above. Then access the bean as usual:<example>InitialContext vContext = new InitialContext(vEnv);Object vObjRef = vContext.lookup("{your bean jndi name}");</example></ul></s2></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -