001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.geronimo.samples.daytrader.web.prims;
018    
019    import java.io.*;
020    import javax.servlet.*;
021    import javax.servlet.http.*;
022    
023    import org.apache.geronimo.samples.daytrader.util.*;
024    
025    import org.apache.geronimo.samples.daytrader.*;
026    
027    /**
028     *
029     * PingServlet2Include tests servlet to servlet request dispatching. Servlet 1,
030     * the controller, creates a new JavaBean object forwards the servlet request with
031     * the JavaBean added to Servlet 2. Servlet 2 obtains access to the JavaBean through
032     * the Servlet request object and provides the dynamic HTML output based on the JavaBean
033     * data.
034     * PingServlet2Servlet is the initial servlet that sends a request to {@link PingServlet2ServletRcv}
035     *
036     */
037    public class PingServlet2Include extends HttpServlet {
038    
039            private static String initTime;
040            private static int hitCount;
041    
042            /**
043             * forwards post requests to the doGet method
044             * Creation date: (11/6/2000 10:52:39 AM)
045             * @param res javax.servlet.http.HttpServletRequest
046             * @param res2 javax.servlet.http.HttpServletResponse
047             */
048            public void doPost(HttpServletRequest req, HttpServletResponse res)
049                    throws ServletException, IOException {
050                    doGet(req, res);
051            }
052            /**
053            * this is the main method of the servlet that will service all get requests.
054            * @param request HttpServletRequest
055            * @param responce HttpServletResponce
056            **/
057            public void doGet(HttpServletRequest req, HttpServletResponse res)
058                    throws ServletException, IOException {
059                    PingBean ab;
060                    try {
061                            res.setContentType("text/html");
062                            
063                            int iter = TradeConfig.getPrimIterations();
064                            for (int ii = 0; ii < iter; ii++) {
065                                    getServletConfig().getServletContext().getRequestDispatcher("/servlet/PingServlet2IncludeRcv").include(req, res);
066                            }
067                            
068    //                      ServletOutputStream out = res.getOutputStream();
069                            java.io.PrintWriter out = res.getWriter();
070                            out.println(
071                                    "<html><head><title>Ping Servlet 2 Include</title></head>"
072                                            + "<body><HR><BR><FONT size=\"+2\" color=\"#000066\">Ping Servlet 2 Include<BR></FONT><FONT size=\"+1\" color=\"#000066\">Init time : "
073                                            + initTime
074                                            + "<BR><BR></FONT>  <B>Hit Count: "
075                                            + hitCount++
076                                            + "</B></body></html>");
077                    } catch (Exception ex) {
078                            Log.error(ex, "PingServlet2Include.doGet(...): general exception");
079                            res.sendError(500, "PingServlet2Include.doGet(...): general exception" + ex.toString());
080                    }
081            }
082            
083            /**
084            * called when the class is loaded to initialize the servlet
085            * @param config ServletConfig:
086            **/
087            public void init(ServletConfig config) throws ServletException {
088                    super.init(config);
089                    initTime = new java.util.Date().toString();
090                    hitCount = 0;
091            }
092    }