<% 
/*
 * Copyright (c) 1998-2000 BEA Systems, Inc.  All rights reserved
 *
 * THIS IS SOURCE CODE PUBLISHED FOR DEMONSTRATION PURPOSES
 *
 * This JSP file illustrates how a BankApp HTML client uses a servlet
 * to access the TUXEDO BankApp DEPOSIT service.
 */
%>

<%@ page import= "
bea.jolt.pool.*,
bea.jolt.pool.servlet.*,
weblogic.jndi.*,
javax.naming.*"
%>

<%! 
private boolean b_init = false;
private ServletSessionPoolManager b_mgr;

/**
 * Since there is no way to override the init() method, we need
 * to come up a local initialization method.
 */
private void localInit(HttpServletRequest req)
    throws ServletException
  {
    // Get the session pool manager through JNDI.
    try {
      Environment env = new Environment();
      Context ctx = env.getInitialContext();
      b_mgr =
        (ServletSessionPoolManager) ctx.lookup(SessionPoolManager.POOLMANAGER_NAME);
    }
    catch (NamingException e) {
      throw new ServletException(e.toString());
    }
  }
%>

<%
  // Codes that are in the "service()" method.
  if (!b_init) {
    // Do some local initialization: get the session pool manager
    // which has initialized a session pool when web server starts.
    localInit(request);
    b_init = true;
  }

  ServletResult output;

  // Get the "demojoltpool" session pool
  ServletSessionPool joltSession =
    (ServletSessionPool) b_mgr.getSessionPool("demojoltpool");
  if (joltSession == null) {
%>

<html>
<head><title>Bankapp</title></head>

<body bgcolor=#FFFFFF>
<font face="Helvetica">
<h2>
No Session Pool
</h2>

<p>
Copyright (c) 1998 by BEA Systems, Inc. All Rights Reserved.

</font>
</body>
</html>

<% 
    out.close();
    return;
  }

  try {
    // Invoke a service and get the result.  No transaction is
    // needed for services, so the 3rd parameter in this call is
    // null.  Present the result page with input and output data.
    output = joltSession.call("DEPOSIT", request, null);
%>

<html>
<head>
<title>DEPOSIT Result on
<%= request.getParameterValues("ACCOUNT_ID")[0]%></title></head>
<body bgcolor=#FFFFFF>
<font face="Helvetica">

<h2>
<font color=#DB1260>
Result of the DEPOSIT Service is:
</font>
</h2>

<table border=0>
<tr>
<td align=right><b>Account number:</b></td><td>
<%=request.getParameterValues("ACCOUNT_ID")[0]%></td></tr>

<tr>
<td align=right><b>Deposit amount:</b></td><td>
<%= request.getParameterValues("SAMOUNT")[0]%></td></tr>

<tr><td align=right><b>Current balance:</b></td><td>
<%= output.getStringValue("SBALANCE", "")%></td></tr>
</table>

<center>
<form>
<input type='button' value='Back' onClick='history.go(-1)'>
</form>
</center>

<p>
Copyright (c) 1998 by BEA Systems, Inc. All Rights Reserved.

</font>
</body>
</html>

<% 
  }
  catch (SessionPoolException e) {
  // All sessions are busy
%>

<html>
<head><title>Error</title></head>
<body bgcolor=#FFFFFF>
<font face="Helvetica">

<h2>
<font color=#DB1260>
Your request could not be completed
</font>
</h2>

<p>
Possible reasons:<br>
<ul>
<li>No sessions are available
<li>The session pool is suspended
<li>The session pool is shutdown
</ul>
<p>Please re-submit your request later.

<p>
Copyright (c) 1998 by BEA Systems, Inc. All Rights Reserved.

</font>
</body>
</html>

<% 
  }
  catch (ApplicationException e) {
    // An application error
    output = (ServletResult) e.getResult();
%>

<html>
<head><title>Application Error</title></head>

<body bgcolor=#FFFFFF>
<font face="Helvetica">

<h3>
<font color='#FF0000'>
Application error
</font>
</h3>

<table border=0>
<tr>
<td align=right><b>Account number:</b></td>
<td><font color='#0000FF'>
<%= request.getParameterValues("ACCOUNT_ID")[0]%></font></td>
</tr>

<tr>
<td align=right><b>Status:</b></td>
<td><font color='#0000FF'>
<%= output.getStringValue("STATLIN", "")
%></font></td>
</tr>
</table>

<center>
<form>
<input type='button' value='Back' OnClick='history.go(-1)'>
</form>
</center>

<p>
Copyright (c) 1998 by BEA Systems, Inc. All Rights Reserved.
</font>
</body>
</html>

<% 
  }
  catch (ServiceException e) {
    // System error
%>

<html>
<head><title>System Error</title></head>
<body bgcolor=#FFFFFF>
<font face="Helvetica">

<h3>
<font color='#FF0000'>System Error
</font>
</h3>

<table border=0>
<tr>
<td align=right><b>Error message:</b></td>
<td><font color='#0000FF'>
<%= e.getMessage()%></font></td>
</tr>

<tr>
<td align=right><b>Error number:</b></td>
<td>
<font color='#0000FF'>
<%= e.getErrno()%></font></td>
</tr>
</table>

<center>
<form>
<input type='button' value='Back' OnClick='history.go(-1)'>
</form>
</center>
<p>
Copyright (c) 1998 by BEA Systems, Inc. All Rights Reserved.

</font>
</body>
</html>

<% 
  }
  catch (Exception e) {
    // Any Java errors
%>

<html>
<head><title>System Error</title></head>
<body bgcolor=#FFFFFF>
<font face="Helvetica">

<h3>
<font color='#FF0000'>System error
</font>
</h3>

<table border=0>
<tr>
<td align=right><b>Error message:</b></td>
<td><font color='#0000FF'>
<%= e.getMessage()%></font></td>
</tr>

<tr>
<td align=right><b>Error number:</b></td>
<td><font color='#0000FF'>Unknown</font></td>
</tr>
</table>

<center>
<form>
<input type='button' value='Back' OnClick='history.go(-1)'>
</form>
</center>
<p>
Copyright (c) 1998 by BEA Systems, Inc. All Rights Reserved.
</font>
</body>
</html>

<% 
  }
  out.close();
%>
