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/request StaticInterceptor.java
Date Mon, 26 Jun 2000 23:20:50 GMT
costin      00/06/26 16:20:50

  Modified:    src/share/org/apache/tomcat/core ContextManager.java
               src/share/org/apache/tomcat/request StaticInterceptor.java
  Log:
  Fix for welcome-file bug - redirect to the welcome file.
  
  Revision  Changes    Path
  1.98      +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java
  
  Index: ContextManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v
  retrieving revision 1.97
  retrieving revision 1.98
  diff -u -r1.97 -r1.98
  --- ContextManager.java	2000/06/26 21:59:30	1.97
  +++ ContextManager.java	2000/06/26 23:20:49	1.98
  @@ -1015,7 +1015,7 @@
   	errorServlet.service( req, res );
       }
   
  -    public Handler getHandlerForPath( Context ctx, String path ) {
  +    public ServletWrapper getHandlerForPath( Context ctx, String path ) {
   	if( ! path.startsWith( "/" ) ) {
   	    return ctx.getServletByName( path );
   	}
  
  
  
  1.6       +30 -43    jakarta-tomcat/src/share/org/apache/tomcat/request/StaticInterceptor.java
  
  Index: StaticInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/StaticInterceptor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StaticInterceptor.java	2000/06/23 22:18:40	1.5
  +++ StaticInterceptor.java	2000/06/26 23:20:49	1.6
  @@ -121,6 +121,7 @@
   	if( pathInfo==null ) pathInfo="";
   	String absPath=ctx.getRealPath( pathInfo );
   	if( absPath == null ) return 0;
  +	String requestURI=req.getRequestURI();
   
   	if( debug > 0 )
   	    log( "Requested: "  + absPath );
  @@ -144,58 +145,44 @@
   	String welcomeFile = getWelcomeFile(ctx, file);
   	if( debug > 0 )
   	    log( "DefaultServlet: welcome file: "  + welcomeFile);
  -
  -	boolean inInclude=false;// XXX detect if we are included
  -	if( inInclude ) {
  -	    // well, we don't have too much choice here 
  -	    if( welcomeFile == null ) {
  -		// We are in include, need to display
  -		// the dir ( XXX do we need that ?? )
  -		req.setWrapper( ctx.getServletByName( "tomcat.dirHandler") );
  -		if( debug > 0) log( "Dir handler, inInclude");
  -		return 0;
  -	    } else {
  -		if( debug > 0) log( "File handler, inInclude");
  -		req.setNote( realFileNote, absPath + "/" + welcomeFile );
  -		req.setWrapper( ctx.getServletByName( "tomcat.fileHandler")); 
  -		return 0;
  -	    }
  -	}
  -
  -	String requestURI=req.getRequestURI();
   
  +	// Doesn't matter if we are or not in include
   	if( welcomeFile == null  ) {
   	    // normal dir, no welcome. 
   	    req.setWrapper( ctx.getServletByName( "tomcat.dirHandler"));
   	    if( debug > 0) log( "Dir handler");
   	    return 0;
  -	} else {
  -	    if(  pathInfo.endsWith("/")) {
  -		if( debug > 0) log( "File handler " +
  -				    absPath + "/" + welcomeFile);
  -		req.setNote( realFileNote, absPath + "/" + welcomeFile );
  -		req.setWrapper( ctx.getServletByName( "tomcat.fileHandler"));
  -		return 0;
  -	    } else {
  -		// Send redirect to either the welcome file
  -		// or to dir/
  -		String redirectURI=requestURI;
  -		if( ! requestURI.endsWith("/")) {
  -		    redirectURI = redirectURI + "/";
  -		}
  -		if( welcomeFile != null ) {
  -		    if( welcomeFile.startsWith("/")) 
  -			welcomeFile=welcomeFile.substring(1);
  -		    redirectURI=redirectURI + welcomeFile;
  -		}
  -		req.setAttribute("javax.servlet.error.message",
  -				 redirectURI);
  -		if( debug > 0) log( "Redirect " + redirectURI );
  -		return 302;
  -	    }
   	}
  +
  +	// Send redirect to the welcome file.
  +	// This is consistent with other web servers and avoids
  +	// gray areas in the spec - if the welcome file is a jsp,
  +	// what will be the requestPath - if it's the dir, then
  +	// jasper will not work. The original code created a
  +	// RequestDispatcher and the JSP will see an included
  +	// request, but that's not a specified behavior
  +	String redirectURI=null;
  +	redirectURI=concatPath( requestURI, welcomeFile);
  +	req.setAttribute("javax.servlet.error.message",
  +			 redirectURI);
  +	if( debug > 0) log( "Redirect " + redirectURI );
  +	return 302;
       }
   
  +    private static String concatPath( String s1, String s2 ) {
  +	if( s1.endsWith( "/" ) ) {
  +	    if( s2.startsWith( "/" ))
  +		return s1 + s2.substring(1);
  +	    else
  +		return s1 + s2;
  +	} else {
  +	    if( s2.startsWith("/"))
  +		return s1 + s2;
  +	    else
  +		return s1 + "/" + s2;
  +	}
  +    }
  +    
       private String getWelcomeFile(Context context, File dir) {
           Enumeration enum = context.getWelcomeFiles();
   
  
  
  

Mime
View raw message