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

2004-10-03 Thread billbarker
billbarker2004/10/03 11:01:52

  Modified:src/share/org/apache/tomcat/core Request.java
   src/share/org/apache/tomcat/modules/mappers
CoyoteMapper.java
  Log:
  Integrate the MappingData with the Request.
  
  Revision  ChangesPath
  1.120 +11 -1 jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java
  
  Index: Request.java
  ===
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v
  retrieving revision 1.119
  retrieving revision 1.120
  diff -u -r1.119 -r1.120
  --- Request.java  25 Feb 2004 06:45:07 -  1.119
  +++ Request.java  3 Oct 2004 18:01:52 -   1.120
  @@ -30,6 +30,7 @@
   import org.apache.tomcat.util.http.Cookies;
   import org.apache.tomcat.util.http.MimeHeaders;
   import org.apache.tomcat.util.http.Parameters;
  +import org.apache.tomcat.util.http.mapper.MappingData;
   
   /**
* This is a low-level, efficient representation of a server request. Most fields
  @@ -155,6 +156,7 @@
   protected ContextManager contextM;
   protected Context context;
   protected Object requestFacade;
  +protected MappingData mappingData = null;
   
   // Session
   protected String reqSessionId;
  @@ -352,6 +354,14 @@
this.localHost = host;
   }
   
  +public MappingData getMappingData() {
  + if(mappingData == null) {
  + mappingData = new MappingData();
  + mappingData.wrapperPath = servletPathMB;
  + mappingData.pathInfo = pathInfoMB;
  + }
  + return mappingData;
  +}
   
   //  Parameters 
   
  @@ -1045,7 +1055,7 @@
scookies.recycle();

   for( int i=0; i 0)
  + if(debug > 9)
log("Redirecting '"+req+"' to '"+
  - mdata.redirectPath+"'", new Exception());
  + mdata.redirectPath+"'");
res.setHeader("Location", mdata.redirectPath.toString());
return 302;
} 
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2004-08-22 Thread billbarker
billbarker2004/08/22 16:49:22

  Added:   src/share/org/apache/tomcat/modules/mappers
CoyoteMapper.java
  Log:
  Initial version of a Mapper that uses the j-t-c Mapper to perform the actual mapping.
  
  It still needs some tuning (e.g. integrate the MappingData with the Request).
  
  Revision  ChangesPath
  1.1  
jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/CoyoteMapper.java
  
  Index: CoyoteMapper.java
  ===
  /*   
   *  Copyright 1999-2004 The Apache Sofware Foundation.
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *  http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.tomcat.modules.mappers;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.Enumeration;
  import java.util.Hashtable;
  import java.util.Vector;
  
  import org.apache.tomcat.core.BaseInterceptor;
  import org.apache.tomcat.core.Container;
  import org.apache.tomcat.core.Context;
  import org.apache.tomcat.core.ContextManager;
  import org.apache.tomcat.core.Request;
  import org.apache.tomcat.core.Response;
  import org.apache.tomcat.core.TomcatException;
  import org.apache.tomcat.util.buf.MessageBytes;
  import org.apache.tomcat.util.collections.SimpleHashtable;
  import org.apache.tomcat.util.io.FileUtil;
  import org.apache.tomcat.util.http.mapper.Mapper;
  import org.apache.tomcat.util.http.mapper.MappingData;
  
  /**
   *  This class will set up the data structures used by a simple patern matching
   *  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
   *   object. The current implementation deals with the Host header and the
   *   request URI.
   *  - Use an external mapper to find the best match.
   *  - Adjust the request paths
   * 
   *  It will maintain a global mapping structure for all prefix mappings,
   *  including contexts. 
   * 
   *  The execution time is proportional with the number of hosts, number of
   *  context, number of mappings and with the length of the request.
   *
   */
  public class CoyoteMapper extends  BaseInterceptor  {
  
  public static final String DEFAULT_HOST = "DEFAULT";
  Mapper map;
  Hashtable hostData = new Hashtable();
  
  public CoyoteMapper() {
  }
  
  /*  Support functions  */
  
  /*  Initialization  */
  
  /** Set the context manager. To keep it simple we don't support
   *  dynamic add/remove for this interceptor. 
   */
  public void engineInit( ContextManager cm )
throws TomcatException
  {
// set-up a per/container note for maps
map=new Mapper();
map.setDefaultHostName(DEFAULT_HOST);
  }
  
  /** Called when a context is added.
   */
  public void addContext( ContextManager cm, Context ctx )
throws TomcatException
  {
String host = ctx.getHost();
if(host == null) {
host = DEFAULT_HOST;
} else if(hostData.get(host) == null) {
Enumeration vhostAliases=ctx.getHostAliases();
Vector valias = new Vector();
while(vhostAliases.hasMoreElements()) {
valias.addElement(vhostAliases.nextElement());
}
String [] aliasNames = new String[valias.size()];
for(int i=0; i < valias.size(); i++) {
aliasNames[i] = (String)valias.elementAt(i);
}
map.addHost(host, aliasNames, "");
hostData.put(host, valias);
}

map.addContext(host, ctx.getPath(), ctx, ctx.getWelcomeFiles(), null);
// StaticInterceptor doesn't have a Container, so we need to
// add one.  
map.addWrapper(host, ctx.getPath(), "/", ctx.getContainer());
  }
  
  /** Called when a context is removed from a CM - we must ask the mapper to
remove all the maps related with this context
   */
  public void removeContext( ContextManager cm, Context ctx )
throws TomcatException
  {
if(debug>0) log( "Removed from maps ");
String host = ctx.getHost();
if(host == null)
host = DEFAULT_HOST;
map.removeContext(host, ctx.getPath());