You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/02/01 23:53:33 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util RequestUtil.java

costin      00/02/01 14:53:33

  Modified:    src/share/org/apache/tomcat/core
                        HttpServletRequestFacade.java JspWrapper.java
                        Request.java RequestImpl.java
               src/share/org/apache/tomcat/request SimpleMapper.java
               src/share/org/apache/tomcat/service
                        Ajp11ConnectionHandler.java
               src/share/org/apache/tomcat/service/connector
                        Ajp12ConnectionHandler.java
               src/share/org/apache/tomcat/util RequestUtil.java
  Log:
  Request simplifications ( still far from Catalina Request, but a bit closer)
  
  - updatePaths moved in Mapper, where it belongs
  - conversion from string to int done in Facade, no need in Request
  - Moved String2Date from HeaderField to RequestUtil, that avoid creating 1 calendar
  per header ( >5% in OptimizeIt)
  - removed getRequestDispather from Request, it was just an indirection from Facade.
  
  Revision  Changes    Path
  1.6       +29 -7     jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletRequestFacade.java
  
  Index: HttpServletRequestFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletRequestFacade.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HttpServletRequestFacade.java	2000/01/11 20:43:02	1.5
  +++ HttpServletRequestFacade.java	2000/02/01 22:53:30	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletRequestFacade.java,v 1.5 2000/01/11 20:43:02 costin Exp $
  - * $Revision: 1.5 $
  - * $Date: 2000/01/11 20:43:02 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletRequestFacade.java,v 1.6 2000/02/01 22:53:30 costin Exp $
  + * $Revision: 1.6 $
  + * $Date: 2000/02/01 22:53:30 $
    *
    * ====================================================================
    *
  @@ -137,7 +137,15 @@
       }
   
       public long getDateHeader(String name) {
  -        return request.getDateHeader(name);
  +	String value=request.getHeader( name );
  +	if( value==null) return -1;
  +	
  +	long date=RequestUtil.toDate(value);
  +	if( date==-1) {
  +	    String msg = sm.getString("httpDate.pe", value);
  +	    throw new IllegalArgumentException(msg);
  +	}
  +	return date;
       }
       
       public String getHeader(String name) {
  @@ -161,9 +169,15 @@
   	usingStream = true;
   	return request.getInputStream();
       }
  +
  +    public int getIntHeader(String name)
  +	throws  NumberFormatException
  +    {
  +	String value=request.getHeader( name );
  +	if( value==null) return -1;
   
  -    public int getIntHeader(String name) {
  -        return request.getIntHeader(name);
  +	int valueInt=Integer.parseInt(value);
  +	return valueInt;
       }
       
       public String getMethod() {
  @@ -254,7 +268,15 @@
       }
   
       public RequestDispatcher getRequestDispatcher(String path) {
  -	return request.getRequestDispatcher(path);
  +        if (path == null)
  +	    return null;
  +
  +	if (! path.startsWith("/")) {
  +	    path= FileUtil.catPath( request.getLookupPath(), path );
  +	    if( path==null) return null;
  +	}
  +
  +	return request.getContext().getRequestDispatcher(path);
       }
   
       public boolean isSecure() {
  
  
  
  1.3       +3 -4      jakarta-tomcat/src/share/org/apache/tomcat/core/JspWrapper.java
  
  Index: JspWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/JspWrapper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JspWrapper.java	2000/01/15 23:30:20	1.2
  +++ JspWrapper.java	2000/02/01 22:53:31	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/JspWrapper.java,v 1.2 2000/01/15 23:30:20 costin Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/01/15 23:30:20 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/JspWrapper.java,v 1.3 2000/02/01 22:53:31 costin Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/02/01 22:53:31 $
    *
    * ====================================================================
    *
  @@ -154,7 +154,6 @@
   			     Constants.JSP.Directive.Compile.Value );
   	
   	request.setContext(context);
  -	request.updatePaths();
   	request.getSession(true);
   	
   	RequestDispatcher rd =
  
  
  
  1.24      +15 -19    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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Request.java	2000/02/01 07:37:36	1.23
  +++ Request.java	2000/02/01 22:53:31	1.24
  @@ -102,21 +102,13 @@
   
       public Enumeration getHeaderNames() ;
       
  -    public MimeHeaders getMimeHeaders();
  -
  -    public long getDateHeader(String name) ;
  -
       public Enumeration getHeaders(String name) ;
   
  -    public int getIntHeader(String name)  ;
  -
       //-------------------- "Computed" properties --------------------
       // ( directly derived from headers or request paths )
   
       /** Return the cookies
        */
  -    public String[] getCookieHeaders();
  -
       public Cookie[] getCookies() ;
   
       public int getContentLength() ;
  @@ -134,6 +126,10 @@
       // -------------------- Mapping --------------------
       // Will be set by mappers
       
  +    public void setContext(Context context) ;
  +
  +    public Context getContext() ;
  +
       public String getContextPath();
   
       public String getServletName();
  @@ -154,11 +150,10 @@
   
       public String getServletPath() ;
   
  -    public void updatePaths() ;//XXX - not to be used, use RD
  -
       public String getResolvedServlet() ;
   
       public void setResolvedServlet(String rs ) ;
  +
       public ServletWrapper getWrapper() ;
       
       public void setWrapper(ServletWrapper handler) ;
  @@ -176,6 +171,7 @@
   
       // -------------------- Security --------------------
       // Will be set by security interceptors
  +
       public String getAuthType() ;
   
       public void setAuthType(String authType) ;
  @@ -225,6 +221,7 @@
       
       // -------------------- Attributes --------------------
       public Object getAttribute(String name) ;
  +
       public void setAttribute(String name, Object value) ;
   
       public void removeAttribute(String name) ;
  @@ -247,21 +244,20 @@
       // inteface is to implement it on top of doRead(b[]).
       // Don't use this method if you can ( it is bad for performance !!)
       public int doRead() throws IOException;
  -    
   
       // -------------------- Internal methods --------------------
  +    /** Support for "pools"
  +     */
       public void recycle() ;
   
  +    /** One-to-One with Response
  +     */
       public Response getResponse() ;
   
  -    public void setContext(Context context) ;
  -
  -    public HttpServletRequestFacade getFacade() ;
  -
       public void setResponse(Response response) ;
   
  -    public Context getContext() ;
  -
  -    public RequestDispatcher getRequestDispatcher(String path);
  -
  +    /** One-to-One with Facade
  +     */
  +    public HttpServletRequestFacade getFacade() ;
  +    
   }
  
  
  
  1.12      +4 -57     jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java
  
  Index: RequestImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- RequestImpl.java	2000/02/01 21:39:38	1.11
  +++ RequestImpl.java	2000/02/01 22:53:31	1.12
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java,v 1.11 2000/02/01 21:39:38 costin Exp $
  - * $Revision: 1.11 $
  - * $Date: 2000/02/01 21:39:38 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java,v 1.12 2000/02/01 22:53:31 costin Exp $
  + * $Revision: 1.12 $
  + * $Date: 2000/02/01 22:53:31 $
    *
    * ====================================================================
    *
  @@ -232,7 +232,7 @@
   
       public int getContentLength() {
           if( contentLength > -1 ) return contentLength;
  -	contentLength = getIntHeader("content-length");
  +	contentLength = getFacade().getIntHeader("content-length");
   	return contentLength;
       }
   
  @@ -281,19 +281,6 @@
   	return context.getRequestSecurityProvider().isSecure(context, getFacade());
       }
   
  -    public RequestDispatcher getRequestDispatcher(String path) {
  -        if (path == null)
  -	    return null;
  -
  -	if (! path.startsWith("/")) {
  -	    path= FileUtil.catPath( getLookupPath(), path );
  -	    if( path==null) return null;
  -	}
  -
  -	return context.getRequestDispatcher(path);
  -    }
  -
  -
       public Principal getUserPrincipal() {
   	if( context.getRequestSecurityProvider() == null )
   	    return null;
  @@ -355,30 +342,6 @@
   	this.context = context;
       }
   
  -    // Called after a Context is found, adjust all other paths.
  -    // XXX XXX XXX
  -    public void updatePaths() {
  -	contextPath = context.getPath();
  -	String requestURI = getRequestURI();
  -	// do not set it if it is already set or we have no
  -	// URI - the case of a sub-request generated internally
  -	if( requestURI!=null && lookupPath==null ) 
  -	    lookupPath = requestURI.substring(contextPath.length(),
  -					      requestURI.length());
  -
  -	// check for ? string on lookuppath
  -	int qindex = lookupPath.indexOf("?");
  -
  -	if (qindex > -1) {
  -	    lookupPath = lookupPath.substring(0, qindex);
  -	}
  -
  -	if (lookupPath.length() < 1) {
  -	    lookupPath = "/";
  -	}
  -    }
  -
  -
       public Cookie[] getCookies() {
   	// XXX need to use Cookie[], Vector is not needed
   	if( ! didCookies ) {
  @@ -559,22 +522,12 @@
       // End Attributes
   
       // -------------------- Facade for MimeHeaders
  -    public long getDateHeader(String name) {
  -	//return reqA.getMimeHeaders().getDateHeader(name);
  -	return getMimeHeaders().getDateHeader(name);
  -    }
  -
       public Enumeration getHeaders(String name) {
   	//	Vector v = reqA.getMimeHeaders().getHeadersVector(name);
   	Vector v = getMimeHeaders().getHeadersVector(name);
   	return v.elements();
       }
   
  -    public int getIntHeader(String name)  {
  -	//        return reqA.getMimeHeaders().getIntHeader(name);
  -        return getMimeHeaders().getIntHeader(name);
  -    }
  -
       // -------------------- Utils - facade for RequestUtil
       public BufferedReader getReader()
   	throws IOException {
  @@ -675,12 +628,6 @@
       // Hints = return null if you don't know,
       // and Tom will find the value. You can also use the static
       // methods in RequestImpl
  -
  -    /** Return the parsed Cookies
  -     */
  -    public String[] getCookieHeaders() {
  -	return null;
  -    }
   
       // server may have it pre-calculated - return null if
       // it doesn't
  
  
  
  1.4       +21 -1     jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleMapper.java
  
  Index: SimpleMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleMapper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimpleMapper.java	2000/02/01 07:37:38	1.3
  +++ SimpleMapper.java	2000/02/01 22:53:31	1.4
  @@ -111,7 +111,27 @@
   	String pathInfo =path.substring(ctxPath.length(),
   					    path.length());
   	rrequest.setContext(ctx);
  -	rrequest.updatePaths();
  +
  +	String lookupPath=rrequest.getLookupPath();
  +
  +	// do not set it if it is already set or we have no
  +	// URI - the case of a sub-request generated internally
  +	if( path!=null && lookupPath==null ) 
  +	    lookupPath= path.substring(ctxPath.length(),
  +				       path.length());
  +
  +	// check for ? string on lookuppath
  +	int qindex = lookupPath.indexOf("?");
  +	
  +	if (qindex > -1) {
  +	    lookupPath=lookupPath.substring(0, qindex);
  +	}
  +	
  +	if (lookupPath.length() < 1) {
  +	    lookupPath = "/";
  +	}
  +
  +	rrequest.setLookupPath( lookupPath );
   	return OK;
       }
   
  
  
  
  1.14      +4 -4      jakarta-tomcat/src/share/org/apache/tomcat/service/Ajp11ConnectionHandler.java
  
  Index: Ajp11ConnectionHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/Ajp11ConnectionHandler.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Ajp11ConnectionHandler.java	2000/02/01 07:37:38	1.13
  +++ Ajp11ConnectionHandler.java	2000/02/01 22:53:32	1.14
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/Ajp11ConnectionHandler.java,v 1.13 2000/02/01 07:37:38 costin Exp $
  - * $Revision: 1.13 $
  - * $Date: 2000/02/01 07:37:38 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/Ajp11ConnectionHandler.java,v 1.14 2000/02/01 22:53:32 costin Exp $
  + * $Revision: 1.14 $
  + * $Date: 2000/02/01 22:53:32 $
    *
    * ====================================================================
    *
  @@ -130,7 +130,7 @@
   
   	    // resolve the server that we are for
   
  -	    int contentLength = reqA.getIntHeader("content-length");
  +	    int contentLength = reqA.getFacade().getIntHeader("content-length");
   	    if (contentLength != -1) {
   		BufferedServletInputStream sis =
   		    (BufferedServletInputStream)reqA.getInputStream();
  
  
  
  1.10      +2 -1      jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp12ConnectionHandler.java
  
  Index: Ajp12ConnectionHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp12ConnectionHandler.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Ajp12ConnectionHandler.java	2000/02/01 07:37:38	1.9
  +++ Ajp12ConnectionHandler.java	2000/02/01 22:53:32	1.10
  @@ -136,7 +136,8 @@
   
   	    // resolve the server that we are for
   
  -	    int contentLength = reqA.getIntHeader("content-length");
  +	    // XXX is this needed ?? 
  +	    int contentLength = reqA.getFacade().getIntHeader("content-length");
   	    if (contentLength != -1) {
   		BufferedServletInputStream sis =
   		    (BufferedServletInputStream)reqA.getInputStream();
  
  
  
  1.7       +64 -0     jakarta-tomcat/src/share/org/apache/tomcat/util/RequestUtil.java
  
  Index: RequestUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/RequestUtil.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RequestUtil.java	2000/01/13 15:10:44	1.6
  +++ RequestUtil.java	2000/02/01 22:53:32	1.7
  @@ -66,6 +66,7 @@
   import java.util.*;
   import javax.servlet.*;
   import javax.servlet.http.*;
  +import java.text.*;
   
   /**
    * Usefull methods for request processing. Used to be in ServerRequest or Request,
  @@ -445,4 +446,67 @@
           return l.elements();
       }
   
  +
  +
  +    /* -------------------- From HttpDate -------------------- */
  +    // Parse date - XXX This code is _very_ slow ( 3 parsers, GregorianCalendar,
  +    // etc ). It was moved out to avoid creating 1 Calendar instance ( and
  +    // a associated parsing ) per header ( the Calendar was created in HttpDate
  +    // which was created for each HeaderField ).
  +    // This also avoid passing HttpHeaders - which was required to access
  +    // HttpHeaderFiled to access HttpDate to access the parsing code.
  +    
  +    // we force our locale here as all http dates are in english
  +    private final static Locale loc = Locale.US;
  +
  +    // all http dates are expressed as time at GMT
  +    private final static TimeZone zone = TimeZone.getTimeZone("GMT");
  +
  +    // format for RFC 1123 date string -- "Sun, 06 Nov 1994 08:49:37 GMT"
  +    private final static String rfc1123Pattern ="EEE, dd MMM yyyyy HH:mm:ss z";
  +
  +    // format for RFC 1036 date string -- "Sunday, 06-Nov-94 08:49:37 GMT"
  +    private final static String rfc1036Pattern ="EEEEEEEEE, dd-MMM-yy HH:mm:ss z";
  +
  +    // format for C asctime() date string -- "Sun Nov  6 08:49:37 1994"
  +    private final static String asctimePattern ="EEE MMM d HH:mm:ss yyyyy";
  +    
  +    private final static SimpleDateFormat rfc1123Format =
  +	new SimpleDateFormat(rfc1123Pattern, loc);
  +    
  +    private final static SimpleDateFormat rfc1036Format =
  +	new SimpleDateFormat(rfc1036Pattern, loc);
  +    
  +    private final static SimpleDateFormat asctimeFormat =
  +	new SimpleDateFormat(asctimePattern, loc);
  +
  +    public static long toDate( String dateString ) {
  +	// XXX
  +	Date date=null;
  +	try {
  +            date = rfc1123Format.parse(dateString);
  +	} catch (ParseException e) { }
  +	
  +        if( date==null)
  +	    try {
  +		date = rfc1036Format.parse(dateString);
  +	    } catch (ParseException e) { }
  +	
  +        if( date==null)
  +	    try {
  +		date = asctimeFormat.parse(dateString);
  +	    } catch (ParseException pe) {
  +	    }
  +
  +	if(date==null) {
  +	    return -1;
  +	}
  +
  +	// Original code was: 
  +	//	Calendar calendar = new GregorianCalendar(zone, loc);
  +	//calendar.setTime(date);
  +	// calendar.getTime().getTime();
  +	return date.getTime();
  +    }
  +    
   }