Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members

TestServletServlet.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  *  2005 Modification Romain Beaugrand
00027  * 
00028  */
00029 
00030 package org.openmobileis.embedded.webserver.test.services.servlet;
00031 
00032 import java.io.IOException;
00033 import java.io.PrintWriter;
00034 import java.util.Enumeration;
00035 
00036 import javax.servlet.ServletException;
00037 import javax.servlet.http.HttpServlet;
00038 import javax.servlet.http.HttpServletRequest;
00039 import javax.servlet.http.HttpServletResponse;
00040 
00041 import org.openmobileis.common.context.ApplicationContextManager;
00042 
00048 public class TestServletServlet extends HttpServlet {
00049     
00050     private ApplicationContextManager applicationContextManager;
00051 
00052     /*
00053      * Start service from GET method, same behavior as POST @param req the
00054      * servlet request @param req the servlet response @exception
00055      * ServletException when an exception has occurred
00056      */
00057     
00058     public TestServletServlet() {
00059     }
00060     
00061     public void init() throws ServletException {
00062     }
00063     
00064     public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
00065         this.processRequest(req, res);
00066     }
00067 
00078     public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
00079         this.processRequest(req, res);
00080     }
00081 
00082     private void processRequest(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
00083         res.setContentType("text/html");
00084         
00085         StringBuffer sb = new StringBuffer(200);
00086 /*        sb.append("<HTML>\n").append("<HEAD><TITLE>Test Servlet</TITLE></HEAD>\n")
00087                         .append("<BODY>\n").append("ServletName : "+this.getServletName())
00088                         .append("\n</BODY></HTML>\n\0");*/
00089         sb.append("<HTML>\n").append("<HEAD><TITLE>Test Servlet</TITLE></HEAD>\n")
00090                 .append("<BODY>\n")
00091                 .append("ServletInfo : "+this.getServletInfo())
00092                 .append("\n<br>\nServletName : "+this.getServletName())
00093                 .append("\n<br>\nMajor version : "+this.getServletContext().getMajorVersion())
00094                 .append("\n<br>\nMinor version : "+this.getServletContext().getMinorVersion())
00095         .append("\n<br>\nInit Parameters");
00096         
00097         Enumeration enum = this.getInitParameterNames();
00098         while (enum.hasMoreElements()) {
00099             String parameterName = (String)enum.nextElement();
00100             String parameterValue = this.getInitParameter(parameterName);
00101             sb.append("\n  <br>&nbsp;&nbsp;&nbsp;&nbsp;Name : "+parameterName);
00102             sb.append("\n  <br>&nbsp;&nbsp;&nbsp;&nbsp;Value : "+parameterValue);
00103         }
00104         
00105         sb.append("\n<br>\nAttributes");
00106         enum = this.getServletContext().getAttributeNames();
00107         while (enum.hasMoreElements()) {
00108             String attributeName = (String)enum.nextElement();
00109             String attributeValue = this.getInitParameter(attributeName);
00110             sb.append("\n  <br>&nbsp;&nbsp;&nbsp;&nbsp;Name : "+attributeName);
00111             sb.append("\n  <br>&nbsp;&nbsp;&nbsp;&nbsp;Value : "+attributeValue);
00112         }
00113         
00114                 sb.append("\n<br>\nServer info : "+this.getServletContext().getServerInfo())
00115                 .append("\n<br>\nServletContextName : "+this.getServletContext().getServletContextName())
00116                 .append("\n</BODY></HTML>\n");
00117         //res.setContentLength(sb.length());
00118         
00119         PrintWriter out = res.getWriter();
00120         //ServletOutputStream out = res.getOutputStream();
00121         
00122         out.print(sb.toString());
00123     }
00124 
00125 }

Generated on Thu Oct 6 10:06:34 2005 for OpenMobileIS by  doxygen 1.4.3