public void print() {
   Log.log(this.toString());
 }
Esempio n. 2
0
  /**
   * This is a convenience method for servlets to set Trade configuration parameters from servlet
   * initialization parameters. The servlet provides the init param and its value as strings. This
   * method then parses the parameter, converts the value to the correct type and sets the
   * corresponding TradeConfig parameter to the converted value
   */
  public static void setConfigParam(String parm, String value) {
    Log.log("TradeConfig setting parameter: " + parm + "=" + value);
    // Compare the parm value to valid TradeConfig parameters that can be set
    // by servlet initialization

    // First check the proposed new parm and value - if empty or null ignore it
    if (parm == null) return;
    parm = parm.trim();
    if (parm.length() <= 0) return;
    if (value == null) return;
    value = value.trim();

    if (parm.equalsIgnoreCase("runTimeMode")) {
      try {
        for (int i = 0; i < runTimeModeNames.length; i++) {
          if (value.equalsIgnoreCase(runTimeModeNames[i])) {
            runTimeMode = i;
            break;
          }
        }
      } catch (Exception e) {
        // >>rjm
        Log.error(
            "TradeConfig.setConfigParm(..): minor exception caught"
                + "trying to set runtimemode to "
                + value
                + "reverting to current value: "
                + runTimeModeNames[runTimeMode],
            e);
      } // If the value is bad, simply revert to current
    } else if (parm.equalsIgnoreCase("orderProcessingMode")) {
      try {
        for (int i = 0; i < orderProcessingModeNames.length; i++) {
          if (value.equalsIgnoreCase(orderProcessingModeNames[i])) {
            orderProcessingMode = i;
            break;
          }
        }
      } catch (Exception e) {
        Log.error(
            "TradeConfig.setConfigParm(..): minor exception caught"
                + "trying to set orderProcessingMode to "
                + value
                + "reverting to current value: "
                + orderProcessingModeNames[orderProcessingMode],
            e);
      } // If the value is bad, simply revert to current
    } else if (parm.equalsIgnoreCase("accessMode")) {
      try {
        for (int i = 0; i < accessModeNames.length; i++) {
          if (value.equalsIgnoreCase(accessModeNames[i])) {
            accessMode = i;
            break;
          }
        }
      } catch (Exception e) {
        Log.error(
            "TradeConfig.setConfigParm(..): minor exception caught"
                + "trying to set accessMode to "
                + value
                + "reverting to current value: "
                + accessModeNames[accessMode],
            e);
      }
    } else if (parm.equalsIgnoreCase("webServicesEndpoint")) {
      try {
        setSoapURL(value);
      } catch (Exception e) {
        Log.error(
            "TradeConfig.setConfigParm(..): minor exception caught"
                + "Setting web services endpoint",
            e);
      } // On error, revert to saved
    } else if (parm.equalsIgnoreCase("workloadMix")) {
      try {
        for (int i = 0; i < workloadMixNames.length; i++) {
          if (value.equalsIgnoreCase(workloadMixNames[i])) {
            workloadMix = i;
            break;
          }
        }
      } catch (Exception e) {
        Log.error(
            "TradeConfig.setConfigParm(..): minor exception caught"
                + "trying to set workloadMix to "
                + value
                + "reverting to current value: "
                + workloadMixNames[workloadMix],
            e);
      } // If the value is bad, simply revert to current
    } else if (parm.equalsIgnoreCase("WebInterface")) {
      try {
        for (int i = 0; i < webInterfaceNames.length; i++) {
          if (value.equalsIgnoreCase(webInterfaceNames[i])) {
            webInterface = i;
            break;
          }
        }
      } catch (Exception e) {
        Log.error(
            "TradeConfig.setConfigParm(..): minor exception caught"
                + "trying to set WebInterface to "
                + value
                + "reverting to current value: "
                + webInterfaceNames[webInterface],
            e);
      } // If the value is bad, simply revert to current
    } else if (parm.equalsIgnoreCase("CachingType")) {
      try {
        for (int i = 0; i < cachingTypeNames.length; i++) {
          if (value.equalsIgnoreCase(cachingTypeNames[i])) {
            cachingType = i;
            break;
          }
        }
      } catch (Exception e) {
        Log.error(
            "TradeConfig.setConfigParm(..): minor exception caught"
                + "trying to set CachingType to "
                + value
                + "reverting to current value: "
                + cachingTypeNames[cachingType],
            e);
      } // If the value is bad, simply revert to current
    } else if (parm.equalsIgnoreCase("maxUsers")) {
      try {
        MAX_USERS = Integer.parseInt(value);
      } catch (Exception e) {
        Log.error(
            "TradeConfig.setConfigParm(..): minor exception caught"
                + "Setting maxusers, error parsing string to int:"
                + value
                + "revering to current value: "
                + MAX_USERS,
            e);
      } // On error, revert to saved
    } else if (parm.equalsIgnoreCase("maxQuotes")) {
      try {
        MAX_QUOTES = Integer.parseInt(value);
      } catch (Exception e) {
        // >>rjm
        Log.error(
            "TradeConfig.setConfigParm(...) minor exception caught"
                + "Setting max_quotes, error parsing string to int "
                + value
                + "reverting to current value: "
                + MAX_QUOTES,
            e);
        // <<rjm
      } // On error, revert to saved
    } else if (parm.equalsIgnoreCase("primIterations")) {
      try {
        primIterations = Integer.parseInt(value);
      } catch (Exception e) {
        Log.error(
            "TradeConfig.setConfigParm(..): minor exception caught"
                + "Setting primIterations, error parsing string to int:"
                + value
                + "revering to current value: "
                + primIterations,
            e);
      } // On error, revert to saved
    } else if (parm.equalsIgnoreCase("LongRun")) {
      try {
        longRun = value.equalsIgnoreCase("true");
      } catch (Exception e) {
        Log.error(
            "TradeConfig.setConfigParm(..): minor exception caught"
                + "Setting primIterations, error parsing string to int:"
                + value
                + "revering to current value: "
                + longRun,
            e);
      } // On error, revert to saved
    }
  }
  /**
   * 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));
  }