/* * File : AbstractServlet.java * Created : 23-jan-2003 12:03 * By : fbusquets * * JClic - Authoring and playing system for educational activities * * Copyright (C) 2000 - 2005 Francesc Busquets & Departament * d'Educacio de la Generalitat de Catalunya * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details (see the LICENSE file). */ package edu.xtec.servlet; import javax.servlet.http.*; import javax.servlet.*; import java.util.Vector; import java.util.Iterator; import java.util.Enumeration; import java.util.HashMap; /** * * @author Francesc Busquets (fbusquets@xtec.net) */ public abstract class AbstractServlet extends HttpServlet { public AbstractServlet(){ super(); RequestProcessor.setDirectResources(true); } public void init(ServletConfig config) throws ServletException { super.init(config); Enumeration en=config.getInitParameterNames(); if(en.hasMoreElements()){ HashMap map=new HashMap(); while(en.hasMoreElements()){ String key=(String)en.nextElement(); String value=(String)config.getInitParameter(key); } RequestProcessor.config(map); } } protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { RequestProcessor rp=null; try{ rp=createRP(); if(rp.wantsInputStream()) rp.setInputStream(request.getInputStream()); else rp.setParams(request.getParameterMap()); Cookie[] ck=request.getCookies(); if(ck!=null) for(int i=0; i=0 ? rp.errCode : HttpServletResponse.SC_INTERNAL_SERVER_ERROR; String errMsg = rp.errMsg!=null ? rp.errMsg : ex.getMessage(); if(!response.isCommitted()){ response.sendError(errCode, errMsg); } System.err.println("ERROR "+errCode+": "+errMsg); ex.printStackTrace(System.err); } finally { if(rp!=null) rp.end(); } } protected abstract RequestProcessor createRP() throws Exception; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { processRequest(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { processRequest(request, response); } }