KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > bench > servlet > Dispatcher


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.bench.servlet;
23
24 import java.util.Hashtable JavaDoc;
25 import java.util.Enumeration JavaDoc;
26
27 import javax.servlet.ServletException JavaDoc;
28
29 import javax.servlet.http.HttpServlet JavaDoc;
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32 import javax.servlet.http.HttpSession JavaDoc;
33
34 public class Dispatcher extends HttpServlet JavaDoc {
35
36        static org.jboss.logging.Logger log =
37        org.jboss.logging.Logger.getLogger(Dispatcher.class);
38
39     public static String JavaDoc[] params = {"hw", "os", "ram", "cpu", "jdk", "ejb", "web", "servlet" };
40
41     protected void doGet(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp)
42         throws ServletException JavaDoc, java.io.IOException JavaDoc {
43         try {
44
45         resp.setHeader("Location", req.getContextPath() + "/");
46
47         if (req.getParameter("gototest") != null)
48             // save config and go to tests
49
saveInfo(req, resp);
50         
51         else if (req.getParameter("goejb") != null)
52             // test ejb
53
testEjb(req, resp);
54
55         else if (req.getParameter("goall") != null)
56             // test the whole stack
57
testAll(req, resp);
58         
59         else
60             // should not get there, go back to the main page
61
req.getRequestDispatcher("/index.jsp").include(req, resp);
62         } catch (Throwable JavaDoc t) {
63             log.debug("failed", t);
64         }
65
66     }
67
68     /**
69      * Saves the info from the request in the session object
70      */

71     void saveInfo(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp)
72         throws ServletException JavaDoc, java.io.IOException JavaDoc {
73         
74         HttpSession JavaDoc session = req.getSession();
75         ConfigData conf = (ConfigData)session.getAttribute("conf");
76
77         for (int i=0; i<conf.size(); i++) {
78             conf.setInfo(conf.getName(i), req.getParameter(conf.getName(i)));
79         }
80         
81         req.getRequestDispatcher("/tests.jsp").include(req, resp);
82         
83     }
84     
85     void testEjb(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp)
86         throws ServletException JavaDoc, java.io.IOException JavaDoc {
87
88         EJBTester ejbTester = new EJBTester(req);
89         
90         // do the test
91
ejbTester.test();
92         
93         req.setAttribute("ejbTester", ejbTester);
94
95         // finally include to the correct jsp page
96

97         req.getRequestDispatcher("/ejbResult.jsp").include(req, resp);
98         
99     }
100
101     void testAll(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp)
102         throws ServletException JavaDoc, java.io.IOException JavaDoc {
103
104         FullTester fullTester = new FullTester(req);
105         
106         // do the test
107
fullTester.test();
108         
109         req.setAttribute("fullTester", fullTester);
110
111         // finally include to the correct jsp page
112
req.getRequestDispatcher("/allResult.jsp").include(req, resp);
113
114     }
115
116 }
117
118
119
Popular Tags