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...@apache.org on 2001/03/08 08:23:05 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/core BaseInterceptor.java Request.java

costin      01/03/07 23:23:05

  Modified:    src/share/org/apache/tomcat/core BaseInterceptor.java
                        Request.java
  Log:
  My last change for M2 - replaced the attempted get/setNote with
  get/setInfo.
  
  The hook is intended for lazy evaluation of request informations like
  the encoding and for more flexibility in attributes like the SSL chain.
  
  Tomcat performance is due in part to the lazy evaluation - certain fields
  in request are not used in all requests, and pre-computing them is a waste.
  
  There is another problem - supporting attributes like the SSL chain
  no longer requires the SSL module to set an attribute ( i.e. the chain ),
  but can be delayed until and if the request needs it.
  
  In the case of encoding - while this doesn't change too much in the
  current implementation, it allows modules to provide smarter mechanisms
  to detect the charset and more optimizations.
  
  Revision  Changes    Path
  1.44      +14 -2     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.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- BaseInterceptor.java	2001/03/04 03:31:52	1.43
  +++ BaseInterceptor.java	2001/03/08 07:23:01	1.44
  @@ -253,11 +253,23 @@
   	return 0;
       }
   
  -    public Object getNote( Request request, int id ) {
  +    /** Hook for lazy evaluation of request info.
  +	This provides and uniform mechanism to allow modules to evaluate
  +	certain expensive request attributes/parameters when they are
  +	needed ( if ever ), and allows specialized modules and
  +	better integration with the web server/server modules.
  +
  +	This replaces a number of hard-coded constructs and should
  +	clean up the core for un-needed dependencies, as well as provide
  +	flexibility in key areas as encoding, etc.
  +    */
  +    public Object getInfo( Context ctx, Request request,
  +			   int id, String key ) {
   	return null;
       }
   
  -    public int setNote( Request request, int id, Object obj ) {
  +    public int setInfo( Context ctx, Request request,
  +			int id, String key, Object obj ) {
   	return DECLINED;
       }
   
  
  
  
  1.96      +75 -0     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.95
  retrieving revision 1.96
  diff -u -r1.95 -r1.96
  --- Request.java	2001/02/27 19:10:14	1.95
  +++ Request.java	2001/03/08 07:23:02	1.96
  @@ -76,13 +76,37 @@
   import java.util.Hashtable;
   
   /**
  + * This is a low-level, efficient representation of a server request. Most fields
  + * are GC-free, expensive operations are delayed until the  user code needs the
  + * information.
    *
  + * Most processing is delegated to modules, using a hook mechanism.
  + * 
  + * This class is not intended for user code - it is used internally by tomcat
  + * for processing the request in the most efficient way. Users ( servlets ) can
  + * access the information using a facade, which provides the high-level view
  + * of the request.
  + *
  + * For lazy evaluation, the request uses the getInfo() hook. The following ids
  + * are defined:
  + * <ul>
  + *  <li>req.encoding - returns the request encoding
  + *  <li>req.attribute - returns a module-specific attribute ( like SSL keys, etc ).
  + * </ul>
  + *
  + * Tomcat defines a number of attributes:
  + * <ul>
  + *   <li>"org.apache.tomcat.request" - allows access to the low-level
  + *       request object in trusted applications 
  + * </ul>
  + *
    * @author James Duncan Davidson [duncan@eng.sun.com]
    * @author James Todd [gonzo@eng.sun.com]
    * @author Jason Hunter [jch@eng.sun.com]
    * @author Harish Prabandham
    * @author Alex Cruikshank [alex@epitonic.com]
    * @author Hans Bergsten [hans@gefionsoftware.com]
  + * @author Costin Manolache
    */
   public class Request {
       public static final String SESSIONID_FROM_COOKIE="cookie";
  @@ -219,8 +243,13 @@
   	return context;
       }
   
  +    int encodingInfo;
  +    int attributeInfo;
  +    
       public void setContextManager( ContextManager cm ) {
   	contextM=cm;
  +	encodingInfo=cm.getNote( ContextManager.REQUEST_NOTE,"req.encoding" );
  +	attributeInfo=cm.getNote( ContextManager.REQUEST_NOTE,"req.attribute" );
       }
   
       public ContextManager getContextManager() {
  @@ -356,6 +385,22 @@
   
       public String getCharacterEncoding() {
           if(charEncoding!=null) return charEncoding;
  +
  +	Object result=null;
  +	Context ctx=getContext();
  +	BaseInterceptor reqI[]= ctx.getContainer().
  +	    getInterceptors(Container.H_getInfo);
  +	for( int i=0; i< reqI.length; i++ ) {
  +	    result=reqI[i].getInfo( ctx, this, encodingInfo, null );
  +	    if ( result != null ) {
  +		break;
  +	    }
  +	}
  +	if( result != null ) {
  +	    charEncoding=(String)result;
  +	    return;
  +	}
  +	
           charEncoding = ContentType.getCharsetFromContentType(getContentType());
   	return charEncoding;
       }
  @@ -616,7 +661,23 @@
   	if( value != null )
   	    return value;
   
  +	Object result=null;
  +	Context ctx=getContext();
  +	BaseInterceptor reqI[]= ctx.getContainer().
  +	    getInterceptors(Container.H_getInfo);
  +	for( int i=0; i< reqI.length; i++ ) {
  +	    result=reqI[i].getInfo( ctx, this, attributeInfo, name );
  +	    if ( result != null ) {
  +		break;
  +	    }
  +	}
  +	if( result != null ) {
  +	    return result;
  +	}
  +
   	// allow access to FacadeManager for servlets
  +	// XXX move to module. Don't add any new special case, the hooks should
  +	// be used
   	if(name.equals(ATTRIB_REAL_REQUEST)) {
   	    if( ! context.allowAttribute(name) ) return null;
   	    return this;
  @@ -626,6 +687,20 @@
       }
   
       public void setAttribute(String name, Object value) {
  +	int status=BaseInterceptor.DECLINED;
  +	Context ctx=getContext();
  +	BaseInterceptor reqI[]= ctx.getContainer().
  +	    getInterceptors(Container.H_setInfo);
  +	for( int i=0; i< reqI.length; i++ ) {
  +	    status=reqI[i].setInfo( ctx, this, attributeInfo, name, value );
  +	    if ( status != BaseInterceptor.DECLINED ) {
  +		break;
  +	    }
  +	}
  +	if ( status != BaseInterceptor.DECLINED ) {
  +	    return; // don't set it, the module will manage it
  +	}
  +
   	if(name!=null && value!=null)
   	    attributes.put(name, value);
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, email: tomcat-dev-help@jakarta.apache.org