X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fservlet%2FServletModuleDispatch.java;h=1c58dd9984e643f86447f881cec2775be719b9da;hb=1bfd964b53be329b60b4ddc3a8fec43fcfa9da88;hp=8490f10ccdbd48274434160e93476dd874b6a7a0;hpb=84b43b6a792e625a3dc8fcc1c80bb601a9a2422b;p=mir.git diff --git a/source/mir/servlet/ServletModuleDispatch.java b/source/mir/servlet/ServletModuleDispatch.java index 8490f10c..1c58dd99 100755 --- a/source/mir/servlet/ServletModuleDispatch.java +++ b/source/mir/servlet/ServletModuleDispatch.java @@ -1,75 +1,118 @@ /* - * Dispatcher + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir 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. + * + * Mir 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. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with the com.oreilly.servlet library, any library + * licensed under the Apache Software License, The Sun (tm) Java Advanced + * Imaging library (JAI), The Sun JIMI library (or with modified versions of + * the above that use the same license as the above), and distribute linked + * combinations including the two. You must obey the GNU General Public + * License in all respects for all of the code used other than the above + * mentioned libraries. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If you do + * not wish to do so, delete this exception statement from your version. */ package mir.servlet; -import java.lang.reflect.*; -import javax.servlet.http.*; -import mir.servlet.ServletModuleException; -import mir.misc.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import mir.log.LoggerWrapper; /** - * Dispatcher, der in einer ServletModule-Klasse, die Methode, die per Http-Post oder Get - * Parameter "do" angegeben wurde, ausruft. + * Dispatcher, calls the method passed to ServletModule Class, through the "do" + * Parameter (via POST or GET) + * + * @version $Id: ServletModuleDispatch.java,v 1.13 2003/03/06 05:40:39 zapata Exp $ + * + * @Author rk + * */ public final class ServletModuleDispatch { - static Logfile theLog; - - static { - theLog = Logfile.getInstance("/tmp/smod.dispatch"); - } + private static LoggerWrapper logger = new LoggerWrapper("ServletModule.Dispatch"); + private static final Class[] SIGNATURE = { HttpServletRequest.class, HttpServletResponse.class }; - /** - * privater Konstruktor, um versehentliche Instantiierung zu verhindern - */ - private ServletModuleDispatch () { - } + /** + * private constructor to prevent unwanted instantiation; + */ - /** - * Die Dispatch-Routine ruft das von dem Hauptservlet kommende ServletModule - * mit dem per HttpServletRequest angegebenen Paramter do auf. - * Ist kein Parameter angegeben, so wird versucht, in die defaultAction - * des ServletModules zu springen. - * - * @param req Http-Request, das vom Dispatcher an die Methode des - * ServletModules durchgereicht wird - * @param res Http-Response, die vom Dispatcher an die Methode des - * ServletModules durchgereicht wird - * @param sMod ServletModule, an das dispatched wird. - * @param mod Name des Modules als String (für Logfile) - */ + private ServletModuleDispatch () { + } - public static void dispatch(ServletModule sMod, HttpServletRequest req, - HttpServletResponse res) throws ServletModuleException - { - //sMod.predeliver(req,res); + /** + * Die Dispatch-Routine ruft das von dem Hauptservlet kommende ServletModule + * mit dem per HttpServletRequest angegebenen Paramter do auf. + * Ist kein Parameter angegeben, so wird versucht, in die defaultAction + * des ServletModules zu springen. + * + * @param req Http-Request, das vom Dispatcher an die Methode des + * ServletModules durchgereicht wird + * @param res Http-Response, die vom Dispatcher an die Methode des + * ServletModules durchgereicht wird + * @param sMod ServletModule, an das dispatched wird. + * @param mod Name des Modules als String (f?r Logfile) + */ - String doParam = req.getParameter("do"); - theLog.printInfo("SerletModuleDispatch: " + sMod.toString() + " with method " + doParam); - if (doParam == null) { - if (sMod.defaultAction() != null) doParam = sMod.defaultAction(); - else throw new ServletModuleException("no parameter do supplied!"); - } + public static void dispatch(ServletModule sMod, HttpServletRequest req, + HttpServletResponse res) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure + { + //sMod.predeliver(req,res); - Class[] params= { HttpServletRequest.class, HttpServletResponse.class}; + String doParam = req.getParameter("do"); + logger.info("ServletModuleDispatch: " + sMod.toString() + " with method " + doParam); + if (doParam == null) { + if (sMod.defaultAction() != null) + doParam = sMod.defaultAction(); + else + throw new ServletModuleExc("no parameter do supplied!"); + } - try { - Method method = sMod.getClass().getMethod(doParam,params); - if (method != null) { - method.invoke(sMod,new Object[] {req,res} ); - return; - } - else theLog.printDebugInfo("method lookup unsuccesful"); - } - catch ( NoSuchMethodException e) { throw new ServletModuleException("no such method!" + e.toString());} - catch ( SecurityException e) { throw new ServletModuleException("method not allowed!" + e.toString());} - catch ( InvocationTargetException e) {throw new ServletModuleException("target method exception!" + e.getTargetException().toString());} - catch ( IllegalAccessException e) { throw new ServletModuleException("illegal method not allowed!" + e.toString());} -// catch ( Exception e ) { throw new ServletModuleException(e.toString()); } + try { + Method method = sMod.getClass().getMethod(doParam,SIGNATURE); + if (method != null) { + method.invoke(sMod,new Object[] {req,res} ); + return; + } + else logger.debug("method lookup unsuccesful"); + } + catch ( NoSuchMethodException e) { + throw new ServletModuleFailure("no such method '"+doParam+"' (" + e.getMessage() + ")", e); + } + catch ( SecurityException e) { + throw new ServletModuleFailure("method not allowed!" + e.getMessage(), e); + } + catch ( InvocationTargetException e) { + logger.debug( "invocation target exception: " + e.getMessage()); - throw new ServletModuleException("delivery failed! -- "); - } -} \ No newline at end of file + throw new ServletModuleFailure(e.getTargetException().getMessage(), e.getTargetException()); + } + catch ( IllegalAccessException e) { + throw new ServletModuleFailure("illegal method not allowed!" + e.getMessage(), e); + } + catch (Throwable t) { + throw new ServletModuleFailure(t); + } + } +}