cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers SimpleMapper1.java

2001-10-05 Thread billbarker

billbarker01/10/05 19:31:10

  Modified:src/share/org/apache/tomcat/modules/generators
ErrorHandler.java
   src/share/org/apache/tomcat/modules/mappers
SimpleMapper1.java
  Log:
  Impove error handling when the user has choosen not to define a ROOT context.
  
  A better solution is to force the definition of DEFAULT@ROOT, but that creates too 
many problems this close to release.  I'm the first to vote to role this back once 
someInterceptor takes responsibilty for DEFAULT@ROOT.
  
  It is very easy (and, it seems common) to setup Tomcat without a ROOT context. This 
caused Tomcat to generate useless exception reports in the log.  With this patch, you 
get the expected 404 response to an un-mappable request.
  
  This fixes Bug #3988
  Reported by: Alex Polverini [EMAIL PROTECTED]
  Reported by: Hans Schmid [EMAIL PROTECTED]
  
  Revision  ChangesPath
  1.20  +20 -0 
jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/ErrorHandler.java
  
  Index: ErrorHandler.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/ErrorHandler.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ErrorHandler.java 2001/09/23 18:17:48 1.19
  +++ ErrorHandler.java 2001/10/06 02:31:10 1.20
  @@ -90,6 +90,26 @@
   
   public void engineInit(ContextManager cm ) {
   }
  +
  +/** Check that we are in a stable state.
  + */
  +public  void engineStart(ContextManager cm )
  + throws TomcatException
  +{
  + /* It is very possible to configure Tomcat without a rootContext.
  +We make certain here that the rootContext is set.  Note that we
  +can't add the context, since we don't have a docRoot.  This one is 
  +only used for error handling.  If somebody subsequently adds a
  +default context, then this one just harmlessly goes to gc 
  +(since it's not part of the app, we don't have to follow Life Cycle)
  + */
  + if(rootContext == null){
  + rootContext = cm.createContext();
  + rootContext.setContextManager(cm);
  + rootContext.setPath();
  + contextInit(rootContext);
  + }
  +}
   
   /** Add default error handlers
*/
  
  
  
  1.12  +9 -3  
jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java
  
  Index: SimpleMapper1.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SimpleMapper1.java2001/09/18 06:48:26 1.11
  +++ SimpleMapper1.java2001/10/06 02:31:10 1.12
  @@ -294,9 +294,15 @@
Container container =(Container)map.
getLongestPrefixMatch(  hostMB, pathMB);

  - if( container == null )
  - throw new RuntimeException( Assertion failed:  +
  - container==null);
  + if( container == null ) {
  + // It is too easy to configure Tomcat w/o a default context
  + // Add this back in when we do better checking
  + //throw new RuntimeException( Assertion failed:  +
  + //  container==null);
  + cm.log(Assertion failed:  +
  +container==null (no Default Context?));
  + return 404;
  + }
   
if(debug0)
cm.log(SM: Prefix match  + pathMB.toString() +  -  +
  
  
  



cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers SimpleMapper1.java

2001-09-18 Thread ccain

ccain   01/09/17 23:48:26

  Modified:src/share/org/apache/tomcat/modules/mappers
SimpleMapper1.java
  Log:
  Typos ...
  
  Revision  ChangesPath
  1.11  +5 -5  
jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java
  
  Index: SimpleMapper1.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SimpleMapper1.java2001/08/26 01:54:26 1.10
  +++ SimpleMapper1.java2001/09/18 06:48:26 1.11
  @@ -67,7 +67,7 @@
   import java.io.*;
   /**
*  This class will set up the data structures used by a simple patern matching
  - *  alghoritm and use it to extract the path components from the request URI.
  + *  algorithm and use it to extract the path components from the request URI.
*
*  This particular implementation does the following:
*  - extract the information that is relevant to matching from the Request
  @@ -357,11 +357,11 @@
*/
   //public int requestMap(Request req) {
// No op. All mapping is done in the first step - it's better because
  - // the alghoritm is more efficient. The only case where those 2 are
  + // the algorithm is more efficient. The only case where those 2 are
// not called togheter is in getContext( path ). 
// 
// We can split it again later if that creates problems - but right
  - // now it's important to have a clear alghoritm. Note that requestMap
  + // now it's important to have a clear algorithm. Note that requestMap
// is _allways_ called after contextMap ( it was asserted in  all
// implementations).

  @@ -465,7 +465,7 @@
   }
   
   
  -/** Prefix and exact mapping alghoritm.
  +/** Prefix and exact mapping algorithm.
*XXX finish factoring out the creation of the map ( right now direct field access 
is
*  used, since the code was just cut out from SimpleMapper).
*  XXX make sure the code is useable as a general path mapper - or at least a 
bridge
  @@ -701,7 +701,7 @@
s=FileUtil.removeLast( s );
}  else {
if( myMap.mapCacheEnabled ) {
  - // XXX implement LRU or another replacement alghoritm
  + // XXX implement LRU or another replacement algorithm
myMap.mapCache.put( path, container );
}
return container;
  
  
  



cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers SimpleMapper1.java

2001-08-25 Thread costin

costin  01/08/25 18:54:26

  Modified:src/share/org/apache/tomcat/modules/mappers
SimpleMapper1.java
  Log:
  Extra check.
  
  Revision  ChangesPath
  1.10  +1 -1  
jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java
  
  Index: SimpleMapper1.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SimpleMapper1.java2001/08/07 12:08:26 1.9
  +++ SimpleMapper1.java2001/08/26 01:54:26 1.10
  @@ -534,7 +534,7 @@
while( en.hasMoreElements() ) {
String s=(String)en.nextElement();
Container ct=(Container)vmap.prefixMappedServlets.get( s );
  - if( ct.getContext() == ctx ) {
  + if( ct!=null  ct.getContext() == ctx ) {
if(debug  0 )
ctx.log( Remove mapping  + s ); 
vmap.prefixMappedServlets.remove( s );
  
  
  



cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers SimpleMapper1.java

2001-07-17 Thread larryi

larryi  01/07/17 07:02:34

  Modified:src/share/org/apache/tomcat/modules/mappers
SimpleMapper1.java
  Log:
  Some corrections for the case insensitive handling.
  
  Revision  ChangesPath
  1.7   +7 -4  
jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java
  
  Index: SimpleMapper1.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SimpleMapper1.java2001/07/16 00:19:46 1.6
  +++ SimpleMapper1.java2001/07/17 14:02:33 1.7
  @@ -568,9 +568,12 @@
   /**
*/
   public void addExactMapping( String host, String path, Object target ) {
  - if( host==null )
  - exactMappedServlets.put( path, target);
  - else {
  +if( host==null ) {
  +if ( ignoreCase )
  +exactMappedServlets.put( path.toLowerCase(), target);
  +else
  +exactMappedServlets.put( path, target);
  +} else {
host=host.toLowerCase();
PrefixMapper vmap=(PrefixMapper)vhostMaps.get( host );
if( vmap == null ) {
  @@ -596,7 +599,6 @@
String host=hostMB.toString();
String path=pathMB.toString();
Object container = null;
  -String s = path;
   
PrefixMapper myMap=null;
if( host!=null ) {
  @@ -621,6 +623,7 @@
if( container!=null ) return container;
}

  +String s = path;
while (s.length() = 0) {
//if(debug8) context.log( Prefix:  + s  );
container = myMap.prefixMappedServlets.get(s);
  
  
  



cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers SimpleMapper1.java

2001-07-15 Thread costin

costin  01/07/15 17:19:46

  Modified:src/share/org/apache/tomcat/modules/mappers
SimpleMapper1.java
  Log:
  Allow case insensitive matching.
  
  This is another big security addition - we already had huge problems with that.
  Note that this fix is done at the lowest level - the mapper - instead of
  requiring each individual servlet/module to do many checks.
  
  It is of course easy to turn this off or on.
  
  Revision  ChangesPath
  1.6   +42 -11
jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java
  
  Index: SimpleMapper1.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SimpleMapper1.java2001/07/02 19:37:54 1.5
  +++ SimpleMapper1.java2001/07/16 00:19:46 1.6
  @@ -62,10 +62,9 @@
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.util.buf.MessageBytes;
   import org.apache.tomcat.util.io.FileUtil;
  -//import org.apache.tomcat.util.PrefixMapper;
   import org.apache.tomcat.util.collections.*;
   import java.util.*;
  -
  +import java.io.*;
   /**
*  This class will set up the data structures used by a simple patern matching
*  alghoritm and use it to extract the path components from the request URI.
  @@ -100,8 +99,11 @@
   // Property for the PrefixMapper - cache the mapping results
   boolean mapCacheEnabled=false;
   
  +
   public SimpleMapper1() {
map=new PrefixMapper();
  + ignoreCase= (File.separatorChar  == '\\');
  + map.setIgnoreCase( ignoreCase );
   }
   
   /*  Support functions  */
  @@ -113,6 +115,17 @@
map.setMapCache( v );
   }
   
  +//  Ingore case 
  +boolean ignoreCase=false;
  +
  +/** Use case insensitive match, for windows and
  + similar platforms
  +*/
  +public void setIgnoreCase( boolean b ) {
  + ignoreCase=b;
  + map.setIgnoreCase( b );
  +}
  +
   /*  Initialization  */
   
   /** Set the context manager. To keep it simple we don't support
  @@ -209,7 +222,10 @@
defC.setNote( ctExtMapNote, eM );
}
// add it to the Container local maps
  - eM.put( path.substring( 1 ), ct );
  + if( ignoreCase )
  + eM.put( path.substring( 1 ).toLowerCase() , ct );
  + else
  + eM.put( path.substring( 1 ), ct );
if(debug0)
log( SM: extension map  + ctxP + / +
 path +   + ct +   );
  @@ -359,6 +375,7 @@
if( extM==null ) return null;
   
// Find the container associated with that extension
  + if( ignoreCase ) extension=extension.toLowerCase();
Container container= (Container)extM.get(extension);
   
if (container == null)
  @@ -460,7 +477,7 @@
   // mappers ( extending this one for example ) using 1.2 collections
   // TreeMap mapCache;
   boolean mapCacheEnabled=false;
  -
  +boolean ignoreCase=false;
   
   public PrefixMapper() {
prefixMappedServlets=new SimpleHashtable();
  @@ -472,6 +489,10 @@
mapCacheEnabled=v;
   }
   
  +public void setIgnoreCase( boolean b ) {
  + ignoreCase=b;
  +}
  +
   /** Remove all mappings matching path
*/
   public void removeAllMappings( String host, Context ctx ) {
  @@ -523,17 +544,24 @@
   /**
*/
   public void addMapping( String host, String path, Object target ) {
  - if( host == null )
  - prefixMappedServlets.put( path, target);
  - else {
  + if( host == null ) {
  + if( ignoreCase )
  + prefixMappedServlets.put( path.toLowerCase(), target);
  + else
  + prefixMappedServlets.put( path, target);
  + } else {
host=host.toLowerCase();
PrefixMapper vmap=(PrefixMapper)vhostMaps.get( host );
if( vmap == null ) {
vmap=new PrefixMapper();
  - vhostMaps.put( host, vmap );
  + vmap.setIgnoreCase( ignoreCase );
  + vhostMaps.put( host, vmap );
vmap.setMapCache( mapCacheEnabled );
}
  - vmap.addMapping( path, target );
  + if( ignoreCase ) 
  + vmap.addMapping( path.toLowerCase(), target );
  + else
  + vmap.addMapping( path, target );
}
   }
   
  @@ -549,7 +577,10 @@
vmap=new PrefixMapper();
vhostMaps.put( host, vmap );
}
  - vmap.addExactMapping( path, target );
  + if( ignoreCase ) 
  + vmap.addExactMapping( path.toLowerCase(), target );
  +  

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers SimpleMapper1.java

2001-07-02 Thread costin

costin  01/07/02 12:37:57

  Modified:src/share/org/apache/tomcat/modules/mappers
SimpleMapper1.java
  Log:
  Fix removeContext, it had a number of big problems when the context was the
  ROOT context.
  
  Many thanks to Remus Jivcu for finding the bug and the cause.
  
  Revision  ChangesPath
  1.5   +13 -4 
jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java
  
  Index: SimpleMapper1.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SimpleMapper1.java2001/06/08 03:08:23 1.4
  +++ SimpleMapper1.java2001/07/02 19:37:54 1.5
  @@ -144,7 +144,7 @@
throws TomcatException
   {
if(debug0) log( Removed from maps );
  - map.removeAllMappings( ctx.getHost(), ctx.getPath());
  + map.removeAllMappings( ctx.getHost(), ctx);
// extension mappings are local to ctx, no need to do something
// about that
   }
  @@ -435,6 +435,7 @@
* @author [EMAIL PROTECTED]
*/
   class PrefixMapper  {
  +private static int debug=1;
   // host - PrefixMapper for virtual hosts
   // hosts are stored in lower case ( the common case )
   SimpleHashtable vhostMaps=new SimpleHashtable();
  @@ -473,7 +474,7 @@
   
   /** Remove all mappings matching path
*/
  -public void removeAllMappings( String host, String path ) {
  +public void removeAllMappings( String host, Context ctx ) {
PrefixMapper vmap=this;
if( host!=null ) {
host=host.toLowerCase();
  @@ -484,15 +485,23 @@
Enumeration en=vmap.prefixMappedServlets.keys();
while( en.hasMoreElements() ) {
String s=(String)en.nextElement();
  - if( s.startsWith( path ))
  + Container ct=(Container)vmap.prefixMappedServlets.get( s );
  + if( ct.getContext() == ctx ) {
  + if(debug  0 )
  + ctx.log( Remove mapping  + s ); 
vmap.prefixMappedServlets.remove( s );
  + }
}

en=vmap.exactMappedServlets.keys();
while( en.hasMoreElements() ) {
String s=(String)en.nextElement();
  - if( s.startsWith( path ))
  + Container ct=(Container)vmap.exactMappedServlets.get( s );
  + if( ct.getContext() == ctx ) {
  + if(debug  0 )
  + ctx.log( Remove mapping  + s ); 
vmap.exactMappedServlets.remove( s );
  + }
}
// reset the cache
mapCache=new SimpleHashtable();
  
  
  



cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers SimpleMapper1.java

2001-06-07 Thread costin

costin  01/06/07 20:08:26

  Modified:src/share/org/apache/tomcat/modules/mappers
SimpleMapper1.java
  Log:
  Added PrefixMapper as an internal class, it is very specific to
  SimpleMapper ( and not used in other modules ). It is also ugly and
  quite slow, so we'll need a new mapper ( now that many things are tuned
  we can see smaller spots ). In any case PrefixMapper doesn't deserve to
  be in tomcat_util.jar.
  
  Revision  ChangesPath
  1.4   +180 -1
jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java
  
  Index: SimpleMapper1.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimpleMapper1.java2001/05/26 17:54:50 1.3
  +++ SimpleMapper1.java2001/06/08 03:08:23 1.4
  @@ -62,7 +62,7 @@
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.util.buf.MessageBytes;
   import org.apache.tomcat.util.io.FileUtil;
  -import org.apache.tomcat.util.PrefixMapper;
  +//import org.apache.tomcat.util.PrefixMapper;
   import org.apache.tomcat.util.collections.*;
   import java.util.*;
   
  @@ -425,3 +425,182 @@
   
   }
   
  +
  +/** Prefix and exact mapping alghoritm.
  + *XXX finish factoring out the creation of the map ( right now direct field access 
is
  + *  used, since the code was just cut out from SimpleMapper).
  + *  XXX make sure the code is useable as a general path mapper - or at least a 
bridge
  + *  can be created between SimpleMapper and a patern matcher like the one in XPath
  + *
  + * @author [EMAIL PROTECTED]
  + */
  +class PrefixMapper  {
  +// host - PrefixMapper for virtual hosts
  +// hosts are stored in lower case ( the common case )
  +SimpleHashtable vhostMaps=new SimpleHashtable();
  +
  +
  +SimpleHashtable prefixMappedServlets;
  +SimpleHashtable exactMappedServlets;
  +
  +// Cache the most recent mappings
  +// Disabled by default ( since we haven't implemented
  +// capacity and remove ). 
  +SimpleHashtable mapCache;
  +// By using TreeMap instead of SimpleMap you go from 143 to 161 RPS
  +// ( at least on my machine )
  +// Interesting - even if SimpleHashtable is faster than Hashtable
  +// most of the time, the average is very close for both - it seems
  +// that while the synchronization in Hashtable is locking, GC have
  +// a chance to work, while in SimpleHashtable case GC creates big
  +// peeks. That will go away with more reuse, so we should use SH.
  +
  +// An alternative to explore after everything works is to use specialized
  +// mappers ( extending this one for example ) using 1.2 collections
  +// TreeMap mapCache;
  +boolean mapCacheEnabled=false;
  +
  +
  +public PrefixMapper() {
  + prefixMappedServlets=new SimpleHashtable();
  + exactMappedServlets=new SimpleHashtable();
  + mapCache=new SimpleHashtable();
  +}
  +
  +public void setMapCache( boolean v ) {
  + mapCacheEnabled=v;
  +}
  +
  +/** Remove all mappings matching path
  + */
  +public void removeAllMappings( String host, String path ) {
  + PrefixMapper vmap=this;
  + if( host!=null ) {
  + host=host.toLowerCase();
  + vmap=(PrefixMapper)vhostMaps.get(host);
  + }
  + 
  + // remove all paths starting with path
  + Enumeration en=vmap.prefixMappedServlets.keys();
  + while( en.hasMoreElements() ) {
  + String s=(String)en.nextElement();
  + if( s.startsWith( path ))
  + vmap.prefixMappedServlets.remove( s );
  + }
  + 
  + en=vmap.exactMappedServlets.keys();
  + while( en.hasMoreElements() ) {
  + String s=(String)en.nextElement();
  + if( s.startsWith( path ))
  + vmap.exactMappedServlets.remove( s );
  + }
  + // reset the cache
  + mapCache=new SimpleHashtable();
  + 
  +}
  +
  +/**
  + */
  +void addMapping( String path, Object target ) {
  + prefixMappedServlets.put( path, target);
  +}
  +
  +/**
  + */
  +void addExactMapping( String path, Object target ) {
  + exactMappedServlets.put( path, target);
  +}
  +
  +/**
  + */
  +public void addMapping( String host, String path, Object target ) {
  + if( host == null )
  + prefixMappedServlets.put( path, target);
  + else {
  + host=host.toLowerCase();
  + PrefixMapper vmap=(PrefixMapper)vhostMaps.get( host );
  + if( vmap == null ) {
  + vmap=new PrefixMapper();
  + vhostMaps.put( host, vmap );
  + vmap.setMapCache( mapCacheEnabled );
  + }
  + vmap.addMapping( path, target );
  + }
  +}
  +
  +/**
  + */
  

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers SimpleMapper1.java

2001-05-26 Thread costin

costin  01/05/26 10:54:50

  Modified:src/share/org/apache/tomcat/modules/mappers
SimpleMapper1.java
  Log:
  Don't decode - it'll be done in postReadRequest.
  
  Revision  ChangesPath
  1.3   +0 -11 
jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java
  
  Index: SimpleMapper1.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleMapper1.java2001/02/20 03:16:52 1.2
  +++ SimpleMapper1.java2001/05/26 17:54:50 1.3
  @@ -245,17 +245,6 @@
*/
   public int contextMap( Request req ) {
MessageBytes pathMB = req.requestURI();
  - if( pathMB.isNull())
  - throw new RuntimeException(ASSERT: null path in request URI);
  - //  if( path.indexOf(?) =0 )
  - //  throw new RuntimeException(ASSERT: ? in requestURI);
  -
  - if (pathMB.indexOf('%') = 0 || pathMB.indexOf( '+' ) = 0) {
  - // XXX rewrite URLDecode to avoid allocation
  - log( Found encoded char - it should have been decoded earlier);
  - pathMB.unescapeURL();
  - // pathMB.setString( RequestUtil.URLDecode(pathMB.toString()) );
  - }
try {
//  String host=null;
MessageBytes hostMB=req.serverName();