caucho
Resin
FAQ
Reference Guide
Demo
Tutorial

Getting Started
Configuration
IDE
Topics
JSP
XML/XSLT

Virtual Hosts
Balancing
Distributed Sessions
Caching
JavaScript
Filters
Servlets
Admin
WebDAV
Velocity
EJB Clients
JMX
Burlap
Hessian
 EJB Clients

Velocity
Topics
JMX

Resin-EJB

Configuring with Resin-EJB as a client uses the BurlapContextFactory as a JNDI link. The client will use JNDI to lookup the EJB home interfaces.

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>

Sample client code follows. The EJBHome lookup is in the init() method for efficiency.

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);
    }
  }
}

Configuring with Resin-EJB and Hessian is the same as with Burlap. Only the names change.

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>

WebLogic
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>
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();
%>

Inprise Application Server

From Damon Maria:

Got Resin 1.2 talking to IAS 4.1 the other day and just thought I'd share my experiences to save someone else some time.

Here's what to do:

  1. Copy vbjorb.jar and vbejb.jar from AppServer/lib into resin/lib. Just adding these into the <classpath .../> in resin.conf doesn't work.
  2. Add the path to your beans into resin.conf:

      <classpath id='c:/development/classes'/>
    

  3. Add the JNDI link from resin to the app server in resin.conf:

    <jndi-link>
      <jndi-name>java:comp/env/ejb</jndi-name>
       <jndi-factory>com.inprise.j2ee.jndi.CtxFactory</jndi-factory>
    </jndi-link>
    

  4. 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 app server JNDI path of "TestSession" then in my servlet I use:

    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);
    

Orion

From Luciano Montebove:

To use Resin as an EJB client with Orion follow these steps:

  1. Under Orion do nothing :)
  2. In Resin add orion.jar, ejb.jar, mail.jar (from orion) in your app WEB-INF/classes dir
  3. In Resin in your app web.xml add these lines:

    <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>
    

  4. Write your servlet/JSP as you would in Orion so for example if you have a SessionBean called MyBean (in your ejb-jar.xml) your lookup should use this string ("java:comp/env/ejb/MyBean")
  5. It's all

jBoss

From Dave Dribin:

To have a Resin web application use jBoss, do the following:

  1. Copy "ejb.jar", "jboss-client.jar", and "jnp-client.jar" from $JBOSS_HOME/client into WEB-INF/lib.
  2. Copy the EJB jar file that you put in $JBOSS_HOME/deploy into WEB-INF/lib.
  3. Put the following <web-app> into resin.conf:

    <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>
    

    Of course change the JNDI URL if you're running jBoss on a different machine.

  4. Make sure you map all of your EJBs to the "ejb/" JNDI context. For example, I have this in my jboss.xml:

    <enterprise-beans>
      <entity>
        <ejb-name>UserBean</ejb-name>
        <jndi-name>ejb/UserHome</jndi-name>
      </entity>
    
      .... other beans ....
    
    </enterprise-beans>
    
    This way you can lookup all the Home interfaces in the "java:comp/env/ejb/" context.

I've attached a simple JSP that shows how to access the User EJB.

And don't forget that if you re-deploy your beans to jBoss, you should copy over the jar file into WEB-INF and restart Resin.

Hope that helps!

-Dave

<!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>

JOnAS

From Pedro Costa:

To use Resin as an EJB client with JOnAS or Enhydra Enterprise follow these steps:

  1. Under JOnAS or Enhydra do nothing
  2. Copy JEREMIE_jonas.jar (RMI_jonas.jar if you are using rmi and not jeremie) into WEB-INF/lib or resin1.2/lib.

    If you are using JOnAS on the same machine as Resin you can do the same by adding the following line to your app on resin.conf (assuming JOnAS is installed on \JONAS)

    <classpath id='/JONAS/lib/JEREMIE_jonas.jar'/>
    

  3. Copy the EJB jar's file containing your beans to WEB-INF/lib If you are using JOnAS on the same machine as Resin you can do the same by 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)

    <classpath id='/JONAS/mybeans' source='/JONAS/mybeans' compile='false'/>
    

  4. In resin.conf add these lines to your app (assuming you are using jeremie):

    <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>
    

  5. Don't forget to change YOUR_HOST to your hostname...
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>

CORBA (J2EE Reference Implementation)

  • Copy the client class jar and the j2ee.jar file to the WEB-INF/classes directory of your web application.
  • Add the following to your web application configuration in the resin.conf file:

    <classpath id='WEB-INF/classes/j2ee.jar'/>
    <classpath id='WEB-INF/classes/{your client class jar}'/>
    

  • In your class, explicitly create the environment for the InitialContext:

    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");
    
    Or create a jndi-link:

    <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>
    

  • Make sure the InitialContext is initialised using the environment set above. Then access the bean as usual:

    InitialContext vContext = new InitialContext(vEnv);
    Object vObjRef = vContext.lookup("{your bean jndi name}");
    


Velocity
Topics
JMX
Copyright © 1998-2002 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.