001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.bench.servlet;
023:
024: import java.util.Hashtable;
025: import java.util.Enumeration;
026:
027: import javax.servlet.ServletException;
028:
029: import javax.servlet.http.HttpServlet;
030: import javax.servlet.http.HttpServletRequest;
031: import javax.servlet.http.HttpServletResponse;
032: import javax.servlet.http.HttpSession;
033:
034: public class Dispatcher extends HttpServlet {
035:
036: static org.apache.log4j.Category log = org.apache.log4j.Category
037: .getInstance(Dispatcher.class);
038:
039: public static String[] params = { "hw", "os", "ram", "cpu", "jdk",
040: "ejb", "web", "servlet" };
041:
042: protected void doGet(HttpServletRequest req,
043: HttpServletResponse resp) throws ServletException,
044: java.io.IOException {
045: try {
046:
047: resp.setHeader("Location", req.getContextPath() + "/");
048:
049: if (req.getParameter("gototest") != null)
050: // save config and go to tests
051: saveInfo(req, resp);
052:
053: else if (req.getParameter("goejb") != null)
054: // test ejb
055: testEjb(req, resp);
056:
057: else if (req.getParameter("goall") != null)
058: // test the whole stack
059: testAll(req, resp);
060:
061: else
062: // should not get there, go back to the main page
063: req.getRequestDispatcher("/index.jsp").include(req,
064: resp);
065: } catch (Throwable t) {
066: log.debug("failed", t);
067: }
068:
069: }
070:
071: /**
072: * Saves the info from the request in the session object
073: */
074: void saveInfo(HttpServletRequest req, HttpServletResponse resp)
075: throws ServletException, java.io.IOException {
076:
077: HttpSession session = req.getSession();
078: ConfigData conf = (ConfigData) session.getAttribute("conf");
079:
080: for (int i = 0; i < conf.size(); i++) {
081: conf.setInfo(conf.getName(i), req.getParameter(conf
082: .getName(i)));
083: }
084:
085: req.getRequestDispatcher("/tests.jsp").include(req, resp);
086:
087: }
088:
089: void testEjb(HttpServletRequest req, HttpServletResponse resp)
090: throws ServletException, java.io.IOException {
091:
092: EJBTester ejbTester = new EJBTester(req);
093:
094: // do the test
095: ejbTester.test();
096:
097: req.setAttribute("ejbTester", ejbTester);
098:
099: // finally include to the correct jsp page
100:
101: req.getRequestDispatcher("/ejbResult.jsp").include(req, resp);
102:
103: }
104:
105: void testAll(HttpServletRequest req, HttpServletResponse resp)
106: throws ServletException, java.io.IOException {
107:
108: FullTester fullTester = new FullTester(req);
109:
110: // do the test
111: fullTester.test();
112:
113: req.setAttribute("fullTester", fullTester);
114:
115: // finally include to the correct jsp page
116: req.getRequestDispatcher("/allResult.jsp").include(req, resp);
117:
118: }
119:
120: }
|