/**
   * Display User Profile information such as address, email, etc. for the given Trader Dispatch to
   * the Trade Account JSP for display
   *
   * @param userID The User to display profile info
   * @param ctx the servlet context
   * @param req the HttpRequest object
   * @param resp the HttpResponse object
   * @param results A short description of the results/success of this web request provided on the
   *     web page
   * @exception javax.servlet.ServletException If a servlet specific exception is encountered
   * @exception javax.io.IOException If an exception occurs while writing results back to the user
   */
  void doAccount(
      ServletContext ctx,
      HttpServletRequest req,
      HttpServletResponse resp,
      String userID,
      String results)
      throws javax.servlet.ServletException, java.io.IOException {
    try {

      AccountDataBean accountData = tAction.getAccountData(userID);
      AccountProfileDataBean accountProfileData = tAction.getAccountProfileData(userID);
      ArrayList orderDataBeans =
          (TradeConfig.getLongRun() ? new ArrayList() : (ArrayList) tAction.getOrders(userID));

      req.setAttribute("accountData", accountData);
      req.setAttribute("accountProfileData", accountProfileData);
      req.setAttribute("orderDataBeans", orderDataBeans);
      req.setAttribute("results", results);
      requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.ACCOUNT_PAGE));
    } catch (java.lang.IllegalArgumentException e) { // this is a user error so I will
      // forward them to another page rather than throw a 500
      req.setAttribute("results", results + "could not find account for userID = " + userID);
      requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.HOME_PAGE));
      // log the exception with an error level of 3 which means, handled exception but would
      // invalidate a automation run
      Log.error(
          "TradeServletAction.doAccount(...)",
          "illegal argument, information should be in exception string",
          e);
    } catch (Exception e) {
      // log the exception with error page
      throw new ServletException(
          "TradeServletAction.doAccount(...)" + " exception user =" + userID, e);
    }
  }
  /**
   * Register a new trader given the provided user Profile information such as address, email, etc.
   * Dispatch to the Trade Home JSP for display
   *
   * @param userID The User to create
   * @param passwd The User password
   * @param fullname The new User fullname info
   * @param ccn The new User credit card info
   * @param money The new User opening account balance
   * @param address The new User address info
   * @param email The new User email info
   * @return The userID of the new trader
   * @param ctx the servlet context
   * @param req the HttpRequest object
   * @param resp the HttpResponse object
   * @exception javax.servlet.ServletException If a servlet specific exception is encountered
   * @exception javax.io.IOException If an exception occurs while writing results back to the user
   */
  void doRegister(
      ServletContext ctx,
      HttpServletRequest req,
      HttpServletResponse resp,
      String userID,
      String passwd,
      String cpasswd,
      String fullname,
      String ccn,
      String openBalanceString,
      String email,
      String address)
      throws ServletException, IOException {
    String results = "";

    try {
      // Validate user passwords match and are atleast 1 char in length
      if ((passwd.equals(cpasswd)) && (passwd.length() >= 1)) {

        AccountDataBean accountData =
            tAction.register(
                userID, passwd, fullname, address, email, ccn, new BigDecimal(openBalanceString));
        if (accountData == null) {
          results = "Registration operation failed;";
          System.out.println(results);
          req.setAttribute("results", results);
          requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.REGISTER_PAGE));
        } else {
          doLogin(ctx, req, resp, userID, passwd);
          results =
              "Registration operation succeeded;  Account "
                  + accountData.getAccountID()
                  + " has been created.";
          req.setAttribute("results", results);
        }
      } else {
        // Password validation failed
        results = "Registration operation failed, your passwords did not match";
        System.out.println(results);
        req.setAttribute("results", results);
        requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.REGISTER_PAGE));
      }

    } catch (Exception e) {
      // log the exception with error page
      throw new ServletException(
          "TradeServletAction.doRegister(...)" + " exception user =" + userID, e);
    }
  }
  /**
   * Retrieve the current portfolio of stock holdings for the given trader Dispatch to the Trade
   * Portfolio JSP for display
   *
   * @param userID The User requesting to view their portfolio
   * @param ctx the servlet context
   * @param req the HttpRequest object
   * @param resp the HttpResponse object
   * @param results A short description of the results/success of this web request provided on the
   *     web page
   * @exception javax.servlet.ServletException If a servlet specific exception is encountered
   * @exception javax.io.IOException If an exception occurs while writing results back to the user
   */
  void doPortfolio(
      ServletContext ctx,
      HttpServletRequest req,
      HttpServletResponse resp,
      String userID,
      String results)
      throws ServletException, IOException {

    try {
      // Get the holdiings for this user

      Collection quoteDataBeans = new ArrayList();
      Collection holdingDataBeans = tAction.getHoldings(userID);

      // Walk through the collection of user
      //  holdings and creating a list of quotes
      if (holdingDataBeans.size() > 0) {

        Iterator it = holdingDataBeans.iterator();
        while (it.hasNext()) {
          HoldingDataBean holdingData = (HoldingDataBean) it.next();
          QuoteDataBean quoteData = tAction.getQuote(holdingData.getQuoteID());
          quoteDataBeans.add(quoteData);
        }
      } else {
        results = results + ".  Your portfolio is empty.";
      }
      req.setAttribute("results", results);
      req.setAttribute("holdingDataBeans", holdingDataBeans);
      req.setAttribute("quoteDataBeans", quoteDataBeans);
      requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.PORTFOLIO_PAGE));
    } catch (java.lang.IllegalArgumentException e) { // this is a user error so I will
      // forward them to another page rather than throw a 500
      req.setAttribute("results", results + "illegal argument:" + e.getMessage());
      requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.PORTFOLIO_PAGE));
      // log the exception with an error level of 3 which means, handled exception but would
      // invalidate a automation run
      Log.error(
          e,
          "TradeServletAction.doPortfolio(...)",
          "illegal argument, information should be in exception string",
          "user error");
    } catch (Exception e) {
      // log the exception with error page
      throw new ServletException(
          "TradeServletAction.doPortfolio(...)" + " exception user =" + userID, e);
    }
  }
  void doWelcome(
      ServletContext ctx, HttpServletRequest req, HttpServletResponse resp, String status)
      throws ServletException, IOException {

    req.setAttribute("results", status);
    requestDispatch(ctx, req, resp, null, TradeConfig.getPage(TradeConfig.WELCOME_PAGE));
  }
  /**
   * Sell a current holding of stock shares for the given trader. Dispatch to the Trade Portfolio
   * JSP for display
   *
   * @param userID The User buying shares
   * @param symbol The stock to sell
   * @param indx The unique index identifying the users holding to sell
   * @param ctx the servlet context
   * @param req the HttpRequest object
   * @param resp the HttpResponse object
   * @exception javax.servlet.ServletException If a servlet specific exception is encountered
   * @exception javax.io.IOException If an exception occurs while writing results back to the user
   */
  void doSell(
      ServletContext ctx,
      HttpServletRequest req,
      HttpServletResponse resp,
      String userID,
      Integer holdingID)
      throws ServletException, IOException {
    String results = "";
    try {
      OrderDataBean orderData = tAction.sell(userID, holdingID, TradeConfig.orderProcessingMode);

      req.setAttribute("orderData", orderData);
      req.setAttribute("results", results);
    } catch (java.lang.IllegalArgumentException e) { // this is a user error so I will
      // just log the exception and then later on I will redisplay the portfolio page
      // because this is just a user exception
      Log.error(
          e,
          "TradeServletAction.doSell(...)",
          "illegal argument, information should be in exception string",
          "user error");
    } catch (Exception e) {
      // log the exception with error page
      throw new ServletException(
          "TradeServletAction.doSell(...)"
              + " exception selling holding "
              + holdingID
              + " for user ="
              + userID,
          e);
    }
    requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.ORDER_PAGE));
  }
 /** Servlet initialization method. */
 public void init(ServletConfig config) throws ServletException {
   super.init(config);
   java.util.Enumeration en = config.getInitParameterNames();
   while (en.hasMoreElements()) {
     String parm = (String) en.nextElement();
     String value = config.getInitParameter(parm);
     TradeConfig.setConfigParam(parm, value);
   }
 }
  /**
   * Buy a new holding of shares for the given trader Dispatch to the Trade Portfolio JSP for
   * display
   *
   * @param userID The User buying shares
   * @param symbol The stock to purchase
   * @param amount The quantity of shares to purchase
   * @param ctx the servlet context
   * @param req the HttpRequest object
   * @param resp the HttpResponse object
   * @exception javax.servlet.ServletException If a servlet specific exception is encountered
   * @exception javax.io.IOException If an exception occurs while writing results back to the user
   */
  void doBuy(
      ServletContext ctx,
      HttpServletRequest req,
      HttpServletResponse resp,
      String userID,
      String symbol,
      String quantity)
      throws ServletException, IOException {

    String results = "";

    try {
      OrderDataBean orderData =
          tAction.buy(
              userID, symbol, new Double(quantity).doubleValue(), TradeConfig.orderProcessingMode);

      req.setAttribute("orderData", orderData);
      req.setAttribute("results", results);
    } catch (java.lang.IllegalArgumentException e) { // this is a user error so I will
      // forward them to another page rather than throw a 500
      req.setAttribute("results", results + "illegal argument:");
      requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.HOME_PAGE));
      // log the exception with an error level of 3 which means, handled exception but would
      // invalidate a automation run
      Log.error(
          e,
          "TradeServletAction.doBuy(...)",
          "illegal argument. userID = " + userID,
          "symbol = " + symbol);
    } catch (Exception e) {
      // log the exception with error page
      throw new ServletException(
          "TradeServletAction.buy(...)"
              + " exception buying stock "
              + symbol
              + " for user "
              + userID,
          e);
    }
    requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.ORDER_PAGE));
  }
  /**
   * Retrieve the current Quote for the given stock symbol Dispatch to the Trade Quote JSP for
   * display
   *
   * @param userID The stock symbol used to get the current quote
   * @param ctx the servlet context
   * @param req the HttpRequest object
   * @param resp the HttpResponse object
   * @exception javax.servlet.ServletException If a servlet specific exception is encountered
   * @exception javax.io.IOException If an exception occurs while writing results back to the user
   */
  void doQuotes(
      ServletContext ctx,
      HttpServletRequest req,
      HttpServletResponse resp,
      String userID,
      String symbols)
      throws ServletException, IOException {
    String results = "";

    // Edge Caching:
    // Getting Quotes has been moved to the JSP
    // Quote.jsp. This makes each Quote  a
    // standalone "fragment", and thus is a candidate for
    // Edge caching.
    //

    requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.QUOTE_PAGE));
  }
  /**
   * Logout a Trade User Dispatch to the Trade Welcome JSP for display
   *
   * @param userID The User to logout
   * @param ctx the servlet context
   * @param req the HttpRequest object
   * @param resp the HttpResponse object
   * @param results A short description of the results/success of this web request provided on the
   *     web page
   * @exception javax.servlet.ServletException If a servlet specific exception is encountered
   * @exception javax.io.IOException If an exception occurs while writing results back to the user
   */
  void doLogout(ServletContext ctx, HttpServletRequest req, HttpServletResponse resp, String userID)
      throws ServletException, IOException {
    String results = "";

    try {
      tAction.logout(userID);

    } catch (java.lang.IllegalArgumentException e) { // this is a user error so I will
      // forward them to another page, at the end of the page.
      req.setAttribute("results", results + "illegal argument:" + e.getMessage());

      // log the exception with an error level of 3 which means, handled exception but would
      // invalidate a automation run
      Log.error(
          e,
          "TradeServletAction.doLogout(...)",
          "illegal argument, information should be in exception string",
          "treating this as a user error and forwarding on to a new page");
    } catch (Exception e) {
      // log the exception and foward to a error page
      Log.error(
          e,
          "TradeServletAction.doLogout(...):",
          "Error logging out" + userID,
          "fowarding to an error page");
      // set the status_code to 500
      throw new ServletException(
          "TradeServletAction.doLogout(...)" + "exception logging out user " + userID, e);
    }
    HttpSession session = req.getSession();
    if (session != null) {
      session.invalidate();
    }

    Object o = req.getAttribute("TSS-RecreateSessionInLogout");
    if (o != null && ((Boolean) o).equals(Boolean.TRUE)) {
      // Recreate Session object before writing output to the response
      // Once the response headers are written back to the client the opportunity
      // to create a new session in this request may be lost
      // This is to handle only the TradeScenarioServlet case
      session = req.getSession(true);
    }
    requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.WELCOME_PAGE));
  }
  /**
   * Main service method for TradeScenarioServlet
   *
   * @param request Object that encapsulates the request to the servlet
   * @param response Object that encapsulates the response from the servlet
   */
  public void performTask(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    // Scenario generator for Trade2
    char action = ' ';
    String userID = null;

    // String to create full dispatch path to TradeAppServlet w/ request Parameters
    String dispPath = null; // Dispatch Path to TradeAppServlet

    String scenarioAction = (String) req.getParameter("action");
    if ((scenarioAction != null) && (scenarioAction.length() >= 1)) {
      action = scenarioAction.charAt(0);
      if (action == 'n') { // null;
        try {
          resp.setContentType("text/html");
          PrintWriter out = new PrintWriter(resp.getOutputStream());
          out.println("<HTML><HEAD>TradeScenarioServlet</HEAD><BODY>Hello</BODY></HTML>");
          out.close();
          return;

        } catch (Exception e) {
          Log.error(
              "trade_client.TradeScenarioServlet.service(...)"
                  + "error creating printwriter from responce.getOutputStream",
              e);

          resp.sendError(
              500,
              "trade_client.TradeScenarioServlet.service(...): erorr creating and writing to PrintStream created from response.getOutputStream()");
        } // end of catch
      } // end of action=='n'
    }

    ServletContext ctx = null;
    HttpSession session = null;
    try {
      ctx = getServletConfig().getServletContext();
      // These operations require the user to be logged in. Verify the user and if not logged in
      // change the operation to a login
      session = req.getSession(true);
      userID = (String) session.getAttribute("uidBean");
    } catch (Exception e) {
      Log.error(
          "trade_client.TradeScenarioServlet.service(...): performing "
              + scenarioAction
              + "error getting ServletContext,HttpSession, or UserID from session"
              + "will make scenarioAction a login and try to recover from there",
          e);
      userID = null;
      action = 'l';
    }

    if (userID == null) {
      action = 'l'; // change to login
      TradeConfig.incrementScenarioCount();
    } else if (action == ' ') {
      // action is not specified perform a random operation according to current mix
      // Tell getScenarioAction if we are an original user or a registered user
      // -- sellDeficits should only be compensated for with original users.
      action = TradeConfig.getScenarioAction(userID.startsWith(TradeConfig.newUserPrefix));
    }
    switch (action) {
      case 'q': // quote
        dispPath = tasPathPrefix + "quotes&symbols=" + TradeConfig.rndSymbols();
        ctx.getRequestDispatcher(dispPath).include(req, resp);
        break;
      case 'a': // account
        dispPath = tasPathPrefix + "account";
        ctx.getRequestDispatcher(dispPath).include(req, resp);
        break;
      case 'u': // update account profile
        dispPath = tasPathPrefix + "account";
        ctx.getRequestDispatcher(dispPath).include(req, resp);

        String fullName = "rnd" + System.currentTimeMillis();
        String address = "rndAddress";
        String password = "******";
        String email = "rndEmail";
        String creditcard = "rndCC";
        dispPath =
            tasPathPrefix
                + "update_profile&fullname="
                + fullName
                + "&password="******"&cpassword="******"&address="
                + address
                + "&email="
                + email
                + "&creditcard="
                + creditcard;
        ctx.getRequestDispatcher(dispPath).include(req, resp);
        break;
      case 'h': // home
        dispPath = tasPathPrefix + "home";
        ctx.getRequestDispatcher(dispPath).include(req, resp);
        break;
      case 'l': // login
        userID = TradeConfig.getUserID();
        String password2 = "xxx";
        dispPath = tasPathPrefix + "login&inScenario=true&uid=" + userID + "&passwd=" + password2;
        ctx.getRequestDispatcher(dispPath).include(req, resp);

        // login is successful if the userID is written to the HTTP session
        if (session.getAttribute("uidBean") == null) {
          System.out.println("TradeScenario login failed. Reset DB between runs");
        }
        break;
      case 'o': // logout
        dispPath = tasPathPrefix + "logout";
        ctx.getRequestDispatcher(dispPath).include(req, resp);
        break;
      case 'p': // portfolio
        dispPath = tasPathPrefix + "portfolio";
        ctx.getRequestDispatcher(dispPath).include(req, resp);
        break;
      case 'r': // register
        // Logout the current user to become a new user
        // see note in TradeServletAction
        req.setAttribute("TSS-RecreateSessionInLogout", Boolean.TRUE);
        dispPath = tasPathPrefix + "logout";
        ctx.getRequestDispatcher(dispPath).include(req, resp);

        userID = TradeConfig.rndNewUserID();
        String passwd = "yyy";
        fullName = TradeConfig.rndFullName();
        creditcard = TradeConfig.rndCreditCard();
        String money = TradeConfig.rndBalance();
        email = TradeConfig.rndEmail(userID);
        String smail = TradeConfig.rndAddress();
        dispPath =
            tasPathPrefix
                + "register&Full Name="
                + fullName
                + "&snail mail="
                + smail
                + "&email="
                + email
                + "&user id="
                + userID
                + "&passwd="
                + passwd
                + "&confirm passwd="
                + passwd
                + "&money="
                + money
                + "&Credit Card Number="
                + creditcard;
        ctx.getRequestDispatcher(dispPath).include(req, resp);
        break;
      case 's': // sell
        dispPath = tasPathPrefix + "portfolioNoEdge";
        ctx.getRequestDispatcher(dispPath).include(req, resp);

        Collection holdings = (Collection) req.getAttribute("holdingDataBeans");
        int numHoldings = holdings.size();
        if (numHoldings > 0) {
          // sell first available security out of holding

          Iterator it = holdings.iterator();
          boolean foundHoldingToSell = false;
          while (it.hasNext()) {
            HoldingDataBean holdingData = (HoldingDataBean) it.next();
            if (!(holdingData.getPurchaseDate().equals(new java.util.Date(0)))) {
              Integer holdingID = holdingData.getHoldingID();

              dispPath = tasPathPrefix + "sell&holdingID=" + holdingID;
              ctx.getRequestDispatcher(dispPath).include(req, resp);
              foundHoldingToSell = true;
              break;
            }
          }
          if (foundHoldingToSell) break;
          if (Log.doTrace())
            Log.trace(
                "TradeScenario: No holding to sell -switch to buy -- userID = "
                    + userID
                    + "  Collection count = "
                    + numHoldings);
        }
        // At this point: A TradeScenario Sell was requested with No Stocks in Portfolio
        // This can happen when a new registered user happens to request a sell before a buy
        // In this case, fall through and perform a buy instead

        /* Trade 2.037: Added sell_deficit counter to maintain correct buy/sell mix.
         * When a users portfolio is reduced to 0 holdings, a buy is requested instead of a sell.
         * This throws off the buy/sell mix by 1. This results in unwanted holding table growth
         * To fix this we increment a sell deficit counter to maintain the correct ratio in getScenarioAction
         * The 'z' action from getScenario denotes that this is a sell action that was switched from a buy
         * to reduce a sellDeficit
         */
        if (userID.startsWith(TradeConfig.newUserPrefix) == false) {
          TradeConfig.incrementSellDeficit();
        }
      case 'b': // buy
        String symbol = TradeConfig.rndSymbol();
        String amount = TradeConfig.rndQuantity() + "";

        dispPath = tasPathPrefix + "quotes&symbols=" + symbol;
        ctx.getRequestDispatcher(dispPath).include(req, resp);

        dispPath = tasPathPrefix + "buy&quantity=" + amount + "&symbol=" + symbol;
        ctx.getRequestDispatcher(dispPath).include(req, resp);
        break;
    } // end of switch statement
  }
 TradeServletAction() {
   if (TradeConfig.getAccessMode() == TradeConfig.STANDARD) tAction = new TradeDirect();
 }
  /**
   * Login a Trade User. Dispatch to the Trade Home JSP for display
   *
   * @param userID The User to login
   * @param passwd The password supplied by the trader used to authenticate
   * @param ctx the servlet context
   * @param req the HttpRequest object
   * @param resp the HttpResponse object
   * @param results A short description of the results/success of this web request provided on the
   *     web page
   * @exception javax.servlet.ServletException If a servlet specific exception is encountered
   * @exception javax.io.IOException If an exception occurs while writing results back to the user
   */
  void doLogin(
      ServletContext ctx,
      HttpServletRequest req,
      HttpServletResponse resp,
      String userID,
      String passwd)
      throws javax.servlet.ServletException, java.io.IOException {
    System.out.println("Login userID: " + userID);
    String results = "";
    try {
      // Got a valid userID and passwd, attempt login

      AccountDataBean accountData = tAction.login(userID, passwd);

      if (accountData != null) {
        HttpSession session = req.getSession(true);
        session.setAttribute("uidBean", userID);
        session.setAttribute("sessionCreationDate", new java.util.Date());
        if (("true").equals(req.getParameter("stress"))) {
          // fib(35);
          char[] s = new char[10 * 1024 * 1000];
          String str = String.copyValueOf(s);
          session.setAttribute("someobject", str);
        }
        results = "Ready to Trade";
        doHome(ctx, req, resp, userID, results);
        return;
      } else {
        req.setAttribute("results", results + "\nCould not find account for + " + userID);
        // log the exception with an error level of 3 which means, handled exception but would
        // invalidate a automation run
        Log.log(
            "TradeServletAction.doLogin(...)",
            "Error finding account for user " + userID + "",
            "user entered a bad username or the database is not populated");
      }
    } catch (java.lang.IllegalArgumentException e) { // this is a user error so I will
      // forward them to another page rather than throw a 500
      req.setAttribute("results", results + "illegal argument:" + e.getMessage());
      // log the exception with an error level of 3 which means, handled exception but would
      // invalidate a automation run
      Log.error(
          e,
          "TradeServletAction.doLogin(...)",
          "illegal argument, information should be in exception string",
          "treating this as a user error and forwarding on to a new page");

    } catch (Exception e) {
      doWelcome(
          ctx,
          req,
          resp,
          "User not found! Is the database <a href = 'config?action=buildDB'>populated </a>?");
      return;
      /*			throw new ServletException(
      "TradeServletAction.doLogin(...)"
      	+ "Exception logging in user "
      	+ userID
      	+ "with password"
      	+ passwd
      	,e);
      	*/

    }

    requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.WELCOME_PAGE));
  }
  /**
   * Create the Trade Home page with personalized information such as the traders account balance
   * Dispatch to the Trade Home JSP for display
   *
   * @param ctx the servlet context
   * @param req the HttpRequest object
   * @param resp the HttpResponse object
   * @param results A short description of the results/success of this web request provided on the
   *     web page
   * @exception javax.servlet.ServletException If a servlet specific exception is encountered
   * @exception javax.io.IOException If an exception occurs while writing results back to the user
   */
  void doHome(
      ServletContext ctx,
      HttpServletRequest req,
      HttpServletResponse resp,
      String userID,
      String results)
      throws javax.servlet.ServletException, java.io.IOException {
    BigDecimal balance;
    String result = "";
    try {
      AccountDataBean accountData = tAction.getAccountData(userID);
      Collection holdingDataBeans = tAction.getHoldings(userID);

      // Edge Caching:
      // Getting the MarketSummary has been moved to the JSP
      // MarketSummary.jsp. This makes the MarketSummary a
      // standalone "fragment", and thus is a candidate for
      // Edge caching.
      // marketSummaryData = tAction.getMarketSummary();

      req.setAttribute("accountData", accountData);
      req.setAttribute("holdingDataBeans", holdingDataBeans);
      // See Edge Caching above
      // req.setAttribute("marketSummaryData", marketSummaryData);
      req.setAttribute("results", results);
    } catch (java.lang.IllegalArgumentException e) { // this is a user error so I will
      // forward them to another page rather than throw a 500
      req.setAttribute(
          "results", results + "check userID = " + userID + " and that the database is populated");
      requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.HOME_PAGE));
      // log the exception with an error level of 3 which means, handled exception but would
      // invalidate a automation run
      Log.error(
          "TradeServletAction.doHome(...)"
              + "illegal argument, information should be in exception string"
              + "treating this as a user error and forwarding on to a new page",
          e);
    }
    // ALPINE No support for EJB's yet
    /*catch (javax.ejb.FinderException e)
    {
    	//this is a user error so I will
    	//forward them to another page rather than throw a 500
    	req.setAttribute(
    		"results",
    		results + "\nCould not find account for + " + userID);
    	//requestDispatch(ctx, req, resp, TradeConfig.getPage(TradeConfig.HOME_PAGE));
    	//log the exception with an error level of 3 which means, handled exception but would invalidate a automation run
    	Log.error(
    		"TradeServletAction.doHome(...)" +
    		"Error finding account for user " + userID +
    		"treating this as a user error and forwarding on to a new page", e);
    }*/
    catch (Exception e) {
      // log the exception with error page
      throw new ServletException(
          "TradeServletAction.doHome(...)" + " exception user =" + userID, e);
    }

    requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.HOME_PAGE));
  }