You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ho...@apache.org on 2005/10/03 04:35:08 UTC
svn commit: r293214 [2/4] - in /geronimo/trunk/sandbox/daytrader: ./
modules/ear/ modules/ear/src/META-INF/ modules/ear/src/application/
modules/ear/src/conf/ modules/ear/src/test-cactus/ modules/ear/src/webapp2/
modules/ear/target/ modules/ejb/src/MET...
Added: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java?rev=293214&view=auto
==============================================================================
--- geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java (added)
+++ geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java Sun Oct 2 19:34:49 2005
@@ -0,0 +1,374 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.samples.daytrader.web;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import org.apache.geronimo.samples.daytrader.util.*;
+
+import java.io.IOException;
+import org.apache.geronimo.samples.daytrader.*;
+
+/**
+ * TradeConfigServlet provides a servlet interface to adjust Trade runtime parameters.
+ * TradeConfigServlet updates values in the {@link org.apache.geronimo.samples.daytrader.web.TradeConfig} JavaBean holding
+ * all configuration and runtime parameters for the Trade application
+ *
+ */
+public class TradeConfigServlet extends HttpServlet {
+
+ /**
+ * Servlet initialization method.
+ */
+ public void init(ServletConfig config) throws ServletException
+ {
+ super.init(config);
+ }
+ /**
+ * Create the TradeConfig bean and pass it the config.jsp page
+ * to display the current Trade runtime configuration
+ * Creation date: (2/8/2000 3:43:59 PM)
+ */
+ void doConfigDisplay(
+ HttpServletRequest req,
+ HttpServletResponse resp,
+ String results)
+ throws Exception {
+
+ TradeConfig currentConfig = new TradeConfig();
+
+ req.setAttribute("tradeConfig", currentConfig);
+ req.setAttribute("status", results);
+ getServletConfig()
+ .getServletContext()
+ .getRequestDispatcher(TradeConfig.getPage(TradeConfig.CONFIG_PAGE))
+ .include(req, resp);
+ }
+
+ void doResetTrade(
+ HttpServletRequest req,
+ HttpServletResponse resp,
+ String results)
+ throws Exception
+ {
+ RunStatsDataBean runStatsData = new RunStatsDataBean();
+ TradeConfig currentConfig = new TradeConfig();
+ try
+ {
+ runStatsData = new TradeAction().resetTrade(false);
+
+ req.setAttribute("runStatsData", runStatsData);
+ req.setAttribute("tradeConfig", currentConfig);
+ results += "Trade Reset completed successfully";
+ req.setAttribute("status", results);
+
+ }
+ catch (Exception e)
+ {
+ results += "Trade Reset Error - see log for details";
+ Log.error(e, results);
+ throw e;
+ }
+ getServletConfig()
+ .getServletContext()
+ .getRequestDispatcher(TradeConfig.getPage(TradeConfig.STATS_PAGE))
+ .include(req, resp);
+
+ }
+
+
+ /**
+ * Update Trade runtime configuration paramaters
+ * Creation date: (2/8/2000 3:44:24 PM)
+ */
+ void doConfigUpdate(HttpServletRequest req, HttpServletResponse resp)
+ throws Exception {
+
+ TradeConfig currentConfig = new TradeConfig();
+
+ String currentConfigStr = "\n\n########## Trade configuration update. Current config:\n\n";
+ String runTimeModeStr = req.getParameter("RunTimeMode");
+ if (runTimeModeStr != null)
+ {
+ try
+ {
+ int i = Integer.parseInt(runTimeModeStr);
+ if ((i >= 0)
+ && (i < TradeConfig.runTimeModeNames.length)) //Input validation
+ TradeConfig.runTimeMode = i;
+ }
+ catch (Exception e)
+ {
+ //>>rjm
+ Log.error(
+ e,
+ "TradeConfigServlet.doConfigUpdate(..): minor exception caught",
+ "trying to set runtimemode to " + runTimeModeStr,
+ "reverting to current value");
+
+ } // If the value is bad, simply revert to current
+ }
+ currentConfigStr += "\t\tRunTimeMode:\t\t" + TradeConfig.runTimeModeNames[TradeConfig.runTimeMode] + "\n";
+
+
+ String orderProcessingModeStr = req.getParameter("OrderProcessingMode");
+ if (orderProcessingModeStr != null)
+ {
+ try
+ {
+ int i = Integer.parseInt(orderProcessingModeStr);
+ if ((i >= 0)
+ && (i < TradeConfig.orderProcessingModeNames.length)) //Input validation
+ TradeConfig.orderProcessingMode = i;
+ }
+ catch (Exception e)
+ {
+ //>>rjm
+ Log.error(
+ e,
+ "TradeConfigServlet.doConfigUpdate(..): minor exception caught",
+ "trying to set orderProcessing to " + orderProcessingModeStr,
+ "reverting to current value");
+
+ } // If the value is bad, simply revert to current
+ }
+ currentConfigStr += "\t\tOrderProcessingMode:\t" + TradeConfig.orderProcessingModeNames[TradeConfig.orderProcessingMode] + "\n";
+
+ String accessModeStr = req.getParameter("AcessMode");
+ if (accessModeStr != null)
+ {
+ try
+ {
+ int i = Integer.parseInt(accessModeStr);
+ if ((i >= 0)
+ && (i < TradeConfig.accessModeNames.length) && (i != TradeConfig.getAccessMode())) //Input validation
+ TradeConfig.setAccessMode(i);
+ }
+ catch (Exception e)
+ {
+ //>>rjm
+ Log.error(
+ e,
+ "TradeConfigServlet.doConfigUpdate(..): minor exception caught",
+ "trying to set orderProcessing to " + orderProcessingModeStr,
+ "reverting to current value");
+
+ } // If the value is bad, simply revert to current
+ }
+ currentConfigStr += "\t\tAcessMode:\t\t" + TradeConfig.accessModeNames[TradeConfig.getAccessMode()] + "\n";
+
+
+ String workloadMixStr = req.getParameter("WorkloadMix");
+ if (workloadMixStr != null)
+ {
+ try
+ {
+ int i = Integer.parseInt(workloadMixStr);
+ if ((i >= 0)
+ && (i < TradeConfig.workloadMixNames.length)) //Input validation
+ TradeConfig.workloadMix = i;
+ }
+ catch (Exception e)
+ {
+ Log.error(
+ e,
+ "TradeConfigServlet.doConfigUpdate(..): minor exception caught",
+ "trying to set workloadMix to " + workloadMixStr,
+ "reverting to current value");
+ } // If the value is bad, simply revert to current
+ }
+ currentConfigStr += "\t\tWorkload Mix:\t\t" + TradeConfig.workloadMixNames[TradeConfig.workloadMix] + "\n";
+
+
+
+ String webInterfaceStr = req.getParameter("WebInterface");
+ if (webInterfaceStr != null)
+ {
+ try
+ {
+ int i = Integer.parseInt(webInterfaceStr);
+ if ((i >= 0)
+ && (i < TradeConfig.webInterfaceNames.length)) //Input validation
+ TradeConfig.webInterface = i;
+ }
+ catch (Exception e)
+ {
+ Log.error(
+ e,
+ "TradeConfigServlet.doConfigUpdate(..): minor exception caught",
+ "trying to set WebInterface to " + webInterfaceStr,
+ "reverting to current value");
+
+
+ } // If the value is bad, simply revert to current
+ }
+ currentConfigStr += "\t\tWeb Interface:\t\t" + TradeConfig.webInterfaceNames[TradeConfig.webInterface] + "\n";
+
+ String cachingTypeStr = req.getParameter("CachingType");
+ if (cachingTypeStr != null)
+ {
+ try
+ {
+ int i = Integer.parseInt(cachingTypeStr);
+ if ((i >= 0)
+ && (i < TradeConfig.cachingTypeNames.length)) //Input validation
+ TradeConfig.cachingType = i;
+ }
+ catch (Exception e)
+ {
+ Log.error(
+ e,
+ "TradeConfigServlet.doConfigUpdate(..): minor exception caught",
+ "trying to set CachingType to " + cachingTypeStr,
+ "reverting to current value");
+ } // If the value is bad, simply revert to current
+ }
+ currentConfigStr += "\t\tCachingType:\t\t" + TradeConfig.cachingTypeNames[TradeConfig.cachingType] + "\n";
+
+ String parm = req.getParameter("SOAP_URL");
+ if ((parm != null) && (parm.length() > 0))
+ {
+ if (!TradeConfig.getSoapURL().equals(parm)) {
+ TradeConfig.setSoapURL(parm);
+ }
+ }
+ else
+ {
+ TradeConfig.setSoapURL(null);
+ }
+
+ parm = req.getParameter("MaxUsers");
+ if ((parm != null) && (parm.length() > 0))
+ {
+ try
+ {
+ TradeConfig.setMAX_USERS(Integer.parseInt(parm));
+ }
+ catch (Exception e)
+ {
+ Log.error(
+ e,
+ "TradeConfigServlet.doConfigUpdate(..): minor exception caught",
+ "Setting maxusers, probably error parsing string to int:" + parm,
+ "revertying to current value: " + TradeConfig.getMAX_USERS());
+
+ } //On error, revert to saved
+ }
+ parm = req.getParameter("MaxQuotes");
+ if ((parm != null) && (parm.length() > 0))
+ {
+ try
+ {
+ TradeConfig.setMAX_QUOTES(Integer.parseInt(parm));
+ }
+ catch (Exception e)
+ {
+ //>>rjm
+ Log.error(
+ e,
+ "TradeConfigServlet: minor exception caught",
+ "trying to set max_quotes, error on parsing int " + parm,
+ "reverting to current value " + TradeConfig.getMAX_QUOTES());
+ //<<rjm
+
+ } //On error, revert to saved
+ }
+ currentConfigStr += "\t\t#Trade Users:\t\t" + TradeConfig.getMAX_USERS() + "\n";
+ currentConfigStr += "\t\t#Trade Quotes:\t\t" + TradeConfig.getMAX_QUOTES() + "\n";
+
+ parm = req.getParameter("primIterations");
+ if ((parm != null) && (parm.length() > 0)) {
+ try {
+ TradeConfig.setPrimIterations(Integer.parseInt(parm));
+ }
+ catch (Exception e) {
+ Log.error(
+ e,
+ "TradeConfigServlet: minor exception caught",
+ "trying to set primIterations, error on parsing int " + parm,
+ "reverting to current value " + TradeConfig.getPrimIterations());
+
+ }
+ }
+
+ String enableTrace = req.getParameter("EnableTrace");
+ if (enableTrace != null)
+ Log.setTrace(true);
+ else
+ Log.setTrace(false);
+ String enableActionTrace = req.getParameter("EnableActionTrace");
+ if (enableActionTrace != null)
+ Log.setActionTrace(true);
+ else
+ Log.setActionTrace(false);
+
+ System.out.println(currentConfigStr);
+
+ }
+
+ public void service(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ String action = null;
+ String result = "";
+
+ resp.setContentType("text/html");
+ try
+ {
+ action = req.getParameter("action");
+ if (action == null)
+ {
+ doConfigDisplay(req, resp, result + "Current Trade Configuration:");
+ return;
+ }
+ else if (action.equals("updateConfig"))
+ {
+ doConfigUpdate(req, resp);
+ result = "<B><BR>Trade Configuration Updated</BR></B>";
+ }
+ else if (action.equals("resetTrade"))
+ {
+ doResetTrade(req, resp, "");
+ return;
+ }
+ else if (action.equals("buildDB"))
+ {
+ resp.setContentType("text/html");
+ new TradeBuildDB(resp.getWriter());
+ result = "Trade Database Built - " + TradeConfig.getMAX_USERS() + "users created";
+ }
+ doConfigDisplay(req, resp, result + "Current Trade Configuration:");
+ }
+ catch (Exception e)
+ {
+ Log.error(
+ e,
+ "TradeConfigServlet.service(...)",
+ "Exception trying to perform action=" + action);
+
+ resp.sendError(
+ 500,
+ "TradeConfigServlet.service(...)"
+ + "Exception trying to perform action="
+ + action
+ + "\nException details: " + e.toString());
+
+ }
+ }
+}
Propchange: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeScenarioServlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeScenarioServlet.java?rev=293214&view=auto
==============================================================================
--- geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeScenarioServlet.java (added)
+++ geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeScenarioServlet.java Sun Oct 2 19:34:49 2005
@@ -0,0 +1,298 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.samples.daytrader.web;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import org.apache.geronimo.samples.daytrader.util.*;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.io.IOException;
+import java.io.PrintWriter;
+import org.apache.geronimo.samples.daytrader.*;
+
+/**
+ * TradeScenarioServlet emulates a population of web users by generating a specific Trade operation
+ * for a randomly chosen user on each access to the URL. Test this servlet by clicking Trade Scenario
+ * and hit "Reload" on your browser to step through a Trade Scenario. To benchmark using this URL aim
+ * your favorite web load generator (such as AKStress) at the Trade Scenario URL and fire away.
+ */
+public class TradeScenarioServlet extends HttpServlet {
+
+ /**
+ * 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);
+ }
+ }
+
+ /**
+ * Returns a string that contains information about TradeScenarioServlet
+ *
+ * @return The servlet information
+ */
+ public java.lang.String getServletInfo()
+ {
+ return "TradeScenarioServlet emulates a population of web users";
+ }
+
+
+
+ /**
+ * Process incoming HTTP GET requests
+ *
+ * @param request Object that encapsulates the request to the servlet
+ * @param response Object that encapsulates the response from the servlet
+ */
+ public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
+ throws ServletException, IOException
+ {
+ performTask(request,response);
+ }
+
+ /**
+ * Process incoming HTTP POST requests
+ *
+ * @param request Object that encapsulates the request to the servlet
+ * @param response Object that encapsulates the response from the servlet
+ */
+ public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
+ throws ServletException, IOException
+ {
+ performTask(request,response);
+ }
+
+ /**
+ * 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 = "xxx";
+ String email = "rndEmail";
+ String creditcard = "rndCC";
+ dispPath = tasPathPrefix + "update_profile&fullname=" + fullName +
+ "&password=" + password + "&cpassword=" + password +
+ "&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
+ }
+
+ // URL Path Prefix for dispatching to TradeAppServlet
+ private final static String tasPathPrefix = "/app?action=";
+
+}
Propchange: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeScenarioServlet.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java?rev=293214&view=auto
==============================================================================
--- geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java (added)
+++ geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java Sun Oct 2 19:34:49 2005
@@ -0,0 +1,736 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.samples.daytrader.web;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import org.apache.geronimo.samples.daytrader.soap.*;
+import org.apache.geronimo.samples.daytrader.util.*;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.ArrayList;
+import java.math.BigDecimal;
+import org.apache.geronimo.samples.daytrader.*;
+
+/**
+ * TradeServletAction provides servlet specific client side access to each of the Trade
+ * brokerage user operations. These include login, logout, buy, sell, getQuote, etc.
+ * TradeServletAction manages a web interface to Trade handling HttpRequests/HttpResponse objects
+ * and forwarding results to the appropriate JSP page for the web interface.
+ * TradeServletAction invokes {@link TradeAction} methods to actually perform
+ * each trading operation.
+ *
+ */
+public class TradeServletAction {
+
+ private TradeServices tAction = null;
+
+ TradeServletAction()
+ {
+ if(TradeConfig.getAccessMode() == TradeConfig.STANDARD)
+ tAction = new TradeAction();
+ else if(TradeConfig.getAccessMode() == TradeConfig.WEBSERVICES)
+ tAction = new TradeWebSoapProxy();
+ }
+
+ /**
+ * 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);
+ Collection orderDataBeans = 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);
+ }
+
+ }
+ /**
+ * Update User Profile information such as address, email, etc. for the given Trader
+ * Dispatch to the Trade Account JSP for display
+ * If any in put is incorrect revert back to the account page w/ an appropriate message
+ *
+ * @param userID The User to upddate profile info
+ * @param password The new User password
+ * @param cpassword Confirm password
+ * @param fullname The new User fullname info
+ * @param address The new User address info
+ * @param cc The new User credit card info
+ * @param email The new User email info
+ * @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 doAccountUpdate(
+ ServletContext ctx,
+ HttpServletRequest req,
+ HttpServletResponse resp,
+ String userID,
+ String password,
+ String cpassword,
+ String fullName,
+ String address,
+ String creditcard,
+ String email)
+ throws javax.servlet.ServletException, java.io.IOException {
+ String results = "";
+
+ //First verify input data
+ boolean doUpdate = true;
+ if ( password.equals(cpassword) == false )
+ {
+ results = "Update profile error: passwords do not match";
+ doUpdate = false;
+ }
+ else if ( password.length() <= 0 ||
+ fullName.length() <= 0 ||
+ address.length() <= 0 ||
+ creditcard.length() <= 0 ||
+ email.length() <= 0
+ )
+ {
+ results = "Update profile error: please fill in all profile information fields";
+ doUpdate = false;
+ }
+ AccountProfileDataBean accountProfileData = new AccountProfileDataBean(userID, password, fullName, address, email, creditcard);
+ try
+ {
+ if (doUpdate)
+ {
+ accountProfileData = tAction.updateAccountProfile(accountProfileData);
+ results = "Account profile update successful";
+ }
+
+ }
+ 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 + "invalid argument, check userID is correct, and the database is populated" + userID);
+ Log.error(
+ e,
+ "TradeServletAction.doAccount(...)",
+ "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 with error page
+ throw new ServletException("TradeServletAction.doAccountUpdate(...)"
+ + " exception user ="
+ + userID,
+ e);
+ }
+ doAccount(ctx, req, resp, userID, results);
+ }
+
+/**
+ * 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));
+}
+ /**
+ * 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);
+ }
+ 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));
+ }
+/**
+ * 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
+{
+
+ 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());
+ 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)
+ {
+ //log the exception with error page
+ throw new ServletException(
+ "TradeServletAction.doLogin(...)"
+ + "Exception logging in user "
+ + userID
+ + "with password"
+ + passwd
+ ,e);
+ }
+
+ requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.WELCOME_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));
+ }
+ /**
+ * 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);
+ }
+ }
+
+ /**
+ * 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));
+ }
+ /**
+ * 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);
+ }
+ }
+ /**
+ * 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));
+ }
+
+ 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));
+ }
+
+
+ private void requestDispatch(
+ ServletContext ctx,
+ HttpServletRequest req,
+ HttpServletResponse resp,
+ String userID,
+ String page)
+ throws ServletException, IOException {
+
+ ctx.getRequestDispatcher(page).include(req, resp);
+ }
+ private void sendRedirect(HttpServletResponse resp, String page)
+ throws ServletException, IOException {
+ resp.sendRedirect(resp.encodeRedirectURL(page));
+ }
+}
\ No newline at end of file
Propchange: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeServletAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeWebContextListener.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeWebContextListener.java?rev=293214&view=auto
==============================================================================
--- geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeWebContextListener.java (added)
+++ geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeWebContextListener.java Sun Oct 2 19:34:49 2005
@@ -0,0 +1,44 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.samples.daytrader.web;
+
+import javax.servlet.*;
+
+import org.apache.geronimo.samples.daytrader.direct.*;
+import org.apache.geronimo.samples.daytrader.util.*;
+
+public class TradeWebContextListener
+ implements ServletContextListener
+{
+
+ //receieve trade web app startup/shutown events to start(initialized)/stop TradeDirect
+ public void contextInitialized(ServletContextEvent event)
+ {
+ Log.trace("TradeWebContextListener contextInitialized -- initializing TradeDirect");
+ TradeDirect.init();
+ }
+ public void contextDestroyed(ServletContextEvent event)
+ {
+ Log.trace("TradeWebContextListener contextDestroy calling TradeDirect:destroy()");
+ TradeDirect.destroy();
+ }
+
+
+
+}
+
Propchange: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/TradeWebContextListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingBean.java?rev=293214&view=auto
==============================================================================
--- geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingBean.java (added)
+++ geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingBean.java Sun Oct 2 19:34:49 2005
@@ -0,0 +1,46 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.samples.daytrader.web.prims;
+
+ /**
+ *
+ * Simple bean to get and set messages
+ */
+
+
+public class PingBean {
+
+ private String msg;
+
+/**
+ * returns the message contained in the bean
+ * @return message String
+ **/
+public String getMsg()
+{
+ return msg;
+}
+/**
+* sets the message contained in the bean
+* param message String
+**/
+public void setMsg(String s)
+{
+ msg = s;
+}
+}
\ No newline at end of file
Propchange: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingJDBCRead.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingJDBCRead.java?rev=293214&view=auto
==============================================================================
--- geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingJDBCRead.java (added)
+++ geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingJDBCRead.java Sun Oct 2 19:34:49 2005
@@ -0,0 +1,119 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.samples.daytrader.web.prims;
+
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import org.apache.geronimo.samples.daytrader.direct.*;
+import org.apache.geronimo.samples.daytrader.util.*;
+
+import org.apache.geronimo.samples.daytrader.*;
+
+/**
+ *
+ * PingJDBCReadPrepStmt uses a prepared statement for database read access.
+ * This primative uses {@link org.apache.geronimo.samples.daytrader.direct.TradeDirect} to set the price of a random stock
+ * (generated by {@link org.apache.geronimo.samples.daytrader.Trade_Config}) through the use of prepared statements.
+ *
+ */
+
+public class PingJDBCRead extends HttpServlet
+{
+
+ private static String initTime;
+ private static int hitCount;
+
+ /**
+ * forwards post requests to the doGet method
+ * Creation date: (11/6/2000 10:52:39 AM)
+ * @param res javax.servlet.http.HttpServletRequest
+ * @param res2 javax.servlet.http.HttpServletResponse
+ */
+ public void doPost(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException
+ {
+ doGet(req, res);
+ }
+ /**
+ * this is the main method of the servlet that will service all get requests.
+ * @param request HttpServletRequest
+ * @param responce HttpServletResponce
+ **/
+ public void doGet(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException
+ {
+ res.setContentType("text/html");
+ java.io.PrintWriter out = res.getWriter();
+ String symbol=null;
+ StringBuffer output = new StringBuffer(100);
+
+ try
+ {
+ //TradeJDBC uses prepared statements so I am going to make use of it's code.
+ TradeDirect trade = new TradeDirect();
+ symbol = TradeConfig.rndSymbol();
+
+ QuoteDataBean quoteData = null;
+ int iter = TradeConfig.getPrimIterations();
+ for (int ii = 0; ii < iter; ii++) {
+ quoteData = trade.getQuote(symbol);
+ }
+
+ output.append(
+ "<html><head><title>Ping JDBC Read w/ Prepared Stmt.</title></head>"
+ + "<body><HR><FONT size=\"+2\" color=\"#000066\">Ping JDBC Read w/ Prep Stmt:</FONT><HR><FONT size=\"-1\" color=\"#000066\">Init time : "
+ + initTime);
+ hitCount++;
+ output.append("<BR>Hit Count: " + hitCount);
+ output.append(
+ "<HR>Quote Information <BR><BR>: "
+ + quoteData.toHTML());
+ output.append("<HR></body></html>");
+ out.println(output.toString());
+ }
+ catch (Exception e)
+ {
+ Log.error(
+ e,
+ "PingJDBCRead w/ Prep Stmt -- error getting quote for symbol",
+ symbol);
+ res.sendError(500, "PingJDBCRead Exception caught: " + e.toString());
+ }
+
+ }
+ /**
+ * returns a string of information about the servlet
+ * @return info String: contains info about the servlet
+ **/
+ public String getServletInfo()
+ {
+ return "Basic JDBC Read using a prepared statment, makes use of TradeJDBC class";
+ }
+ /**
+ * called when the class is loaded to initialize the servlet
+ * @param config ServletConfig:
+ **/
+ public void init(ServletConfig config) throws ServletException
+ {
+ super.init(config);
+ hitCount = 0;
+ initTime = new java.util.Date().toString();
+ }
+}
\ No newline at end of file
Propchange: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingJDBCRead.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingJDBCWrite.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingJDBCWrite.java?rev=293214&view=auto
==============================================================================
--- geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingJDBCWrite.java (added)
+++ geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingJDBCWrite.java Sun Oct 2 19:34:49 2005
@@ -0,0 +1,119 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.samples.daytrader.web.prims;
+
+import java.io.*;
+import java.math.BigDecimal;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import org.apache.geronimo.samples.daytrader.direct.*;
+import org.apache.geronimo.samples.daytrader.util.*;
+
+import org.apache.geronimo.samples.daytrader.*;
+/**
+ *
+ * PingJDBCReadPrepStmt uses a prepared statement
+ * for database update. Statement parameters are set dynamically on each request.
+ * This primative uses {@link org.apache.geronimo.samples.daytrader.direct.TradeDirect} to set the price of a random stock
+ * (generated by {@link org.apache.geronimo.samples.daytrader.Trade_Config}) through the use of prepared statements.
+ *
+ */
+
+public class PingJDBCWrite extends HttpServlet {
+
+ private static String initTime;
+ private static int hitCount;
+
+
+/**
+* this is the main method of the servlet that will service all get requests.
+* @param request HttpServletRequest
+* @param responce HttpServletResponce
+**/
+public void doGet(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException {
+
+ String symbol = null;
+ BigDecimal newPrice;
+ StringBuffer output = new StringBuffer(100);
+ res.setContentType("text/html");
+ java.io.PrintWriter out = res.getWriter();
+
+ try
+ {
+ //get a random symbol to update and a random price.
+ symbol = TradeConfig.rndSymbol();
+ newPrice = TradeConfig.getRandomPriceChangeFactor();
+
+ //TradeJDBC makes use of prepared statements so I am going to reuse the existing code.
+ TradeDirect trade = new TradeDirect();
+
+ //update the price of our symbol
+ QuoteDataBean quoteData = null;
+ int iter = TradeConfig.getPrimIterations();
+ for (int ii = 0; ii < iter; ii++) {
+ quoteData = trade.updateQuotePriceVolumeInt(symbol, newPrice, 100.0, false);
+ }
+
+ //write the output
+ output.append(
+ "<html><head><title>Ping JDBC Write w/ Prepared Stmt.</title></head>"
+ + "<body><HR><FONT size=\"+2\" color=\"#000066\">Ping JDBC Write w/ Prep Stmt:</FONT><FONT size=\"-1\" color=\"#000066\"><HR>Init time : "
+ + initTime);
+ hitCount++;
+ output.append("<BR>Hit Count: " + hitCount);
+ output.append("<HR>Update Information<BR>");
+ output.append("<BR>" + quoteData.toHTML() + "<HR></FONT></BODY></HTML>");
+ out.println(output.toString());
+
+ }
+ catch (Exception e)
+ {
+ Log.error(e, "PingJDBCWrite -- error updating quote for symbol", symbol);
+ res.sendError(500, "PingJDBCWrite Exception caught: " + e.toString());
+ }
+}
+/**
+ * returns a string of information about the servlet
+ * @return info String: contains info about the servlet
+ **/
+public String getServletInfo()
+{
+ return "Basic JDBC Write using a prepared statment makes use of TradeJDBC code.";
+}
+/**
+* called when the class is loaded to initialize the servlet
+* @param config ServletConfig:
+**/
+public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ initTime = new java.util.Date().toString();
+ hitCount = 0;
+
+}
+/**
+ * forwards post requests to the doGet method
+ * Creation date: (11/6/2000 10:52:39 AM)
+ * @param res javax.servlet.http.HttpServletRequest
+ * @param res2 javax.servlet.http.HttpServletResponse
+ */
+public void doPost(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException {
+ doGet(req, res);
+}}
Propchange: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingJDBCWrite.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet.java?rev=293214&view=auto
==============================================================================
--- geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet.java (added)
+++ geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet.java Sun Oct 2 19:34:49 2005
@@ -0,0 +1,101 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.samples.daytrader.web.prims;
+
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import org.apache.geronimo.samples.daytrader.util.*;
+
+
+/**
+ *
+ * PingServlet tests fundamental dynamic HTML creation functionality through
+ * server side servlet processing.
+ *
+ */
+public class PingServlet extends HttpServlet
+{
+
+ private static String initTime;
+ private static int hitCount;
+
+ /**
+ * forwards post requests to the doGet method
+ * Creation date: (11/6/2000 10:52:39 AM)
+ * @param res javax.servlet.http.HttpServletRequest
+ * @param res2 javax.servlet.http.HttpServletResponse
+ */
+ public void doPost(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException
+ {
+ doGet(req, res);
+ }
+ /**
+ * this is the main method of the servlet that will service all get requests.
+ * @param request HttpServletRequest
+ * @param responce HttpServletResponce
+ **/
+ public void doGet(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException
+ {
+ try
+ {
+ res.setContentType("text/html");
+
+ // The following 2 lines are the difference between PingServlet and PingServletWriter
+ // the latter uses a PrintWriter for output versus a binary output stream.
+ ServletOutputStream out = res.getOutputStream();
+ //java.io.PrintWriter out = res.getWriter();
+ hitCount++;
+ out.println(
+ "<html><head><title>Ping Servlet</title></head>"
+ + "<body><HR><BR><FONT size=\"+2\" color=\"#000066\">Ping Servlet<BR></FONT><FONT size=\"+1\" color=\"#000066\">Init time : "
+ + initTime
+ + "<BR><BR></FONT> <B>Hit Count: "
+ + hitCount
+ + "</B></body></html>");
+ }
+ catch (Exception e)
+ {
+ Log.error(e, "PingServlet.doGet(...): general exception caught");
+ res.sendError(500, e.toString());
+
+ }
+ }
+ /**
+ * returns a string of information about the servlet
+ * @return info String: contains info about the servlet
+ **/
+ public String getServletInfo()
+ {
+ return "Basic dynamic HTML generation through a servlet";
+ }
+ /**
+ * called when the class is loaded to initialize the servlet
+ * @param config ServletConfig:
+ **/
+ public void init(ServletConfig config) throws ServletException
+ {
+ super.init(config);
+ initTime = new java.util.Date().toString();
+ hitCount = 0;
+
+ }
+}
\ No newline at end of file
Propchange: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2EntityLocal.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2EntityLocal.java?rev=293214&view=auto
==============================================================================
--- geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2EntityLocal.java (added)
+++ geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2EntityLocal.java Sun Oct 2 19:34:49 2005
@@ -0,0 +1,173 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.samples.daytrader.web.prims;
+
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import javax.naming.*;
+
+import org.apache.geronimo.samples.daytrader.ejb.*;
+import org.apache.geronimo.samples.daytrader.util.*;
+
+import org.apache.geronimo.samples.daytrader.*;
+
+/**
+ *
+ * Primitive designed to run within the TradeApplication and makes use of {@link trade_client.TradeConfig}
+ * for config parameters and random stock symbols.
+ * Servlet will generate a random stock symbol and get the price of that symbol using a {@link trade.Quote} Entity EJB
+ * This tests the common path of a Servlet calling an Entity EJB to get data
+ *
+ */
+
+public class PingServlet2EntityLocal extends HttpServlet
+{
+ private static String initTime;
+ private static int hitCount;
+ private static LocalQuoteHome quoteHome;
+
+ /**
+ * forwards post requests to the doGet method
+ * Creation date: (11/6/2000 10:52:39 AM)
+ * @param res javax.servlet.http.HttpServletRequest
+ * @param res2 javax.servlet.http.HttpServletResponse
+ */
+ public void doPost(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException
+ {
+ doGet(req, res);
+ }
+
+ /**
+ * this is the main method of the servlet that will service all get requests.
+ * @param request HttpServletRequest
+ * @param responce HttpServletResponce
+ **/
+ public void doGet(HttpServletRequest req, HttpServletResponse res)
+ throws IOException, ServletException
+ {
+
+ res.setContentType("text/html");
+ java.io.PrintWriter out = res.getWriter();
+
+ LocalQuote quote = null;
+ String symbol = null;
+
+ StringBuffer output = new StringBuffer(100);
+ output.append(
+ "<html><head><title>Servlet2EntityLocal</title></head>"
+ + "<body><HR><FONT size=\"+2\" color=\"#000066\">PingServlet2EntityLocal<BR></FONT>"
+ + "<FONT size=\"-1\" color=\"#000066\"><BR>PingServlet2Entity performs a JNDI lookup"
+ + " on the Local QuoteBean Home and then gets the price of a random symbol (generated by TradeConfig)"
+ + " through the Local interface");
+ try
+ {
+ //this is just a large general catch block.
+
+ //it is important only to look up the home once.
+ if (quoteHome == null)
+ {
+ //make sure that only one thread looks up the home
+ synchronized (lock)
+ {
+ if (quoteHome == null)
+ {
+ output.append(
+ "<HR>Performing JNDI lookup and creating reference to QuoteHome</B>");
+ try
+ {
+ //do not pass an environment so that it uses the system env.
+ InitialContext ic = new InitialContext();
+ //lookup and narrow (cast) the reference to the ejbHome.
+ quoteHome = (LocalQuoteHome) ic.lookup("java:comp/env/ejb/LocalQuote");
+ }
+ catch (Exception ne)
+ {
+ //wrap and throw the exception for handling
+ Log.error(ne,"web_primtv.PingServlet2Entity.doGet(...): error looking up LocalQuoteHome");
+ throw ne;
+ }
+ }
+ }
+ }
+
+ //generate random symbol
+ try {
+ int iter = TradeConfig.getPrimIterations();
+ for (int ii = 0; ii < iter; ii++) {
+ //get a random symbol to look up and get the key to that symbol.
+ symbol = TradeConfig.rndSymbol();
+ //find the EntityInstance.
+ quote = quoteHome.findByPrimaryKey(symbol);
+ }
+ }
+ catch (Exception e)
+ {
+ Log.error("web_primtv.PingServlet2Entity.doGet(...): error performing findByPrimaryKey");
+ throw e;
+ }
+ //get the price and print the output.
+ QuoteDataBean quoteData = quote.getDataBean();
+
+ output.append("<HR>initTime: " + initTime + "<BR>Hit Count: ").append(
+ hitCount++);
+ output
+ .append("<HR>Quote Information<BR><BR> " + quoteData.toHTML());
+ output.append("</font><HR></body></html>");
+ out.println(output.toString());
+ }
+ catch (Exception e)
+ {
+ Log.error(e,"PingServlet2Entity.doGet(...): error");
+ //this will send an Error to teh web applications defined error page.
+ res.sendError(
+ 500,
+ "PingServlet2Entity.doGet(...): error"
+ + e.toString());
+
+ }
+ }
+
+ /**
+ * returns a string of information about the servlet
+ * @return info String: contains info about the servlet
+ **/
+
+ public String getServletInfo()
+ {
+ return "web primitive, tests Servlet to Entity EJB path";
+ }
+
+ /**
+ * called when the class is loaded to initialize the servlet
+ * @param config ServletConfig:
+ **/
+ public void init(ServletConfig config) throws ServletException
+ {
+ super.init(config);
+ hitCount = 0;
+ initTime = new java.util.Date().toString();
+ //set this to null, this will be initialized in the doGet method.
+ quoteHome = null;
+ //this lock is used to synchronize initialization of the EJBHome
+ lock = new Integer(99);
+
+ }
+ private java.lang.Integer lock;
+}
\ No newline at end of file
Propchange: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2EntityLocal.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2EntityRemote.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2EntityRemote.java?rev=293214&view=auto
==============================================================================
--- geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2EntityRemote.java (added)
+++ geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2EntityRemote.java Sun Oct 2 19:34:49 2005
@@ -0,0 +1,176 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.samples.daytrader.web.prims;
+
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import javax.naming.*;
+import javax.rmi.PortableRemoteObject;
+
+import org.apache.geronimo.samples.daytrader.ejb.*;
+import org.apache.geronimo.samples.daytrader.util.*;
+
+import org.apache.geronimo.samples.daytrader.*;
+
+/**
+ *
+ * Primitive designed to run within the TradeApplication and makes use of {@link trade_client.TradeConfig}
+ * for config parameters and random stock symbols.
+ * Servlet will generate a random stock symbol and get the price of that symbol using a {@link trade.Quote} Entity EJB
+ * This tests the common path of a Servlet calling an Entity EJB to get data
+ * In this servlet the call is made the through the Quote EJBs Remote Interface
+ *
+ */
+
+public class PingServlet2EntityRemote extends HttpServlet
+{
+ private static String initTime;
+ private static int hitCount;
+ private static QuoteHome quoteHome;
+
+ /**
+ * forwards post requests to the doGet method
+ * Creation date: (11/6/2000 10:52:39 AM)
+ * @param res javax.servlet.http.HttpServletRequest
+ * @param res2 javax.servlet.http.HttpServletResponse
+ */
+ public void doPost(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException
+ {
+ doGet(req, res);
+ }
+
+ /**
+ * this is the main method of the servlet that will service all get requests.
+ * @param request HttpServletRequest
+ * @param responce HttpServletResponce
+ **/
+ public void doGet(HttpServletRequest req, HttpServletResponse res)
+ throws IOException, ServletException
+ {
+
+ res.setContentType("text/html");
+ java.io.PrintWriter out = res.getWriter();
+
+ Quote quote = null;
+ String symbol = null;
+
+ StringBuffer output = new StringBuffer(100);
+ output.append(
+ "<html><head><title>Servlet2EntityRemote</title></head>"
+ + "<body><HR><FONT size=\"+2\" color=\"#000066\">PingServlet2EntityRemote<BR></FONT>"
+ + "<FONT size=\"-1\" color=\"#000066\"><BR>PingServlet2EntityRemote performs a JNDI lookup"
+ + " on the QuoteBean Remote Home and then gets the price of a random symbol (generated by TradeConfig)"
+ + " through the Remote Interface");
+ try
+ {
+ //this is just a large general catch block.
+
+ //it is important only to look up the home once.
+ if (quoteHome == null)
+ {
+ //make sure that only one thread looks up the home
+ synchronized (lock)
+ {
+ if (quoteHome == null)
+ {
+ output.append(
+ "<HR>Performing JNDI lookup and creating reference to QuoteHome</B>");
+ try
+ {
+ //do not pass an environment so that it uses the system env.
+ InitialContext ic = new InitialContext();
+ //lookup and narrow (cast) the reference to the ejbHome.
+ quoteHome = (QuoteHome) PortableRemoteObject.narrow(
+ ic.lookup("java:comp/env/ejb/Quote"),
+ QuoteHome.class);
+ }
+ catch (Exception ne)
+ {
+ //wrap and throw the exception for handling
+ Log.error(ne,"web_primtv.PingServlet2Entity.doGet(...): error looking up QuoteHome");
+ throw ne;
+ }
+ }
+ }
+ }
+ //generate random symbol
+ try {
+ int iter = TradeConfig.getPrimIterations();
+ for (int ii = 0; ii < iter; ii++) {
+ //get a random symbol to look up and get the key to that symbol.
+ symbol = TradeConfig.rndSymbol();
+ //find the EntityInstance.
+ quote = quoteHome.findByPrimaryKey(symbol);
+ }
+ }
+ catch (Exception e)
+ {
+ Log.error("web_primtv.PingServlet2Entity.doGet(...): error performing findByPrimaryKey");
+ throw e;
+ }
+ //get the price and print the output.
+ QuoteDataBean quoteData = quote.getDataBean();
+
+ output.append("<HR>initTime: " + initTime + "<BR>Hit Count: ").append(
+ hitCount++);
+ output
+ .append("<HR>Quote Information<BR><BR> " + quoteData.toHTML());
+ output.append("</font><HR></body></html>");
+ out.println(output.toString());
+ }
+ catch (Exception e)
+ {
+ Log.error(e,"PingServlet2Entity.doGet(...): error");
+ //this will send an Error to teh web applications defined error page.
+ res.sendError(
+ 500,
+ "PingServlet2Entity.doGet(...): error"
+ + e.toString());
+
+ }
+ }
+
+ /**
+ * returns a string of information about the servlet
+ * @return info String: contains info about the servlet
+ **/
+
+ public String getServletInfo()
+ {
+ return "web primitive, tests Servlet to Entity EJB path";
+ }
+
+ /**
+ * called when the class is loaded to initialize the servlet
+ * @param config ServletConfig:
+ **/
+ public void init(ServletConfig config) throws ServletException
+ {
+ super.init(config);
+ hitCount = 0;
+ initTime = new java.util.Date().toString();
+ //set this to null, this will be initialized in the doGet method.
+ quoteHome = null;
+ //this lock is used to synchronize initialization of the EJBHome
+ lock = new Integer(99);
+
+ }
+ private java.lang.Integer lock;
+}
\ No newline at end of file
Propchange: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2EntityRemote.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2Include.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2Include.java?rev=293214&view=auto
==============================================================================
--- geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2Include.java (added)
+++ geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2Include.java Sun Oct 2 19:34:49 2005
@@ -0,0 +1,92 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.samples.daytrader.web.prims;
+
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import org.apache.geronimo.samples.daytrader.util.*;
+
+import org.apache.geronimo.samples.daytrader.*;
+
+/**
+ *
+ * PingServlet2Include tests servlet to servlet request dispatching. Servlet 1,
+ * the controller, creates a new JavaBean object forwards the servlet request with
+ * the JavaBean added to Servlet 2. Servlet 2 obtains access to the JavaBean through
+ * the Servlet request object and provides the dynamic HTML output based on the JavaBean
+ * data.
+ * PingServlet2Servlet is the initial servlet that sends a request to {@link PingServlet2ServletRcv}
+ *
+ */
+public class PingServlet2Include extends HttpServlet {
+
+ private static String initTime;
+ private static int hitCount;
+
+ /**
+ * forwards post requests to the doGet method
+ * Creation date: (11/6/2000 10:52:39 AM)
+ * @param res javax.servlet.http.HttpServletRequest
+ * @param res2 javax.servlet.http.HttpServletResponse
+ */
+ public void doPost(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException {
+ doGet(req, res);
+ }
+ /**
+ * this is the main method of the servlet that will service all get requests.
+ * @param request HttpServletRequest
+ * @param responce HttpServletResponce
+ **/
+ public void doGet(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException {
+ PingBean ab;
+ try {
+ res.setContentType("text/html");
+
+ int iter = TradeConfig.getPrimIterations();
+ for (int ii = 0; ii < iter; ii++) {
+ getServletConfig().getServletContext().getRequestDispatcher("/servlet/PingServlet2IncludeRcv").include(req, res);
+ }
+
+ ServletOutputStream out = res.getOutputStream();
+ out.println(
+ "<html><head><title>Ping Servlet 2 Include</title></head>"
+ + "<body><HR><BR><FONT size=\"+2\" color=\"#000066\">Ping Servlet 2 Include<BR></FONT><FONT size=\"+1\" color=\"#000066\">Init time : "
+ + initTime
+ + "<BR><BR></FONT> <B>Hit Count: "
+ + hitCount++
+ + "</B></body></html>");
+ } catch (Exception ex) {
+ Log.error(ex, "PingServlet2Include.doGet(...): general exception");
+ res.sendError(500, "PingServlet2Include.doGet(...): general exception" + ex.toString());
+ }
+ }
+
+ /**
+ * called when the class is loaded to initialize the servlet
+ * @param config ServletConfig:
+ **/
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ initTime = new java.util.Date().toString();
+ hitCount = 0;
+ }
+}
\ No newline at end of file
Propchange: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2Include.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2IncludeRcv.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2IncludeRcv.java?rev=293214&view=auto
==============================================================================
--- geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2IncludeRcv.java (added)
+++ geronimo/trunk/sandbox/daytrader/modules/web/src/webapp/WEB-INF/classes/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2IncludeRcv.java Sun Oct 2 19:34:49 2005
@@ -0,0 +1,55 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.samples.daytrader.web.prims;
+
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+/**
+ *
+ * PingServlet2Include tests servlet to servlet request dispatching. Servlet 1,
+ * the controller, creates a new JavaBean object forwards the servlet request with
+ * the JavaBean added to Servlet 2. Servlet 2 obtains access to the JavaBean through
+ * the Servlet request object and provides the dynamic HTML output based on the JavaBean
+ * data.
+ * PingServlet2Servlet is the initial servlet that sends a request to {@link PingServlet2ServletRcv}
+ *
+ */
+public class PingServlet2IncludeRcv extends HttpServlet {
+
+ /**
+ * forwards post requests to the doGet method
+ * Creation date: (11/6/2000 10:52:39 AM)
+ * @param res javax.servlet.http.HttpServletRequest
+ * @param res2 javax.servlet.http.HttpServletResponse
+ */
+ public void doPost(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException {
+ doGet(req, res);
+ }
+ /**
+ * this is the main method of the servlet that will service all get requests.
+ * @param request HttpServletRequest
+ * @param responce HttpServletResponce
+ **/
+ public void doGet(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException {
+ // do nothing but get included by PingServlet2Include
+ }
+}
\ No newline at end of file