tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/startup EmbededTomcat.java
Date Tue, 20 Jun 2000 19:22:59 GMT
costin      00/06/20 12:22:57

  Modified:    src/etc  server.xml
               src/share/org/apache/tomcat/context WebXmlReader.java
               src/share/org/apache/tomcat/core BaseInterceptor.java
                        ServletWrapper.java
               src/share/org/apache/tomcat/request AccessInterceptor.java
                        JDBCRealm.java SimpleMapper1.java SimpleRealm.java
               src/share/org/apache/tomcat/session
                        StandardSessionInterceptor.java
               src/share/org/apache/tomcat/startup EmbededTomcat.java
  Added:       src/share/org/apache/tomcat/request InvokerInterceptor.java
  Removed:     src/share/org/apache/tomcat/servlets BasicLoginServlet.java
                        DefaultErrorPage.java FormLoginServlet.java
                        InvokerServlet.java
  Log:
  - Invoker: new (clean) code, a lot of improvements and fewer layers.
  
  - If you embed tomcat, you can add to the context classpath specific jar files.
  Probably just including them in lib is better, but it seem some people need that.
  
  - moved all the debug/log in BaseInterceptor, no need to duplicate it in all subclasses
  
  - removed old servlets ( that are no longer active - the error handler and invoker are
  rewritten)
  
  Revision  Changes    Path
  1.26      +6 -0      jakarta-tomcat/src/etc/server.xml
  
  Index: server.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/etc/server.xml,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- server.xml	2000/06/19 21:40:14	1.25
  +++ server.xml	2000/06/20 19:22:31	1.26
  @@ -76,6 +76,12 @@
               className="org.apache.tomcat.request.SimpleMapper1" 
               debug="0" />
   
  +        <!-- Non-standard invoker, for backward compat. ( /servlet/* )
  +          -->
  +        <RequestInterceptor 
  +            className="org.apache.tomcat.request.InvokerInterceptor" 
  +            debug="20" />
  +
           <!-- Plug a session manager. You can plug in more advanced session
                modules.
             -->
  
  
  
  1.24      +2 -2      jakarta-tomcat/src/share/org/apache/tomcat/context/WebXmlReader.java
  
  Index: WebXmlReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/WebXmlReader.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- WebXmlReader.java	2000/06/13 00:32:34	1.23
  +++ WebXmlReader.java	2000/06/20 19:22:32	1.24
  @@ -48,11 +48,11 @@
   	throws TomcatException
       {
   	addServlet( ctx, "default", "org.apache.tomcat.servlets.DefaultServlet");
  -	addServlet( ctx, "invoker", "org.apache.tomcat.servlets.InvokerServlet");
  +// 	addServlet( ctx, "invoker", "org.apache.tomcat.servlets.InvokerServlet");
   	ServletWrapper sw=addServlet( ctx, "jsp", "org.apache.jasper.runtime.JspServlet");
   	//	sw.addInitParam("jspCompilerPlugin", "org.apache.jasper.compiler.JikesJavaCompiler");
   
  -	ctx.addServletMapping( "/servlet/*", "invoker");
  +// 	ctx.addServletMapping( "/servlet/*", "invoker");
   	ctx.addServletMapping( "*.jsp", "jsp");
   	
   	ctx.setSessionTimeOut( 30 );
  
  
  
  1.12      +13 -0     jakarta-tomcat/src/share/org/apache/tomcat/core/BaseInterceptor.java
  
  Index: BaseInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/BaseInterceptor.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- BaseInterceptor.java	2000/06/16 21:03:19	1.11
  +++ BaseInterceptor.java	2000/06/20 19:22:32	1.12
  @@ -73,6 +73,7 @@
       protected ContextManager cm; 
       protected String methods[]=new String[0];
       protected int debug=0;
  +    protected String name=null;
       
       public BaseInterceptor() {
       }
  @@ -83,6 +84,18 @@
   
       public void setContextManager( ContextManager cm ) {
   	this.cm=cm;
  +    }
  +
  +    protected void log( String s ) {
  +	if( name == null ) {
  +	    String cname=this.getClass().getName();
  +	    name=cname.substring( cname.lastIndexOf(".") +1);
  +	    name=name + ": ";
  +	}
  +	if( cm!= null )
  +	    cm.log( name + s );
  +	else 
  +	    System.out.println(name + s ); 
       }
       
       // -------------------- Request notifications --------------------
  
  
  
  1.57      +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java
  
  Index: ServletWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ServletWrapper.java,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- ServletWrapper.java	2000/06/20 00:17:43	1.56
  +++ ServletWrapper.java	2000/06/20 19:22:33	1.57
  @@ -374,7 +374,7 @@
       void handleReload(Request req) throws TomcatException {
   	// That will be reolved after we reset the context - and many
   	// other conflicts.
  -	if( isReloadable && ! "invoker".equals( getServletName())) {
  +	if( isReloadable ) {// && ! "invoker".equals( getServletName())) {
   	    ServletLoader loader=context.getServletLoader();
   	    if( loader!=null) {
   		// XXX no need to check after we remove the old loader
  
  
  
  1.9       +14 -26    jakarta-tomcat/src/share/org/apache/tomcat/request/AccessInterceptor.java
  
  Index: AccessInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/AccessInterceptor.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AccessInterceptor.java	2000/06/19 21:53:15	1.8
  +++ AccessInterceptor.java	2000/06/20 19:22:40	1.9
  @@ -83,7 +83,6 @@
    *  concepts - I think we can do that, but need to experiment with that)
    */
   public class AccessInterceptor extends  BaseInterceptor  {
  -    int debug=0;
       ContextManager cm;
   
       // Security mapping note
  @@ -96,20 +95,6 @@
       public AccessInterceptor() {
       }
   
  -    /* -------------------- Support functions -------------------- */
  -    public void setDebug( int i ) {
  -	if( debug > 0 || i>0)
  -	    System.out.println("setDebug " + i );
  -    }
  -    
  -    void log( String msg ) {
  -	if( cm==null) 
  -	    System.out.println("AccessInterceptor: " + msg );
  -	else
  -	    cm.log( "AccessInterceptor: " + msg );
  -    }
  -
  -
       /* -------------------- Initialization -------------------- */
       
       /** Set the context manager. To keep it simple we don't support
  @@ -169,16 +154,18 @@
   	    // Workaround for common error - ctx path included
   	    if( ! page.startsWith( cpath ) )
   		page= cpath + page;
  -	    else 
  -		ctx.log("FORM: WARNING, login page starts with context path " +
  -			page);
  +	    else
  +		if( ! "/".equals(cpath))
  +		    ctx.log("FORM: WARNING, login page starts with " +
  +			    "context path " + page);
   	    
   
   	    if( ! errorPage.startsWith( cpath ) )
   		errorPage= cpath + errorPage;
  -	    else 
  -		ctx.log("FORM: WARNING, error page starts with context path " +
  -			errorPage);
  +	    else
  +		if( ! "/".equals(cpath))
  +		    ctx.log("FORM: WARNING, error page starts with " +
  +			    "context path " + errorPage);
   
   	    // Adjust login and error paths - avoid computations in handlers
   	    ctx.setFormLoginPage( page );
  @@ -229,9 +216,9 @@
   	if( ctxSecurityC==null)
   	    ctxCt.setNote( secMapNote, new SecurityConstraints() );
   
  -	log( "addContainer() " + ctx.getHost() + " " +
  -	     ctx.getPath() + " " +
  -	     ct.getPath() );
  +// 	log( "addContainer() " + ctx.getHost() + " " +
  +// 	     ctx.getPath() + " " +
  +// 	     ct.getPath() );
   	
   	if( ct.getRoles()!=null || ct.getTransport()!=null ) {
   	    if( debug > 0 )
  @@ -282,9 +269,10 @@
   		    ! "NONE".equals( transport )) {
   		    req.setNote( reqTransportNote, transport );
   		}
  -	    
  +		
   		// roles will be checked by a different interceptor
  -		req.setNote( reqRolesNote, roles );
  +		if( roles!= null  && roles.length > 0) 
  +		    req.setNote( reqRolesNote, roles );
   	    }
   	}
    	return 0;
  
  
  
  1.6       +0 -29     jakarta-tomcat/src/share/org/apache/tomcat/request/JDBCRealm.java
  
  Index: JDBCRealm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/JDBCRealm.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JDBCRealm.java	2000/06/19 20:48:59	1.5
  +++ JDBCRealm.java	2000/06/20 19:22:41	1.6
  @@ -102,13 +102,6 @@
   
       // ----------------------------------------------------- Instance Variables
   
  -
  -
  -    /**
  -     * The debugging detail level for this component.
  -     */
  -    private int debug = 0;
  -
       /**
        * The connection to the database.
        */
  @@ -180,25 +173,7 @@
       // ------------------------------------------------------------- Properties
   
   
  -
  -    /**
  -     * Return the debugging detail level for this component.
  -     */
  -    public int getDebug() {
  -	    return (this.debug);
  -    }
  -
  -
       /**
  -     * Set the debugging detail level for this component.
  -     *
  -     * @param debug The new debugging detail level
  -     */
  -    public void setDebug(int debug) {
  -	this.debug = debug;
  -    }
  -
  -    /**
        * Set the JDBC driver that will be used.
        *
        * @param driverName The driver name
  @@ -439,10 +414,6 @@
         }
       }
   
  -
  -    void log( String s ) {
  -	    cm.log("JDBCRealm: " + s );
  -    }
       public void setContextManager( ContextManager cm ) {
         super.setContextManager( cm );
   
  
  
  
  1.8       +0 -7      jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleMapper1.java
  
  Index: SimpleMapper1.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleMapper1.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SimpleMapper1.java	2000/06/10 21:55:31	1.7
  +++ SimpleMapper1.java	2000/06/20 19:22:46	1.8
  @@ -110,13 +110,6 @@
   	debug=level;
       }
   
  -    void log( String msg ) {
  -	if( cm==null) 
  -	    System.out.println("SimpleMapper: " + msg );
  -	else
  -	    cm.log( msg );
  -    }
  -
       /** Allow the mapper to cache mapping results - resulting in a
        *  faster match for frequent requests. ( treat this as experimental)
        */
  
  
  
  1.3       +0 -10     jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleRealm.java
  
  Index: SimpleRealm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleRealm.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleRealm.java	2000/06/19 21:53:15	1.2
  +++ SimpleRealm.java	2000/06/20 19:22:47	1.3
  @@ -82,17 +82,12 @@
   public class SimpleRealm extends  BaseInterceptor {
   
       MemoryRealm memoryRealm;
  -    int debug=0;
       ContextManager cm;
       int reqRolesNote;
       
       public SimpleRealm() {
       }
   
  -    void log( String s ) {
  -	cm.log("SimpleRealm: " + s );
  -    }
  -
       /** Set the context manager. To keep it simple we don't support
        *  dynamic add/remove for this interceptor. 
        */
  @@ -111,11 +106,6 @@
   	}
       }
   
  -    public void setDebug( int d ) {
  -	debug=d;
  -    }
  -
  -    
       public void contextInit( Context ctx)
   	throws TomcatException
       {
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/request/InvokerInterceptor.java
  
  Index: InvokerInterceptor.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
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  package org.apache.tomcat.request;
  
  import org.apache.tomcat.util.*;
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.facade.*;
  import org.apache.tomcat.core.Constants;
  import java.io.IOException;
  import java.io.PrintWriter;
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.UnavailableException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   *
   *
   * @author James Duncan Davidson [duncan@eng.sun.com]
   * @author Jason Hunter [jch@eng.sun.com]
   * @author James Todd [gonzo@eng.sun.com]
   * @author Costin Manolache
   */
  public class InvokerInterceptor extends BaseInterceptor {
  
      String prefix="/servlet/";
      int prefixLen=prefix.length();
  
      public int requestMap(Request req) {
  	// If we have an explicit mapper - return
  	if( req.getWrapper() != null &&
  	    ! "default".equals( req.getWrapper().getName()))
  	    return 0;
  
  	// if doesn't starts with /servlet - return
  	String pathInfo = req.getPathInfo();
  	String servletPath=req.getServletPath();
  	
  	// Now we need to fix path info and servlet path
  	if( pathInfo == null ||
  	    ! pathInfo.startsWith( prefix ))
  	    return 0;
  
  	Context ctx=req.getContext();
  	// Set the wrapper, and add a new mapping - next time
  	// we'll not have to do that ( the simple mapper is
  	// supposed to be faster )
  	
  	String servletName = null;
  	String newPathInfo = null;
  	
  	if( debug>0 )
  	    log( "Original ServletPath=" +servletPath +
  		 " PathInfo=" + pathInfo);
  
  	int secondSlash=pathInfo.indexOf("/", prefixLen );
  	if ( secondSlash > -1) {
  	    servletName = pathInfo.substring(prefixLen, secondSlash );
  	    newPathInfo = pathInfo.substring( secondSlash );
  	} else {
  	    servletName = pathInfo.substring( prefixLen );
  	}
  	
  	String newServletPath = prefix + servletName;
  
  	if( debug > 0)
  	    log( "After pathfix SN=" + servletName +
  		 " SP=" + newServletPath +
  		 " PI=" + newPathInfo);
  	
  	ServletWrapper wrapper = ctx.getServletByName(servletName);
   	req.setServletPath(newServletPath);
  	req.setPathInfo(newPathInfo);
  	
  	if (wrapper != null) {
  	    req.setWrapper( wrapper );
  	    return 0;
  	}
  	    
  	// Dynamic add for the wrapper
  	
  	// even if the server doesn't supports dynamic mappings,
  	// we'll avoid the interceptor for include() and
  	// it's a much cleaner way to construct the servlet and
  	// make sure all interceptors are up to date.
  	try {
  	    ctx.addServletMapping( newServletPath + "/*" ,
  				   servletName );
  	    wrapper = ctx.getServletByName( servletName);
  	    wrapper.setOrigin( ServletWrapper.ORIGIN_INVOKER );
  	    if( debug > 0)
  		log( "Added mapping " + wrapper +
  		     " path=" + newServletPath + "/*" );
  	} catch( TomcatException ex ) {
  	    ex.printStackTrace();
  	    return 404;
  	}
  
  	req.setWrapper( wrapper );
  	return 0;
      }
      
  
  }
  
  
  
  1.5       +0 -6      jakarta-tomcat/src/share/org/apache/tomcat/session/StandardSessionInterceptor.java
  
  Index: StandardSessionInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardSessionInterceptor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StandardSessionInterceptor.java	2000/06/20 00:17:45	1.4
  +++ StandardSessionInterceptor.java	2000/06/20 19:22:54	1.5
  @@ -221,10 +221,4 @@
   	    throw new TomcatException( ex );
   	}
       }
  -
  -
  -    private void log( String s ) {
  -	System.out.println("StandardSessionInterceptor: " + s );
  -    }
  -
   }
  
  
  
  1.7       +35 -2     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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- EmbededTomcat.java	2000/06/20 00:17:46	1.6
  +++ EmbededTomcat.java	2000/06/20 19:22:57	1.7
  @@ -182,13 +182,26 @@
   	}
       }
   
  +    Hashtable extraClassPaths=new Hashtable();
   
       /** The application may want to add an application-specific path
   	to the context.
       */
  -    public void addClassPath( ServletContext ctx, String cpath ) {
  -	if(debug>-1) log( "addClassPath " + ctx.getRealPath("") + " " +
  +    public void addClassPath( ServletContext context, String cpath ) {
  +	if(debug>-1) log( "addClassPath " + context.getRealPath("") + " " +
   			  cpath );
  +
  +	try {
  +	    Vector cp=(Vector)extraClassPaths.get(context);
  +	    if( cp == null ) {
  +		cp=new Vector();
  +		extraClassPaths.put( context, cp );
  +	    }
  +	    cp.addElement( cpath );
  +	} catch( Exception ex ) {
  +	    ex.printStackTrace();
  +	}
  +	
   	// XXX This functionality can be achieved by setting it in the parent
   	// class loader ( i.e. the loader that is used to load tomcat ).
   
  @@ -219,6 +232,22 @@
   	    }
   	    Context ctx=facadeM.getRealContext( sctx );
   	    contextM.initContext( ctx );
  +
  +	    ServletLoader sl=ctx.getServletLoader();
  +	    System.out.println("ServletLoader: " + sl );
  +	    Object pd=ctx.getProtectionDomain();
  +	    System.out.println("Ctx.pd " + pd);
  +
  +	    // Add any extra cpaths
  +	    Vector cp=(Vector)extraClassPaths.get( sctx );
  +	    if( cp!=null ) {
  +		for( int i=0; i<cp.size(); i++ ) {
  +		    String cpath=(String)cp.elementAt(i);
  +		    sl.addRepository( new File(cpath), pd);
  +		}
  +	    }
  +
  +
   	} catch( Exception ex ) {
   	    ex.printStackTrace();
   	}
  @@ -321,6 +350,10 @@
   	SimpleMapper1 mapI=new SimpleMapper1();
   	addRequestInterceptor( mapI );
   	mapI.setDebug(20);
  +
  +	InvokerInterceptor invI=new InvokerInterceptor();
  +	addRequestInterceptor( invI );
  +	invI.setDebug(20);
   	
   	addRequestInterceptor( new StandardSessionInterceptor());
   	
  
  
  

Mime
View raw message