J2EE Sample Code: Accessing the Stateful Session EJB in a Web Application

The following code sample illustrates how to use the stateful session EJB inside a Web application. This sample uses the AMNU test application supplied by IBM and does some simple add, update, and query operations.

Creating the AmnuEjbSample.WAR

To distribute a Web application, you must package it in a Web application archive (WAR). The WAR supports SunOne, WebLogic, WebSphere, and Oracle, with some minor differences that are noted below. Here is the directory structure and file names (linked to its sample code below).

StatefulEjbSample.WAR:

Once the directory structure and files have been created, you can use the following command to create the WAR:

$JAVA_HOME/bin/jar -cf ../AmnuEjbSample.WAR .

Deploying the AmnuEjbSample.WAR

There are two deployment options:

Accessing the AmnuEjbSample.WAR

After you have deployed the Web application (WAR), you can access it through the following URL:

http://machine:port/StatefulEjbSample/index.jsp
This application server
Uses this default port...
SunOne 81 or 4444 (see HTTP Port(s) listed on App Server Instances / server1 / General tab)
WebLogic 7001
WebSphere 9080
Oracle9i 7777

Stateful Session EJBs

Since multiple calls need to be made to the same instance of the stateful session EJB, the reference to the stateful session EJB is saved in the session object and removed when finished.

Source code for index.jsp

<%@page contentType="text.html"%>

<%@page import="javax.naming.InitialContext" %>
<%@page import="javax.rmi.PortableRemoteObject" %>
<%@page import="com.attachmate.cicsbridge.j2ee.ejb.stateful.BridgeAPI_EJB" %>
<%@page import="com.attachmate.cicsbridge.j2ee.ejb.stateful.BridgeAPI_EJBHome" %>
<%@page import="com.attachmate.cicsbridge.j2ee.outputs.*" %>

<%
        BridgeAPI_EJB m_ejb = null;
        // inputs
        String input;
        input = request.getParameter("hostIP");
        String m_hostIP = input == null ? "" : input;
        input = request.getParameter("hostPort");
        String m_hostPort = input == null ? "" : input;
        input = request.getParameter("terminalModel");
        String m_terminalModel = input == null ? "" : input;
        input = request.getParameter("userid");
        String m_userid = input == null ? "" : input;
        input = request.getParameter("password");
        String m_password = input == null ? "" : input;
        // modes
        boolean m_add = false;
        boolean m_update = false;
        boolean m_query = false;
        // outputs
        String m_number = "";
        String m_name = "";
        String m_address = "";
        String m_phone = "";
        String m_date = "";
        String m_amount = "";
        String m_comment = "";
        PutString putstring;
        GetString getstring;
        int m_returnCode = 0;
        // get the stateful session ejb out of the session object
        m_ejb = (BridgeAPI_EJB) session.getAttribute("ejb");
        if ("connectBridge".equals(request.getParameter("Execute")))
        {
            javax.naming.InitialContext ic = new javax.naming.InitialContext();
            // look up stateful session ejb with resource name
            // (mapped to jndi name in weblogic.xml, sun-web.xml, orion.xml or as setup in WebSphere)
            Object ref = ic.lookup("java:comp/env/ejb/BridgeAPI");
            BridgeAPI_EJBHome home = null;
            home = (BridgeAPI_EJBHome) PortableRemoteObject.narrow(ref,
                    BridgeAPI_EJBHome.class);
            m_ejb = home.create();
            // save stateful session ejb instance in the session object for future reference
            session.setAttribute("ejb", m_ejb);
            m_returnCode = m_ejb.connectBridge(m_hostIP, Integer
                    .parseInt(m_hostPort), Integer.parseInt(m_terminalModel),
                    m_userid, m_password);
        }
        else if ("disconnect".equals(request.getParameter("Execute")))
        {
            session.removeAttribute("ejb");
            m_returnCode = m_ejb.disconnect();
            // remove stateful session ejb
            m_ejb.remove();
            // cleanup session object, etc.
            m_ejb = null;
        }
        else if ("cancel".equals(request.getParameter("Execute")))
        {
            m_add = false;
            m_update = false;
        }
        else if ("AddEntry".equals(request.getParameter("Execute")))
        {
            m_number = request.getParameter("number");
            m_add = true;
        }
        else if ("EnterAdd".equals(request.getParameter("Execute")))
        {
            m_number = request.getParameter("number");
            m_returnCode += m_ejb.sendKeys("@CAMNU@EAADD" + m_number + "@E");
            // check that navigation worked here
            putstring = m_ejb.putString(request.getParameter("name"), 4, 11);
            m_returnCode += putstring.getReturnCode();
            putstring = m_ejb.putString(request.getParameter("address"), 5, 11);
            m_returnCode += putstring.getReturnCode();
            putstring = m_ejb.putString(request.getParameter("phone"), 6, 11);
            m_returnCode += putstring.getReturnCode();
            putstring = m_ejb.putString(request.getParameter("date"), 7, 11);
            m_returnCode += putstring.getReturnCode();
            putstring = m_ejb.putString(request.getParameter("amount"), 8, 11);
            m_returnCode += putstring.getReturnCode();
            putstring = m_ejb.putString(request.getParameter("comment"), 9, 11);
            m_returnCode += putstring.getReturnCode();
            m_returnCode += m_ejb.sendKeys("@E");
        }
        else if ("UpdateEntry".equals(request.getParameter("Execute")))
        {
            m_number = request.getParameter("number");
            m_returnCode += m_ejb.sendKeys("@CAMNU@EAINQ" + m_number + "@E");
            // check that navigation worked here
            getstring = m_ejb.getString(-1, 4, 11, 25);
            m_returnCode += getstring.getReturnCode();
            m_name = getstring.getText().trim();
            getstring = m_ejb.getString(-1, 5, 11, 25);
            m_returnCode += getstring.getReturnCode();
            m_address = getstring.getText().trim();
            getstring = m_ejb.getString(-1, 6, 11, 25);
            m_returnCode += getstring.getReturnCode();
            m_phone = getstring.getText().trim();
            getstring = m_ejb.getString(-1, 7, 11, 25);
            m_returnCode += getstring.getReturnCode();
            m_date = getstring.getText().trim();
            getstring = m_ejb.getString(-1, 8, 11, 25);
            m_returnCode += getstring.getReturnCode();
            m_amount = getstring.getText().trim();
            getstring = m_ejb.getString(-1, 9, 11, 25);
            m_returnCode += getstring.getReturnCode();
            m_comment = getstring.getText().trim();
            m_returnCode += m_ejb.sendKeys("@E");
            m_update = true;
        }
        else if ("EnterUpdate".equals(request.getParameter("Execute")))
        {
            m_number = request.getParameter("number");
            m_returnCode += m_ejb.sendKeys("@CAMNU@EAUPD" + m_number + "@E");
            // check that navigation worked here
            putstring = m_ejb.putString(request.getParameter("name"), 4, 11);
            m_returnCode += putstring.getReturnCode();
            putstring = m_ejb.putString(request.getParameter("address"), 5, 11);
            m_returnCode += putstring.getReturnCode();
            putstring = m_ejb.putString(request.getParameter("phone"), 6, 11);
            m_returnCode += putstring.getReturnCode();
            putstring = m_ejb.putString(request.getParameter("date"), 7, 11);
            m_returnCode += putstring.getReturnCode();
            putstring = m_ejb.putString(request.getParameter("amount"), 8, 11);
            m_returnCode += putstring.getReturnCode();
            putstring = m_ejb.putString(request.getParameter("comment"), 9, 11);
            m_returnCode += putstring.getReturnCode();
            m_returnCode += m_ejb.sendKeys("@E");
        }
        else if ("QueryEntry".equals(request.getParameter("Execute")))
        {
            m_number = request.getParameter("number");
            m_returnCode += m_ejb.sendKeys("@C");
            putstring = m_ejb.putString("AMNU", 1, 1);
            m_returnCode += putstring.getReturnCode();
            m_returnCode += m_ejb.sendKeys("@E");
            putstring = m_ejb.putString("AINQ", 12, 21);
            m_returnCode += putstring.getReturnCode();
            putstring = m_ejb.putString(m_number, 12, 33);
            m_returnCode += putstring.getReturnCode();
            m_returnCode += m_ejb.sendKeys("@E");
            // check that navigation worked here
            getstring = m_ejb.getString(-1, 4, 11, 25);
            m_returnCode += getstring.getReturnCode();
            m_name = getstring.getText().trim();
            getstring = m_ejb.getString(-1, 5, 11, 25);
            m_returnCode += getstring.getReturnCode();
            m_address = getstring.getText().trim();
            getstring = m_ejb.getString(-1, 6, 11, 25);
            m_returnCode += getstring.getReturnCode();
            m_phone = getstring.getText().trim();
            getstring = m_ejb.getString(-1, 7, 11, 25);
            m_returnCode += getstring.getReturnCode();
            m_date = getstring.getText().trim();
            getstring = m_ejb.getString(-1, 8, 11, 25);
            m_returnCode += getstring.getReturnCode();
            m_amount = getstring.getText().trim();
            getstring = m_ejb.getString(-1, 9, 11, 25);
            m_returnCode += getstring.getReturnCode();
            m_comment = getstring.getText().trim();
            m_returnCode += m_ejb.sendKeys("@E");
            m_query = true;
        }
%>

<html>
<head>
    <title> AMNU Stateful Session EJB Sample </title>
</head>
<body>
    <form action='<%=request.getRequestURI()%>' method='post'>
    <table>
        <tr>
            <td align=center colspan=2> <b> AMNU Stateful Session EJB Sample </b> </td>
        </tr>
<%
        if (m_ejb == null)
        {
%>
        <tr>
            <td align=right> hostIP: </td>
            <td>
                <input type='text' name='hostIP' size='15' value='<%=m_hostIP%>'>
            </td>
        </tr>
        <tr>
            <td align=right> hostPort: </td>
            <td>
                <input type='text' name='hostPort' size='10' value='<%=m_hostPort%>'>
            </td>
        </tr>
        <tr>
            <td align=right> terminalModel: </td>
            <td>
                <input type='text' name='terminalModel' size='5' value='<%=m_terminalModel%>'>
            </td>
        </tr>
        <tr>
            <td align=right> userid: </td>
            <td>
                <input type='text' name='userid' size='20' value='<%=m_userid%>'>
               </td>
        </tr>
        <tr>
            <td align=right> password: </td>
            <td>
                <input type='password' name='password' size='20' value='<%=m_password%>'>
            </td>
        </tr>
        <tr>
            <td align=center colspan=2>
                <input type='submit' name='Execute' value='connectBridge'>
            </td>
        </tr>
<%
        }
        else
        {
            if (m_add == true)
            {
%>
        <tr>
            <td align=center colspan=2> </td>
        </tr>
        <tr>
            <td align=right> number: </td>
            <td>
                <b> <%=m_number%> </b> 
                <input type='hidden' name='number' value='<%=m_number%>'>
            </td>
        </tr>
        <tr>
            <td align=right> name: </td>
            <td>
                <select name='name'>
                    <option value='GEORGE WASHINGTON'> GEORGE WASHINGTON </option>
                    <option value='SIR JOHN A MACDONALD'> SIR JOHN A MACDONALD </option>
                    <option value='ROBERT WALPOLE'> ROBERT WALPOLE </option>
                    <option value='GUADALUPE VICTORIA'> GUADALUPE VICTORIA </option>
                </select>
            </td>
        </tr>
        <tr>
            <td align=right> address: </td>
            <td>
                <select name='address'>
                    <option value='1600 PENNSYLVANIA AV'> 1600 PENNSYLVANIA AV </option>
                    <option value='24 SUSSEX DRIVE'> 24 SUSSEX DRIVE </option>
                    <option value='10 DOWNING STREET'> 10 DOWNING STREET </option>
                    <option value='LOS PINOS'> LOS PINOS </option>
                </select>
            </td>
        </tr>
        <tr>
            <td align=right> phone: </td>
            <td>
                <select name='phone'>
                    <option value='456 1414'> 456 1414 </option>
                    <option value='239 5000'> 239 5000 </option>
                    <option value='79250918'> 79250918 </option>
                    <option value='682 9822'> 682 9822 </option>
                </select>
            </td>
        </tr>
        <tr>
            <td align=right> date: </td>
            <td>
                <select name='date'>
                    <option value='07 04 76'> 07 04 76 </option>
                    <option value='07 01 67'> 07 01 67 </option>
                    <option value='04 03 21'> 04 03 21 </option>
                    <option value='05 05 62'> 05 05 62 </option>
                </select>
            </td>
        </tr>
        <tr>
            <td align=right> amount: </td>
            <td>
                <select name='amount'>
                    <option value='$1776.00'> $1776.00 </option>
                    <option value='$1867.00'> $1867.00 </option>
                    <option value='$1721.00'> $1721.00 </option>
                    <option value='$1862.00'> $1862.00 </option>
                </select>
            </td>
        </tr>
        <tr>
            <td align=right> comment: </td>
            <td>
                <select name='comment'>
                    <option value='*USA*'> *USA* </option>
                    <option value='*CANADA*'> *CANADA* </option>
                    <option value='*ENGLAND*'> *ENGLAND* </option>
                    <option value='*MEXICO*'> *MEXICO* </option>
                </select>
            </td>
        </tr>
        <tr>
            <td align=center colspan=2>
                <input type='submit' name='Execute' value='EnterAdd'>
                <input type='submit' name='Execute' value='Cancel'>
            </td>
        </tr>
<%
            }
            else if (m_update == true)
            {
%>
        <tr>
            <td align=center colspan=2>
            </td>
        </tr>
        <tr>
            <td align=right> number: </td>
            <td>
                <b> <%=m_number%> </b> 
                <input type='hidden' name='number' value='<%=m_number%>'>
            </td>
        </tr>
        <tr>
            <td align=right> name: </td>
            <td>
                <select name='name'>
                    <option value='GEORGE WASHINGTON'<%=("GEORGE WASHINGTON".equals(m_name) ? " selected" : "")%>> GEORGE WASHINGTON </option>
                    <option value='SIR JOHN A MACDONALD'<%=("SIR JOHN A MACDONALD".equals(m_name) ? " selected" : "")%>> SIR JOHN A MACDONALD </option>
                    <option value='ROBERT WALPOLE'<%=("ROBERT WALPOLE".equals(m_name) ? " selected" : "")%>> ROBERT WALPOLE </option>
                    <option value='GUADALUPE VICTORIA'<%=("GUADALUPE VICTORIA".equals(m_name) ? " selected" : "")%>> GUADALUPE VICTORIA </option>
                </select>
            </td>
        </tr>
        <tr>
            <td align=right> address: </td>
            <td>
                <select name='address'>
                    <option value='1600 PENNSYLVANIA AV'<%=("1600 PENNSYLVANIA AV".equals(m_address) ? " selected" : "")%>> 1600 PENNSYLVANIA AV </option>
                    <option value='24 SUSSEX DRIVE'<%=("24 SUSSEX DRIVE".equals(m_address) ? " selected" : "")%>> 24 SUSSEX DRIVE </option>
                    <option value='10 DOWNING STREET'<%=("10 DOWNING STREET".equals(m_address) ? " selected" : "")%>> 10 DOWNING STREET </option>
                    <option value='LOS PINOS'<%=("LOS PINOS".equals(m_address) ? " selected" : "")%>> LOS PINOS </option>
                </select>
            </td>
        </tr>
        <tr>
            <td align=right> phone: </td>
            <td>
                <select name='phone'>
                    <option value='456 1414'<%=("456 1414".equals(m_phone) ? " selected" : "")%>> 456 1414 </option>
                    <option value='239 5000'<%=("239 5000".equals(m_phone) ? " selected" : "")%>> 239 5000 </option>
                    <option value='79250918'<%=("79250918".equals(m_phone) ? " selected" : "")%>> 79250918 </option>
                    <option value='682 9822'<%=("682 9822".equals(m_phone) ? " selected" : "")%>> 682 9822 </option>
                </select>
            </td>
        </tr>
        <tr>
            <td align=right> date: </td>
            <td>
                <select name='date'>
                    <option value='07 04 76'<%=("07 04 76".equals(m_date) ? " selected" : "")%>> 07 04 76 </option>
                    <option value='07 01 67'<%=("07 01 67".equals(m_date) ? " selected" : "")%>> 07 01 67 </option>
                    <option value='04 03 21'<%=("04 03 21".equals(m_date) ? " selected" : "")%>> 04 03 21 </option>
                    <option value='05 05 62'<%=("05 05 62".equals(m_date) ? " selected" : "")%>> 05 05 62 </option>
                </select>
            </td>
        </tr>
        <tr>
            <td align=right> amount: </td>
            <td>
                <select name='amount'>
                    <option value='$1776.00'<%=("$1776.00".equals(m_amount) ? " selected" : "")%>> $1776.00 </option>
                    <option value='$1867.00'<%=("$1867.00".equals(m_amount) ? " selected" : "")%>> $1867.00 </option>
                    <option value='$1721.00'<%=("$1721.00".equals(m_amount) ? " selected" : "")%>> $1721.00 </option>
                    <option value='$1862.00'<%=("$1862.00".equals(m_amount) ? " selected" : "")%>> $1862.00 </option>
                </select>
            </td>
        </tr>
        <tr>
            <td align=right> comment: </td>
            <td>
                <select name='comment'>
                    <option value='*USA*'<%=("*USA*".equals(m_comment) ? " selected" : "")%>> *USA* </option>
                    <option value='*CANADA*'<%=("*CANADA*".equals(m_comment) ? " selected" : "")%>> *CANADA* </option>
                    <option value='*ENGLAND*'<%=("*ENGLAND*".equals(m_comment) ? " selected" : "")%>> *ENGLAND* </option>
                    <option value='*MEXICO*'<%=("*MEXICO*".equals(m_comment) ? " selected" : "")%>> *MEXICO* </option>
                </select>
            </td>
        </tr>
        <tr>
            <td align=center colspan=2>
                <input type='submit' name='Execute' value='EnterUpdate'>
                <input type='submit' name='Execute' value='Cancel'>
            </td>
        </tr>
<%
            }
            else
            {
%>
        <tr>
            <td align=right> Number: </td>
            <td>
                <select name='number'>
                    <option value='900123'<%=("900123".equals(m_number) ? " selected" : "")%>> 900123 </option>
                    <option value='900234'<%=("900234".equals(m_number) ? " selected" : "")%>> 900234 </option>
                    <option value='900345'<%=("900345".equals(m_number) ? " selected" : "")%>> 900345 </option>
                    <option value='900456'<%=("900456".equals(m_number) ? " selected" : "")%>> 900456 </option>
                </select>
            </td>
        </tr>
        <tr>
            <td align=center colspan=2>
                <input type='submit' name='Execute' value='AddEntry'>
                <input type='submit' name='Execute' value='UpdateEntry'>
                <input type='submit' name='Execute' value='QueryEntry'>
            </td>
        </tr>
<%
                if (m_query == true)
                {
%>
        <tr>
            <td align=center colspan=2> </td>
        </tr>
        <tr>
            <td align=right> number: </td>
            <td> <b> <%=m_number%> </b> </td>
        </tr>
        <tr>
            <td align=right> name: </td>
            <td> <%=m_name%> </td>
        </tr>
        <tr>
            <td align=right> address: </td>
            <td> <%=m_address%> </td>
        </tr>
        <tr>
            <td align=right> phone: </td>
            <td> <%=m_phone%> </td>
        </tr>
        <tr>
            <td align=right> date: </td>
            <td> <%=m_date%> </td>
        </tr>
        <tr>
            <td align=right> amount: </td>
            <td> <%=m_amount%> </td>
        </tr>
        <tr>
            <td align=right> comment: </td>
            <td> <%=m_comment%> </td>
        </tr>
        <tr>
            <td align=center colspan=2> </td>
        </tr>
<%
                }
            }
%>
        <tr>
            <td align=center colspan=2>
                <input type='submit' name='Execute' value='disconnect'>
            </td>
        </tr>
<%
        }
%>
        <tr> <td align=center colspan=2>returnCode [<%=m_returnCode%>] </td> </tr>
    </table>
</form>
</body>
</html>

Source code for Xsun-web.xml

Required when deploying to SunOne.

Sample Code:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sun-web-app PUBLIC
 '-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Servlet 2.3//EN'
 'http://www.sun.com/software/sunone/appserver/dtds/sun-web-app_2_3-0.dtd'>

<sun-web-app>
	<session-config>
		<session-manager persistence-type="memory">
			<manager-properties/>
			<store-properties/>
		</session-manager>
		<session-properties/>
		<cookie-properties/>
	</session-config>
	<ejb-ref>
		<ejb-ref-name>ejb/BridgeAPI</ejb-ref-name>
		<jndi-name>ejb/BridgeAPI</jndi-name>
	</ejb-ref>
	<cache max-entries="4096" timeout-in-seconds="30" enabled="false">
		<default-helper/>
	</cache>
	<jsp-config>
		<property name="classdebuginfo" value="true">
			<description>Enable debug info compilation in the generated servlet class</description>
		</property>
		<property name="mappedfile" value="true">
			<description>Maintain a one-to-one correspondence between static content and the generated servlet class' java code</description>
		</property>
	</jsp-config>
</sun-web-app>

Source code for web.xml

Required for all application servers.

Sample code:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
	<display-name>AMNU EJB Sample WAR</display-name>
	<session-config>
		<session-timeout> 30 </session-timeout>
	</session-config>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	<ejb-ref>
		<description>BridgeAPI_EJB</description>
		<ejb-ref-name>ejb/BridgeAPI</ejb-ref-name>
		<ejb-ref-type>Session</ejb-ref-type>
		<home>com.attachmate.cicsbridge.j2ee.ejb.stateful.BridgeAPI_EJBHome</home>
		<remote>com.attachmate.cicsbridge.j2ee.ejb.stateful.BridgeAPI_EJB</remote>
	</ejb-ref>
</web-app>

Source code for weblogic.xml

Required when deploying to WebLogic.

Sample code:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE weblogic-web-app PUBLIC
 '-//BEA Systems, Inc.//DTD Web Application 7.0//EN'
 'http://www.bea.com/servers/wls700/dtd/weblogic700-web-jar.dtd'>

<weblogic-web-app>
	<description>AMNU EJB Sample WAR</description>
	<reference-descriptor>
		<ejb-reference-description>
			<ejb-ref-name>ejb/BridgeAPI</ejb-ref-name>
			<jndi-name>ejb/BridgeAPI</jndi-name>
		</ejb-reference-description>
	</reference-descriptor>
	<session-descriptor>
		<session-param>
			<param-name>URLRewritingEnabled</param-name>
			<param-value>true</param-value>
		</session-param>
		<session-param>
			<param-name>IDLength</param-name>
			<param-value>52</param-value>
		</session-param>
		<session-param>
			<param-name>CookieComment</param-name>
			<param-value>WebLogic Server Session Tracking Cookie</param-value>
		</session-param>
		<session-param>
			<param-name>CookieMaxAgeSecs</param-name>
			<param-value>-1</param-value>
		</session-param>
		<session-param>
			<param-name>CookieName</param-name>
			<param-value>JSESSIONID</param-value>
		</session-param>
		<session-param>
			<param-name>InvalidationIntervalSecs</param-name>
			<param-value>60</param-value>
		</session-param>
		<session-param>
			<param-name>JDBCConnectionTimeoutSecs</param-name>
			<param-value>120</param-value>
		</session-param>
		<session-param>
			<param-name>PersistentStoreCookieName</param-name>
			<param-value>WLCOOKIE</param-value>
		</session-param>
		<session-param>
			<param-name>PersistentStoreDir</param-name>
			<param-value>session_db</param-value>
		</session-param>
		<session-param>
			<param-name>PersistentStoreType</param-name>
			<param-value>memory</param-value>
		</session-param>
		<session-param>
			<param-name>PersistentStoreTable</param-name>
			<param-value>wl_servlet_sessions</param-value>
		</session-param>
		<session-param>
			<param-name>CookiesEnabled</param-name>
			<param-value>true</param-value>
		</session-param>
		<session-param>
			<param-name>TrackingEnabled</param-name>
			<param-value>true</param-value>
		</session-param>
		<session-param>
			<param-name>TimeoutSecs</param-name>
			<param-value>3600</param-value>
		</session-param>
	</session-descriptor>
	<context-root>/AmnuEjbSample</context-root>
</weblogic-web-app>

Source code for orion-web.xml

Required when deploying to Oracle.

Sample code:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE orion-web-app PUBLIC
 "-//Evermind//DTD Orion Web Application 2.3//EN"
 "http://xmlns.oracle.com/ias/dtds/orion-web.dtd">

<orion-web-app>
	<ejb-ref-mapping location="BridgeAPI_EJB" name="ejb/BridgeAPI"/>
</orion-web-app>

Oracle specific source code

With Oracle you can use ORMI to find a stateful session EJB by its JNDI name inside an enterprise application. Refer to the Oracle application server documentation for complete instructions on how to do this.


The BridgeAPI-ejbClient.jar

The EJB Client JAR is not required if the sample WAR is repackaged inside the BridgeAPI.ear before deployment.

To deploy the EAR and WAR separately
  1. Deploy the BridgeAPI.ear to the application server.

  2. Get the EJB Client JAR from the appropriate location, or perform the required steps in the Application server table (below).

  3. Place the EJB Client JAR lib directory so it gets packaged inside the sample WAR.

Application server

Description

WebLogic You need to use the appc compiler (see WebLogic documentation) to generate and compile classes into the EJB Client JAR from the EJB deploy (typical path to EJB is: [install dir]/user_projects/domains/[your domain]/myserver/.wlnotdelete/BridgeAPI/BridgeAPI-ejb.jar )
SunOne Typical location and name of EJB Client JAR is: [install dir]/AppServer7/domains/domain1/server1/applications/j2ee-apps/BridgeAPI_1/BridgeAPIClient.jar .
WebSphere Inside the [install dir]/WebSphere/AppServer/config/cells/[machine name]/applications/BridgeAPI_EAR.ear/BridgeAPI_EAR.ear file you will find the BridgeAPI-ejb.jar which is the EJB Client JAR.
Oracle Inside the BridgeAPI.ear you will find the BridgeAPI-ejb.JAR which you will use as the EJB Client JAR.


Source code for application.xml

Required for all application servers.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE application PUBLIC
 "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
 "http://java.sun.com/dtd/application_1_3.dtd">

<application>
	<display-name>BridgeAPI_EAR</display-name>
	<module>
		<connector>BridgeAPI.rar</connector>
	</module>
	<module>
		<ejb>BridgeAPI-ejb.jar</ejb> 
	</module>
	<module>
		<web>
			<web-uri>AmnuEjbSample.WAR</web-uri>
			<context-root>/AmnuEjbSample</context-root>
		</web>
	</module>
</application>
Related Topics
Bullet RA and EJB Requestors
Bullet Packaging Enterprise Applications
Bullet RA and EJB Requestor Errors
Bullet J2EE Sample Code: Accessing the Resource Adapter from a Web Application
  Attachmate