costin 00/12/31 17:58:39 Modified: src/share/org/apache/tomcat/startup EmbededTomcat.java Added: src/share/org/apache/tomcat/modules/config AutoSetup.java DefaultCMSetter.java LoaderInterceptor11.java LoaderInterceptor12.java PolicyInterceptor.java src/share/org/apache/tomcat/modules/generators ErrorHandler.java src/share/org/apache/tomcat/modules/loggers LogEvents.java Removed: src/share/org/apache/tomcat/context AutoSetup.java DefaultCMSetter.java ErrorHandler.java LoaderInterceptor11.java LoaderInterceptor12.java LogEvents.java PolicyInterceptor.java Log: Reorganized modules in tomcat.context, based on module type ( config, generators, loggers ) Revision Changes Path 1.1 jakarta-tomcat/src/share/org/apache/tomcat/modules/config/AutoSetup.java Index: AutoSetup.java =================================================================== /* * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.tomcat.context; import org.apache.tomcat.core.*; import org.apache.tomcat.util.*; import java.io.*; import java.net.*; import java.util.*; /** * Prepare a context manager - expand wars in webapps and * automaticly install contexts * * This happens _before_ Context.init() * * @author costin@dnt.ro */ public class AutoSetup extends BaseInterceptor { int debug=0; Hashtable definedContexts=new Hashtable(); public AutoSetup() { } /** This will add all contexts to the default host. * We need a mechanism ( or convention ) to configure * virtual hosts too */ public void engineStart(ContextManager cm) throws TomcatException { String home=cm.getHome(); File webappD=new File(home + "/webapps"); if (! webappD.exists() || ! webappD.isDirectory()) { log("No webapps/ directory " + webappD ); return ; // nothing to set up } Enumeration en=cm.getContexts(); while (en.hasMoreElements()){ Context ctx=(Context)en.nextElement(); if( ctx.getHost()== null ) { // this is a context that goes into the default server // we care only about the root context for autosetup // until we define a pattern for automatic vhost setup. definedContexts.put( ctx.getPath(), ctx ); if(debug>0) log("Register explicit context " + ctx.getPath()); } } String[] list = webappD.list(); if( list.length==0 ) { log("No apps in webapps/ "); } for (int i = 0; i < list.length; i++) { String name = list[i]; if( name.endsWith(".war") ) { String fname=name.substring(0, name.length()-4); File appDir=new File( home + "/webapps/" + fname); if( ! appDir.exists() ) { // no check if war file is "newer" than directory // To update you need to "remove" the context first!!! appDir.mkdirs(); // Expand war file try { FileUtil.expand(home + "/webapps/" + name, home + "/webapps/" + fname); } catch( IOException ex) { log("expanding webapp " + name, ex); // do what ? } } // we will add the directory to the path name=fname; } // XXX XXX Add a .xml case // If a "path.xml" file is found in webapps/, it will be loaded // as a fragment ( what will allow setting options // for contexts or automatic config for contexts with different base) // Decode path // Path will be based on the War name // Current code supports only one level, we // need to decide an encoding scheme for multi-level String path="/" + name; // decode(name) // log("XXX : " + path ); if( path.equals("/ROOT") ) path=""; if( definedContexts.get(path) == null ) { // if no explicit set up and is a directory File f=new File( webappD, name); if (f.isDirectory()) { Context ctx=new Context(); ctx.setContextManager( cm ); ctx.setPath(path); definedContexts.put( path, ctx ); // use absolute filename based on CM home instead of relative // don't assume HOME==TOMCAT_HOME ctx.setDocBase( f.getAbsolutePath() ); if( debug > 0 ) log("automatic add " + ctx.toString() + " " + path); cm.addContext(ctx); ctx.init(); } else { if( debug>0) log("Already set up: " + path + " " + definedContexts.get(path)); } } } } } 1.1 jakarta-tomcat/src/share/org/apache/tomcat/modules/config/DefaultCMSetter.java Index: DefaultCMSetter.java =================================================================== /* * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.tomcat.modules.aaa; import org.apache.tomcat.core.*; import org.apache.tomcat.request.*; import org.apache.tomcat.util.*; import java.io.*; import java.net.*; import java.util.*; import java.security.*; import org.apache.tomcat.util.log.*; // don't extend - replace ! /** * Check ContextManager and set defaults for non-set properties * * @author costin@dnt.ro */ public final class DefaultCMSetter extends BaseInterceptor { /** Default work dir, relative to home */ public static final String DEFAULT_WORK_DIR="work"; public DefaultCMSetter() { } /** Adjust context manager paths. * FIRST */ public void engineInit( ContextManager cm ) throws TomcatException { // Adjust paths in CM String home=cm.getHome(); if( home==null ) { // try system property home=System.getProperty(ContextManager.TOMCAT_HOME); } // Make it absolute if( home!= null ) { home=FileUtil.getCanonicalPath( home ); cm.setHome( home ); log( "engineInit: home= " + home ); } String installDir=cm.getInstallDir(); if( installDir!= null ) { installDir=FileUtil.getCanonicalPath( installDir ); cm.setInstallDir( installDir ); log( "engineInit: install= " + installDir ); } // if only one is set home==installDir if( home!=null && installDir == null ) cm.setInstallDir( home ); if( home==null && installDir != null ) cm.setHome( installDir ); // if neither home or install is set, // and no system property, try "." if( home==null && installDir==null ) { home=FileUtil.getCanonicalPath( "." ); installDir=home; cm.setHome( home ); cm.setInstallDir( home ); } // Adjust work dir String workDir=cm.getWorkDir(); if( workDir==null ) { workDir= DEFAULT_WORK_DIR; } if( ! FileUtil.isAbsolute( workDir )) { workDir=FileUtil. getCanonicalPath(home + File.separator+ workDir); } cm.setWorkDir( workDir ); initLoggers(cm.getLoggers()); } /** Generate a random number */ public void engineStart( ContextManager cm ) throws TomcatException { try { PrintWriter stopF=new PrintWriter (new FileWriter(cm.getHome() + "/conf/random.txt")); stopF.println( Math.random() ); stopF.close(); } catch( IOException ex ) { log( "Can't create stop file " + ex ); } } private void initLoggers(Hashtable Loggers){ if( Loggers!=null ){ Enumeration el=Loggers.elements(); while( el.hasMoreElements()){ Logger l=(Logger)el.nextElement(); String path=l.getPath(); if( path!=null ) { File f=new File( path ); if( ! f.isAbsolute() ) { File wd= new File(cm.getHome(), f.getPath()); l.setPath( wd.getAbsolutePath() ); } // create the files, ready to log. } l.open(); } } } /** Adjust paths */ public void addContext( ContextManager cm, Context ctx) throws TomcatException { // adjust context paths and loggers String docBase=ctx.getDocBase(); String absPath=ctx.getAbsolutePath(); if( absPath==null ) { if (FileUtil.isAbsolute( docBase ) ) absPath=docBase; else absPath = cm.getHome() + File.separator + docBase; try { absPath = new File(absPath).getCanonicalPath(); } catch (IOException npe) { } ctx.setAbsolutePath( absPath ); } if( debug > 0 ) { String h=ctx.getHost(); log( "addContext: " + ((h==null) ? "":h) + ":" + ctx.getPath() + " " + docBase + " " + absPath + " " + cm.getHome()); } // this would belong to a logger interceptor ? Log loghelper=ctx.getLog(); Log loghelperServlet=ctx.getServletLog(); if( loghelper!=null && loghelper.getLogger() != null ) cm.addLogger( loghelper.getLogger() ); if( loghelperServlet != null && loghelperServlet.getLogger() != null) cm.addLogger( loghelperServlet.getLogger() ); } } 1.1 jakarta-tomcat/src/share/org/apache/tomcat/modules/config/LoaderInterceptor11.java Index: LoaderInterceptor11.java =================================================================== /* * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.tomcat.modules.config; import org.apache.tomcat.core.*; import org.apache.tomcat.request.*; import org.apache.tomcat.util.*; import org.apache.tomcat.util.depend.*; import java.io.*; import java.net.*; import java.util.*; import java.security.*; /** * Set class loader based on WEB-INF/classes, lib. * Use with JDK1.1. * * @author costin@dnt.ro */ public class LoaderInterceptor11 extends BaseInterceptor { public LoaderInterceptor11() { } public void addContext( ContextManager cm, Context context) throws TomcatException { String base = context.getAbsolutePath(); // Add "WEB-INF/classes" File dir = new File(base + "/WEB-INF/classes"); // GS, Fix for the jar@lib directory problem. // Thanks for Kevin Jones for providing the fix. if( dir.exists() ) { try { URL url=new URL( "file", null, dir.getAbsolutePath() + "/" ); context.addClassPath( url ); } catch( MalformedURLException ex ) { } } File f = new File(base + "/WEB-INF/lib"); Vector jars = new Vector(); getJars(jars, f); for(int i=0; i < jars.size(); ++i) { String jarfile = (String) jars.elementAt(i); File jf=new File(f, jarfile ); String absPath=jf.getAbsolutePath(); try { URL url=new URL( "file", null, absPath ); context.addClassPath( url ); } catch( MalformedURLException ex ) { } } // Add servlet.jar and jasper.jar } public void contextInit( Context context) throws TomcatException { ContextManager cm = context.getContextManager(); URL classP[]=context.getClassPath(); if( debug > 0 ) { for( int i=0; i< classP.length ; i++ ) log ( "Set classpath " + classP[i] ); } DependManager dm=context.getDependManager(); if( dm==null ) { dm=new DependManager(); context.setDependManager( dm ); } // XXX Customize this - based on context prefs, // select the right parent - it may be CM.getParentLoader() ClassLoader parent=this.getClass().getClassLoader(); SimpleClassLoader loader=new SimpleClassLoader(classP, parent); DependClassLoader dcl=new DependClassLoader( dm, loader); context.setClassLoader( dcl ); } public void reload( Request req, Context context) throws TomcatException { log( "Reload event " ); ContextManager cm = context.getContextManager(); URL urls[]=context.getClassPath(); DependManager dm=new DependManager(); context.setDependManager( dm ); ClassLoader oldLoader=context.getClassLoader(); int oldLoaderNote=cm.getNoteId( ContextManager.CONTAINER_NOTE, "oldLoader"); context.getContainer().setNote( oldLoaderNote, oldLoader); // XXX Customize this - based on context prefs, // select the right parent - it may be CM.getParentLoader() ClassLoader parent=this.getClass().getClassLoader(); SimpleClassLoader loader=new SimpleClassLoader(urls, parent); DependClassLoader dcl=new DependClassLoader( dm, loader); context.setClassLoader( dcl ); } private void getJars(Vector v, File f) { FilenameFilter jarfilter = new FilenameFilter() { public boolean accept(File dir, String fname) { if(fname.endsWith(".jar")) return true; return false; } }; FilenameFilter dirfilter = new FilenameFilter() { public boolean accept(File dir, String fname) { File f1 = new File(dir, fname); if(f1.isDirectory()) return true; return false; } }; if(f.exists() && f.isDirectory() && f.isAbsolute()) { String[] jarlist = f.list(jarfilter); for(int i=0; (jarlist != null) && (i < jarlist.length); ++i) { v.addElement(jarlist[i]); } String[] dirlist = f.list(dirfilter); for(int i=0; (dirlist != null) && (i < dirlist.length); ++i) { File dir = new File(f, dirlist[i]); getJars(v, dir); } } } } 1.1 jakarta-tomcat/src/share/org/apache/tomcat/modules/config/LoaderInterceptor12.java Index: LoaderInterceptor12.java =================================================================== /* * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.tomcat.modules.config; import org.apache.tomcat.core.*; import org.apache.tomcat.request.*; import org.apache.tomcat.util.*; import org.apache.tomcat.util.depend.*; import java.io.*; import java.net.*; import java.util.*; import java.security.*; /** * Set class loader based on WEB-INF/classes, lib. * Uses the protection domain - if any, so PolicyInterceptor * must be called before it. * * @author costin@dnt.ro */ public class LoaderInterceptor12 extends BaseInterceptor { String classLoaderName; public LoaderInterceptor12() { } public void setClassLoaderName( String name ) { classLoaderName=name; } /** The class paths are added when the context is added */ public void addContext( ContextManager cm, Context context) throws TomcatException { if( debug>0) log( "Add context " + context.getPath()); String base = context.getAbsolutePath(); // Add "WEB-INF/classes" File dir = new File(base + "/WEB-INF/classes"); // GS, Fix for the jar@lib directory problem. // Thanks for Kevin Jones for providing the fix. if( dir.exists() ) { try { URL url=new URL( "file", null, dir.getAbsolutePath() + "/" ); context.addClassPath( url ); } catch( MalformedURLException ex ) { } } File f = new File(base + "/WEB-INF/lib"); Vector jars = new Vector(); getJars(jars, f); for(int i=0; i < jars.size(); ++i) { String jarfile = (String) jars.elementAt(i); File jf=new File(f, jarfile ); String absPath=jf.getAbsolutePath(); try { URL url=new URL( "file", null, absPath ); context.addClassPath( url ); } catch( MalformedURLException ex ) { } } } /** The class loader is set when the context us initialized * or at reload */ public void contextInit( Context context) throws TomcatException { if( debug>0 ) log( "Init context " + context.getPath()); ContextManager cm = context.getContextManager(); URL urls[]=context.getClassPath(); DependManager dm=context.getDependManager(); if( dm==null ) { dm=new DependManager(); context.setDependManager( dm ); } // XXX Customize this - based on context prefs, // select the right parent - it may be CM.getParentLoader() ClassLoader parent=this.getClass().getClassLoader(); URLClassLoader urlLoader=URLClassLoader.newInstance( urls, parent ); DependClassLoader dcl=new DependClassLoader( dm, urlLoader); context.setClassLoader( dcl ); } public void reload( Request req, Context context) throws TomcatException { log( "Reload event " ); ContextManager cm = context.getContextManager(); URL urls[]=context.getClassPath(); ClassLoader oldLoader=context.getClassLoader(); int oldLoaderNote=cm.getNoteId( ContextManager.CONTAINER_NOTE, "oldLoader"); context.getContainer().setNote( oldLoaderNote, oldLoader); DependManager dm=new DependManager(); context.setDependManager( dm ); // XXX Customize this - based on context prefs, // select the right parent - it may be CM.getParentLoader() ClassLoader parent=this.getClass().getClassLoader(); URLClassLoader urlLoader=URLClassLoader.newInstance( urls , parent); DependClassLoader dcl=new DependClassLoader( dm, urlLoader); context.setClassLoader( dcl ); } private void getJars(Vector v, File f) { FilenameFilter jarfilter = new FilenameFilter() { public boolean accept(File dir, String fname) { if(fname.endsWith(".jar")) return true; return false; } }; FilenameFilter dirfilter = new FilenameFilter() { public boolean accept(File dir, String fname) { File f1 = new File(dir, fname); if(f1.isDirectory()) return true; return false; } }; if(f.exists() && f.isDirectory() && f.isAbsolute()) { String[] jarlist = f.list(jarfilter); for(int i=0; (jarlist != null) && (i < jarlist.length); ++i) { v.addElement(jarlist[i]); } String[] dirlist = f.list(dirfilter); for(int i=0; (dirlist != null) && (i < dirlist.length); ++i) { File dir = new File(f, dirlist[i]); getJars(v, dir); } } } } 1.1 jakarta-tomcat/src/share/org/apache/tomcat/modules/config/PolicyInterceptor.java Index: PolicyInterceptor.java =================================================================== /* * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.tomcat.modules.config; import org.apache.tomcat.core.*; import org.apache.tomcat.request.*; import org.apache.tomcat.util.*; import java.io.*; import java.net.*; import java.util.*; import java.security.*; import org.apache.tomcat.util.log.*; /** * Set policy-based access to tomcat. * Must be hooked before class loader setter. * The context will have a single protection domain, pointing to the doc root. * That will include all classes loaded that belong to the context ( jsps, WEB-INF/classes, * WEB-INF/lib/ * * @author Glenn Nielsen * @author costin@dnt.ro */ public class PolicyInterceptor extends BaseInterceptor { String securityManagerClass="java.lang.SecurityManager"; String policyFile=null; public PolicyInterceptor() { } public void setSecurityManagerClass(String cls) { securityManagerClass=cls; } public void setPolicyFile( String pf) { policyFile=pf; } /** Set the security manager, so that policy will be used */ public void engineInit(ContextManager cm) throws TomcatException { if( System.getSecurityManager() != null ) return; try { if( null == System.getProperty("java.security.policy")) { if( policyFile==null ) { // XXX ugly API - change CM File f= new File(cm.getHome(), "conf/tomcat.policy"); policyFile=f.getPath(); } log("Setting policy file to " + policyFile); System.setProperty("java.security.policy", policyFile); } Class c=Class.forName(securityManagerClass); Object o=c.newInstance(); System.setSecurityManager((SecurityManager)o); if (debug>0) log("Security Manager set to " + securityManagerClass, Logger.DEBUG); } catch( ClassNotFoundException ex ) { log("SecurityManager Class not found: " + securityManagerClass, Logger.ERROR); } catch( Exception ex ) { log("SecurityManager Class could not be loaded: " + securityManagerClass, Logger.ERROR); } } /** Add a default set of permissions to the context */ protected void addDefaultPermissions( Context context,String base, Permissions p ) { // Add default read "-" FilePermission for docBase, classes, lib // Default per context permissions FilePermission fp = new FilePermission(base + "/-", "read"); if( fp != null ) p.add((Permission)fp); // JspFactory.getPageContext() runs in JSP Context and needs the below // permission during the init of a servlet generated from a JSP. PropertyPermission pp = new PropertyPermission("line.separator","read"); if( pp != null ) p.add((Permission)pp); } public void contextInit( Context context) throws TomcatException { ContextManager cm = context.getContextManager(); String base = context.getAbsolutePath(); try { File dir = new File(base); URL url = new URL("file:" + dir.getAbsolutePath()); CodeSource cs = new CodeSource(url,null); /* We'll construct permissions for Jasper. Tomcat uses normal policy and URLClassLoader. We may add fancy config later, if needed */ Permissions p = new Permissions(); // // Add global permissions ( from context manager ) // // XXX maybe use imply or something like that // Permissions perms = (Permissions)cm.getPermissions(); // if( perms!= null ) { // Enumeration enum=perms.elements(); // while(enum.hasMoreElements()) { // p.add((Permission)enum.nextElement()); // } // } addDefaultPermissions( context, dir.getAbsolutePath(), p); /** Add whatever permissions are specified in the policy file */ Policy.getPolicy().refresh(); PermissionCollection pFileP=Policy.getPolicy().getPermissions(cs); if( pFileP!= null ) { Enumeration enum=pFileP.elements(); while(enum.hasMoreElements()) { p.add((Permission)enum.nextElement()); } } // This is used only for Jasper ! Should be replaced by // a standard URLClassLoader. ProtectionDomain pd = new ProtectionDomain(cs,p); // context.setProtectionDomain(pd); context.setAttribute( Context.ATTRIB_PROTECTION_DOMAIN, pd); // new permissions - added context manager and file to whatever was // specified by default // context.setPermissions( p ); } catch(Exception ex) { log("Security init for Context " + base + " failed", ex); } } } 1.1 jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/ErrorHandler.java Index: ErrorHandler.java =================================================================== /* * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.tomcat.modules.generators; import org.apache.tomcat.core.*; import org.apache.tomcat.request.*; import org.apache.tomcat.util.*; import java.io.*; import java.net.*; import java.util.*; import java.security.*; import org.apache.tomcat.util.log.*; /** * Handle errors - this is the default handler, you can replace it * with customized versions * * @author Costin Manolache */ public final class ErrorHandler extends BaseInterceptor { private Context rootContext=null; public ErrorHandler() { } public void engineInit( ContextManager cm ) throws TomcatException { } public void addContext( ContextManager cm, Context ctx) throws TomcatException { } /** Add default error handlers */ public void contextInit( Context ctx) throws TomcatException { if( ctx.getHost() == null && ctx.getPath().equals("")) rootContext = ctx; boolean showDebugInfo=true; ContextManager cm=ctx.getContextManager(); String dI=cm.getProperty( "showDebugInfo" ); if( dI!=null && ( dI.equalsIgnoreCase("no") || dI.equalsIgnoreCase("false"))) { showDebugInfo=false; } // override with per/context setting dI=ctx.getProperty( "showDebugInfo" ); if( dI!=null && ( dI.equalsIgnoreCase("no") || dI.equalsIgnoreCase("false"))) { showDebugInfo=false; } if( dI!=null && ( dI.equalsIgnoreCase("yes") || dI.equalsIgnoreCase("true"))) { showDebugInfo=true; } ctx.addServlet( new ExceptionHandler(this, showDebugInfo)); ctx.addServlet( new StatusHandler(this, showDebugInfo)); // Default status handlers ctx.addServlet( new RedirectHandler(this)); ctx.addErrorPage( "302", "tomcat.redirectHandler"); ctx.addServlet( new NotFoundHandler(this, showDebugInfo)); ctx.addErrorPage( "404", "tomcat.notFoundHandler"); } public int handleError( Request req, Response res, Throwable t ) { ContextManager cm=req.getContextManager(); Context ctx = req.getContext(); if(ctx==null) { // that happens only if the request can't pass contextMap // hook. The reason for that is a malformed request, or any // other error. ctx=rootContext; } if( t==null ) { handleStatusImpl( cm, ctx, req, res, res.getStatus() ); } else { handleErrorImpl( cm, ctx, req, res, t ); } return 200; } // -------------------- Implementation of handleError // Originally in ContextManager. private final void handleStatusImpl( ContextManager cm, Context ctx, Request req, Response res, int code ) { String errorPath=null; Handler errorServlet=null; // don't log normal cases ( redirect and need_auth ), they are not // error // XXX this log was intended to debug the status code generation. // it can be removed for all cases. if( code != 302 && code != 401 && code!=400 ) {// tuneme ctx.log( "Status code:" + code + " request:" + req + " msg:" + req.getAttribute("javax.servlet.error.message")); } errorPath = ctx.getErrorPage( code ); if( errorPath != null ) { errorServlet=getHandlerForPath( cm, ctx, errorPath ); // Make sure Jsps will work req.setAttribute( "javax.servlet.include.request_uri", ctx.getPath() + "/" + errorPath ); req.setAttribute( "javax.servlet.include.servlet_path", errorPath ); } boolean isDefaultHandler = false; if( errorServlet==null ) { errorServlet=ctx.getServletByName( "tomcat.statusHandler"); isDefaultHandler = true; } if (errorServlet == null) { ctx.log( "Handler errorServlet is null! errorPath:" + errorPath); return; } if (!isDefaultHandler && !res.isBufferCommitted()) res.resetBuffer(); req.setAttribute("javax.servlet.error.status_code",new Integer( code)); req.setAttribute("tomcat.servlet.error.request", req); if( debug>0 ) ctx.log( "Handler " + errorServlet + " " + errorPath); errorServlet.service( req, res ); Exception ex=res.getErrorException(); if( ex!=null && ! (ex instanceof IOException) ) { // we can ignore IOException - probably the user // has clicked "STOP" // we need to log any other error - something may be // broken if the error servlet has errors. ctx.log( "Error in default status handler", ex); } } // XXX XXX Security - we should log the message, but nothing // should show up to the user - it gives up information // about the internal system ! // Developers can/should use the logs !!! /** General error handling mechanism. It will try to find an error handler * or use the default handler. */ void handleErrorImpl( ContextManager cm, Context ctx, Request req, Response res , Throwable t ) { /** The exception must be available to the user. Note that it is _WRONG_ to send the trace back to the client. AFAIK the trace is the _best_ debugger. */ if( t instanceof IllegalStateException ) { ctx.log("IllegalStateException in " + req, t); // Nothing special in jasper exception treatement, no deps //} else if( t instanceof org.apache.jasper.JasperException ) { // ctx.log("JasperException in " + req, t); } else if( t instanceof IOException ) { if( "Broken pipe".equals(t.getMessage())) { ctx.log("Broken pipe in " + req, t, Logger.DEBUG); // tuneme return; } if( "Connection reset by peer".equals(t.getMessage())) { ctx.log("Connection reset by peer in " + req, t, Logger.DEBUG); // tuneme return; } ctx.log("IOException in " + req, t ); } else { ctx.log("Exception in " + req , t ); } if(null!=req.getAttribute("tomcat.servlet.error.defaultHandler")){ // we are in handleRequest for the "default" error handler log("ERROR: can't find default error handler, or error in default error page", t); } String errorPath=null; Handler errorServlet=null; // Scan the exception's inheritance tree looking for a rule // that this type of exception should be forwarded Class clazz = t.getClass(); while (errorPath == null && clazz != null) { String name = clazz.getName(); errorPath = ctx.getErrorPage(name); clazz = clazz.getSuperclass(); } if( errorPath != null ) { errorServlet=getHandlerForPath( cm, ctx, errorPath ); // Make sure Jsps will work req.setAttribute( "javax.servlet.include.request_uri", ctx.getPath() + "/" + errorPath ); req.setAttribute( "javax.servlet.include.servlet_path", errorPath ); } boolean isDefaultHandler = false; if ( errorLoop( ctx, req ) ){ return; } if ( errorServlet==null) { errorServlet = ctx.getServletByName("tomcat.exceptionHandler"); isDefaultHandler = true; } if (errorServlet == null) { ctx.log( "Handler errorServlet is null! errorPath:" + errorPath); return; } if (!isDefaultHandler && !res.isBufferCommitted()) res.resetBuffer(); req.setAttribute("javax.servlet.error.exception_type", t.getClass()); req.setAttribute("javax.servlet.error.message", t.getMessage()); req.setAttribute("javax.servlet.jsp.jspException", t); req.setAttribute("tomcat.servlet.error.throwable", t); req.setAttribute("tomcat.servlet.error.request", req); if( debug>0 ) ctx.log( "Handler " + errorServlet + " " + errorPath); errorServlet.service( req, res ); Exception ex=res.getErrorException(); if( ! (ex instanceof IOException) ) { // we can ignore IOException - probably the user // has clicked "STOP" // we need to log any other error - something may be // broken if the error servlet has errors. ctx.log( "Error in errorServlet", ex); } } public final Handler getHandlerForPath( ContextManager cm, Context ctx, String path ) { if( ! path.startsWith( "/" ) ) { return ctx.getServletByName( path ); } Request req1=new Request(); Response res1=new Response(); cm.initRequest( req1, res1 ); req1.requestURI().setString( ctx.getPath() + path ); cm.processRequest( req1 ); return req1.getHandler(); } /** Handle the case of error handler generating an error or special status */ private boolean errorLoop( Context ctx, Request req ) { if( req.getAttribute("javax.servlet.error.status_code") != null || req.getAttribute("javax.servlet.error.exception_type")!=null) { if( ctx.getDebug() > 0 ) ctx.log( "Error: exception inside exception servlet " + req.getAttribute("javax.servlet.error.status_code") + " " + req. getAttribute("javax.servlet.error.exception_type")); return true; } return false; } } class NotFoundHandler extends Handler { static StringManager sm=StringManager. getManager("org.apache.tomcat.resources"); int sbNote=0; boolean showDebugInfo=true; NotFoundHandler(BaseInterceptor bi, boolean showDebugInfo) { // setOrigin( Handler.ORIGIN_INTERNAL ); name="tomcat.notFoundHandler"; setModule(bi); this.showDebugInfo=showDebugInfo; } public void doService(Request req, Response res) throws Exception { res.setContentType("text/html"); // ISO-8859-1 default String requestURI = (String)req. getAttribute("javax.servlet.include.request_uri"); if (requestURI == null) { requestURI = req.requestURI().toString(); } if( sbNote==0 ) { sbNote=req.getContextManager().getNoteId(ContextManager.REQUEST_NOTE, "NotFoundHandler.buff"); } // we can recycle it because // we don't call toString(); StringBuffer buf=(StringBuffer)req.getNote( sbNote ); if( buf==null ) { buf = new StringBuffer(); req.setNote( sbNote, buf ); } boolean bufReset = (res.getBuffer().getBytesWritten() == 0); // only include ... if reset was successful if (bufReset) { buf.append("") .append(sm.getString("defaulterrorpage.notfound404")) .append("\r\n"); } buf.append("

") .append(sm.getString("defaulterrorpage.notfound404")) .append("

\r\n"); buf.append(sm.getString("defaulterrorpage.originalrequest")) .append( requestURI ) .append("\r\n"); if ( null != requestURI && showDebugInfo ) { buf.append("

\r\n") .append(sm.getString("defaulterrorpage.notfoundrequest")) .append(" ") .append( requestURI ) .append("\r\n"); } // only add if reset was successful if ( bufReset ) buf.append(""); buf.append("\r\n"); res.setContentLength(buf.length()); res.getBuffer().write( buf ); buf.setLength(0); } } class ExceptionHandler extends Handler { static StringManager sm=StringManager. getManager("org.apache.tomcat.resources"); int sbNote=0; boolean showDebugInfo=true; ExceptionHandler(BaseInterceptor bi, boolean showDebugInfo) { // setOrigin( Handler.ORIGIN_INTERNAL ); name="tomcat.exceptionHandler"; setModule( bi ); this.showDebugInfo=showDebugInfo; } public void doService(Request req, Response res) throws Exception { String msg=(String)req.getAttribute("javax.servlet.error.message"); String errorURI = res.getErrorURI(); Throwable e= (Throwable)req. getAttribute("tomcat.servlet.error.throwable"); if( e==null ) { log("Exception handler called without an exception", new Throwable("trace")); return; } res.setContentType("text/html"); res.setStatus( 500 ); if( sbNote==0 ) { sbNote=req.getContextManager().getNoteId(ContextManager.REQUEST_NOTE, "ExceptionHandler.buff"); } // we can recycle it because // we don't call toString(); StringBuffer buf=(StringBuffer)req.getNote( sbNote ); if( buf==null ) { buf = new StringBuffer(); req.setNote( sbNote, buf ); } boolean bufReset = (res.getBuffer().getBytesWritten() == 0); // only include ... if reset was successful if (bufReset) { buf.append(""); if( null != errorURI && showDebugInfo ) { buf.append(sm.getString("defaulterrorpage.includedservlet") ) .append(" "); } else { buf.append("Error: "); } buf.append( 500 ) .append("\r\n\r\n"); } buf.append("

"); if( null != errorURI && showDebugInfo ) { buf.append(sm.getString("defaulterrorpage.includedservlet") ). append(" "); } else { buf.append("Error: "); } buf.append( 500 ); buf.append("

\r\n"); // More info - where it happended" buf.append("

") .append(sm.getString("defaulterrorpage.location")) .append(req.requestURI().toString()) .append("

"); if ( null != errorURI && showDebugInfo ) { buf.append("\r\n

") .append(sm.getString("defaulterrorpage.errorlocation")) .append(" ") .append(errorURI) .append("

"); } if (showDebugInfo) { buf.append("") .append(sm.getString("defaulterrorpage.internalservleterror")); buf.append("
\r\n
");
  	    // prints nested exceptions too, including SQLExceptions, recursively
  	    String trace = Logger.throwableToString
  		(e, "" + sm.getString("defaulterrorpage.rootcause") + "");
  	    buf.append(trace);
  	    buf.append("
\r\n"); } else { buf.append("Error: ") .append(e.getMessage()) .append("

\r\n"); } // only add if reset was successful if ( bufReset ) buf.append(""); buf.append("\r\n"); res.getBuffer().write( buf ); buf.setLength(0); } } class StatusHandler extends Handler { static StringManager sm=StringManager. getManager("org.apache.tomcat.resources"); int sbNote=0; boolean showDebugInfo=true; StatusHandler(BaseInterceptor bi, boolean showDebugInfo) { //setOrigin( Handler.ORIGIN_INTERNAL ); name="tomcat.statusHandler"; setModule( bi ); this.showDebugInfo=showDebugInfo; } // We don't want interceptors called for redirect // handler public void doService(Request req, Response res) throws Exception { String msg=(String)req.getAttribute("javax.servlet.error.message"); String errorURI = res.getErrorURI(); res.setContentType("text/html"); // res is reset !!! // status is already set int sc=res.getStatus(); if( sbNote==0 ) { sbNote=req.getContextManager().getNoteId(ContextManager.REQUEST_NOTE, "StatusHandler.buff"); } // we can recycle it because // we don't call toString(); StringBuffer buf=(StringBuffer)req.getNote( sbNote ); if( buf==null ) { buf = new StringBuffer(); req.setNote( sbNote, buf ); } boolean bufReset = (res.getBuffer().getBytesWritten() == 0); // only include ... if reset was successful if (bufReset) { buf.append(""); if( null != errorURI && showDebugInfo ) { buf.append(sm.getString("defaulterrorpage.includedservlet") ) .append(" "); } else { buf.append("Error: "); } buf.append( sc ) .append("\r\n\r\n"); } buf.append("

"); if( null != errorURI && showDebugInfo ) { buf.append(sm.getString("defaulterrorpage.includedservlet") ) .append(" "); } else { buf.append("Error: "); } buf.append( sc ); buf.append("

\r\n"); // More info - where it happended" buf.append("

") .append(sm.getString("defaulterrorpage.location")) .append(req.requestURI().toString()) .append("

"); if ( sc >= 400 && errorURI != null && showDebugInfo) { buf.append("\r\n

") .append(sm.getString("defaulterrorpage.errorlocation")) .append(" ") .append(errorURI) .append("

"); } buf.append("\r\n") .append(msg) .append("
\r\n"); // add unavailable time if present if ( sc == 503) { Integer ut = (Integer)req.getAttribute("tomcat.servlet.error.service.unavailableTime"); if ( ut != null) { buf.append("
"); // if permanent if (ut.intValue() < 0) { buf.append(sm.getString("defaulterrorpage.service.permanently.unavailable")); } else { buf.append(sm.getString("defaulterrorpage.service.unavailable",ut)); } buf.append("
\r\n"); } } // only add if reset was successful if ( bufReset ) buf.append(""); buf.append("\r\n"); res.setContentLength(buf.length()); res.getBuffer().write( buf ); buf.setLength(0); } } class RedirectHandler extends Handler { static StringManager sm=StringManager. getManager("org.apache.tomcat.resources"); int sbNote=0; RedirectHandler(BaseInterceptor bi) { //setOrigin( Handler.ORIGIN_INTERNAL ); name="tomcat.redirectHandler"; setModule( bi ); } // We don't want interceptors called for redirect // handler public void doService(Request req, Response res) throws Exception { String location = (String) req.getAttribute("javax.servlet.error.message"); Context ctx=req.getContext(); location = makeAbsolute(req, location); if( debug>0) ctx.log("Redirect " + location + " " + req ); res.setContentType("text/html"); // ISO-8859-1 default res.setHeader("Location", location); if( sbNote==0 ) { sbNote=req.getContextManager().getNoteId(ContextManager.REQUEST_NOTE, "RedirectHandler.buff"); } // we can recycle it because // we don't call toString(); StringBuffer buf=(StringBuffer)req.getNote( sbNote ); if( buf==null ) { buf = new StringBuffer(); req.setNote( sbNote, buf ); } buf.append(""). append(sm.getString("defaulterrorpage.documentmoved")). append("\r\n

"). append(sm.getString("defaulterrorpage.documentmoved")). append("

\r\n"). append(sm.getString("defaulterrorpage.thisdocumenthasmoved")). append(" here.

\r\n\r\n"); res.setContentLength(buf.length()); res.getBuffer().write( buf ); buf.setLength(0); } // XXX Move it to URLUtil !!! private String makeAbsolute(Request req, String location) { URL url = null; try { // Try making a URL out of the location // Throws an exception if the location is relative url = new URL(location); } catch (MalformedURLException e) { String requrl = getRequestURL(req); try { url = new URL(new URL(requrl), location); } catch (MalformedURLException ignored) { // Give up return location; } } return url.toString(); } static String getRequestURL( Request req ) { StringBuffer url = new StringBuffer (); String scheme = req.scheme().toString(); int port = req.getServerPort (); String urlPath = req.requestURI().toString(); url.append (scheme); // http, https url.append ("://"); url.append (req.serverName().toString()); if ((scheme.equals ("http") && port != 80) || (scheme.equals ("https") && port != 443)) { url.append (':'); url.append (port); } url.append(urlPath); return url.toString(); } } 1.1 jakarta-tomcat/src/share/org/apache/tomcat/modules/loggers/LogEvents.java Index: LogEvents.java =================================================================== /* * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.tomcat.modules.loggers; import org.apache.tomcat.core.*; import org.apache.tomcat.util.*; import java.io.*; import java.net.*; import java.util.*; /** Log all hook events during tomcat execution. * Use debug>0 to log addContainer ( since this generates a lot of * output ) */ public class LogEvents extends BaseInterceptor { public LogEvents() { } // -------------------- Request notifications -------------------- public int requestMap(Request request ) { log( "requestMap " + request); return 0; } public int contextMap( Request request ) { log( "contextMap " + request); return 0; } public int preService(Request request, Response response) { log( "preService " + request); return 0; } public int authenticate(Request request, Response response) { log( "authenticate " + request); return 0; } public int authorize(Request request, Response response, String reqRoles[]) { StringBuffer sb=new StringBuffer(); appendSA( sb, reqRoles, " "); log( "authorize " + request + " " + sb.toString() ); return 0; } public int beforeBody( Request request, Response response ) { log( "beforeBody " + request); return 0; } public int beforeCommit( Request request, Response response) { log( "beforeCommit " + request); return 0; } public int afterBody( Request request, Response response) { log( "afterBody " + request); return 0; } public int postRequest( Request request, Response response) { log( "postRequest " + request); return 0; } public int handleError( Request request, Response response, Throwable t) { log( "handleError " + request + " " + t); return 0; } public int postService(Request request, Response response) { log( "postService " + request); return 0; } public int newSessionRequest( Request req, Response res ) { log( "newSessionRequest " + req ); return 0; } // -------------------- Context notifications -------------------- public void contextInit(Context ctx) throws TomcatException { log( "contextInit " + ctx); } public void contextShutdown(Context ctx) throws TomcatException { log( "contextShutdown " + ctx); } /** Notify when a new servlet is added */ public void addServlet( Context ctx, Handler sw) throws TomcatException { log( "addServlet " + ctx + " " + sw ); } /** Notify when a servlet is removed from context */ public void removeServlet( Context ctx, Handler sw) throws TomcatException { log( "removeServlet " + ctx + " " + sw); } public void addMapping( Context ctx, String path, Handler servlet) throws TomcatException { log( "addMapping " + ctx + " " + path + "->" + servlet); } public void removeMapping( Context ctx, String path ) throws TomcatException { log( "removeMapping " + ctx + " " + path); } private void appendSA( StringBuffer sb, String s[], String sep) { for( int i=0; i 0 ) log( "addContainer " + ct.getContext() + " " + ct ); } public void engineState( ContextManager cm , int state ) throws TomcatException { log( "engineState " + state ); } public void engineStart( ContextManager cm ) throws TomcatException { log( "engineStart " ); } /** Called when a context is removed from a CM */ public void removeContext( ContextManager cm, Context ctx ) throws TomcatException { log( "removeContext" + ctx); } /** Servlet Init notification */ public void preServletInit( Context ctx, Handler sw ) throws TomcatException { log( "preServletInit " + ctx + " " + sw); } public void postServletInit( Context ctx, Handler sw ) throws TomcatException { log( "postServletInit " + ctx + " " + sw); } /** Servlet Destroy notification */ public void preServletDestroy( Context ctx, Handler sw ) throws TomcatException { log( "preServletDestroy " + ctx + " " + sw); } public void postServletDestroy( Context ctx, Handler sw ) throws TomcatException { log( "postServletDestroy " + ctx + " " + sw); } } 1.40 +10 -10 jakarta-tomcat/src/share/org/apache/tomcat/startup/EmbededTomcat.java Index: EmbededTomcat.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/EmbededTomcat.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- EmbededTomcat.java 2000/12/29 01:34:42 1.39 +++ EmbededTomcat.java 2001/01/01 01:58:39 1.40 @@ -254,23 +254,23 @@ // no AutoSetup ! protected String moduleSet1[] = { - "org.apache.tomcat.context.DefaultCMSetter", + "org.apache.tomcat.modules.config.DefaultCMSetter", "org.apache.tomcat.facade.WebXmlReader", - "org.apache.tomcat.context.PolicyInterceptor", - "org.apache.tomcat.context.LoaderInterceptor12", - "org.apache.tomcat.context.ErrorHandler", + "org.apache.tomcat.modules.config.PolicyInterceptor", + "org.apache.tomcat.modules.config.LoaderInterceptor12", + "org.apache.tomcat.modules.generators.ErrorHandler", "org.apache.tomcat.modules.config.WorkDirSetup", "org.apache.tomcat.modules.session.SessionId", - "org.apache.tomcat.request.SimpleMapper1", - "org.apache.tomcat.request.InvokerInterceptor", + "org.apache.tomcat.modules.mappers.SimpleMapper1", + "org.apache.tomcat.modules.generators.InvokerInterceptor", "org.apache.tomcat.facade.JspInterceptor", - "org.apache.tomcat.request.StaticInterceptor", + "org.apache.tomcat.modules.generators.StaticInterceptor", "org.apache.tomcat.modules.session.SimpleSessionStore", "org.apache.tomcat.facade.LoadOnStartupInterceptor", "org.apache.tomcat.facade.Servlet22Interceptor", - "org.apache.tomcat.request.AccessInterceptor", - "org.apache.tomcat.request.CredentialsInterceptor", - "org.apache.tomcat.request.Jdk12Interceptor" + "org.apache.tomcat.modules.aaa.AccessInterceptor", + "org.apache.tomcat.modules.aaa.CredentialsInterceptor", + "org.apache.tomcat.modules.mappers.Jdk12Interceptor" }; protected String moduleSet2[] = {