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

<java type=import>
bea.jolt.pool.*
bea.jolt.pool.servlet.*
weblogic.jndi.*
javax.naming.*
java.util.Hashtable
java.io.IOException
</java>

<java type=class>
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());
  }
}
</java>

<java type=code>
  // 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 session =
    (ServletSessionPool) b_mgr.getSessionPool("demojoltpool");
  if (session == null) {
</java>

<HTML><HEAD><TITLE>Bankapp</TITLE></HEAD>
<BODY><H2>No Session Pool</H2></BODY></HTML>

<java>
    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 = session.call("WITHDRAWAL", request, null);
</java>

<html>
<head><title>WITHDRAWAL Result on
<java type=print>request.getParameterValues("ACCOUNT_ID")[0]</java></title></head>

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

<h2>
<font color=#DB1260>
Result of the WITHDRAWAL Service
</font>
</h2>

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

<tr>
<td align=right><b>Withdraw amount:</b></td><td>
<java type=print>request.getParameterValues("SAMOUNT")[0]</java></td></tr>

<tr>
<td align=right><b>Current balance:</b></td><td>
<java type=print>output.getStringValue("SBALANCE", "")</java></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>

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

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

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

<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'>
<java type=print>request.getParameterValues("ACCOUNT_ID")[0]</java></font></td>
</tr>

<tr>
<td align=right><b>Status:</b></td>
<td><font color='#0000FF'>
<java type=print>output.getStringValue("STATLIN", "")</java></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>

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

<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'>
<java type=print>e.getMessage()</java></font></td>
</tr>

<tr>
<td align=right><b>Error number:</b></td>
<td><font color='#0000FF'>
<java type=print>e.getErrno()</java></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>

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

<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'>
<java type=print>e.getMessage()</java></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>

<java>
  }
  out.close();
</java>
