/** * 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)); }