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/09/24 20:02:06 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/core Context.java ContextInterceptor.java ContextManager.java FacadeManager.java Handler.java Request.java Response.java

costin      00/09/24 11:02:06

  Modified:    src/share/org/apache/tomcat/core Context.java
                        ContextInterceptor.java ContextManager.java
                        FacadeManager.java Handler.java Request.java
                        Response.java
  Log:
  - Core is now independent of facades, i.e. we have a real layering and
  module separation !!!
  
  - Added deprecate comments to FacadeManager - we know there are better
  ways to get to the real object from trusted webapps, and the 1-1 relation
  between Request-RequestFacade, etc have serious security problems.
  
  - start to use the recyclable ServerCookie. We still need to add code
  like in MimeHeaders to enable recycling. The best solution (IMHO) is to
  transform MimeHeaders in a general-purpose MultiMap ( string -> string[],
  with most elements having only one value ) and start using it not only
  for headers, but for cookies and parameters too. Right now normal header
  processing can be done with 0 GC ( constant memory ), we should extend
   that to all other request components.
  
  Revision  Changes    Path
  1.116     +7 -5      jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java
  
  Index: Context.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v
  retrieving revision 1.115
  retrieving revision 1.116
  diff -u -r1.115 -r1.116
  --- Context.java	2000/08/30 05:15:37	1.115
  +++ Context.java	2000/09/24 18:02:05	1.116
  @@ -69,8 +69,6 @@
   import java.io.*;
   import java.net.*;
   import java.util.*;
  -import javax.servlet.http.*;
  -import javax.servlet.*;
   
   
   /* Right now we have all the properties defined in web.xml.
  @@ -124,7 +122,7 @@
       private String absPath; 
       // internal state / related objects
       private ContextManager contextM;
  -    private ServletContext contextFacade;
  +    private Object contextFacade;
   
       boolean reloadable=true; // XXX change default to false after testing
   
  @@ -190,9 +188,13 @@
   	defaultContainer.setPath( null ); // default container
       }
   
  -    /** Every context is associated with a facade
  +    /** Every context is associated with a facade. We don't know the exact
  +	type of the facade, as a Context can be associated with a 2.2 ...
  +	ServletContext.
  +
  +	I'm not sure if this method is good - it adds deps to upper layers.
        */
  -    public ServletContext getFacade() {
  +    public Object getFacade() {
           if(contextFacade==null )
   	    contextFacade = getFacadeManager().createServletContextFacade( this );
   	return contextFacade;
  
  
  
  1.13      +3 -4      jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java
  
  Index: ContextInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ContextInterceptor.java	2000/08/02 02:17:10	1.12
  +++ ContextInterceptor.java	2000/09/24 18:02:05	1.13
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v 1.12 2000/08/02 02:17:10 costin Exp $
  - * $Revision: 1.12 $
  - * $Date: 2000/08/02 02:17:10 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextInterceptor.java,v 1.13 2000/09/24 18:02:05 costin Exp $
  + * $Revision: 1.13 $
  + * $Date: 2000/09/24 18:02:05 $
    *
    * ====================================================================
    *
  @@ -63,7 +63,6 @@
   
   
   package org.apache.tomcat.core;
  -import javax.servlet.Servlet;
   
   /**
    * Notifications for all context events. 
  
  
  
  1.133     +0 -2      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.132
  retrieving revision 1.133
  diff -u -r1.132 -r1.133
  --- ContextManager.java	2000/09/23 18:39:47	1.132
  +++ ContextManager.java	2000/09/24 18:02:05	1.133
  @@ -65,8 +65,6 @@
   import org.apache.tomcat.request.*;
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.logging.*;
  -import javax.servlet.*;
  -import javax.servlet.http.*;
   import java.io.*;
   import java.net.*;
   import java.util.*;
  
  
  
  1.8       +21 -9     jakarta-tomcat/src/share/org/apache/tomcat/core/FacadeManager.java
  
  Index: FacadeManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/FacadeManager.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- FacadeManager.java	2000/08/27 20:37:29	1.7
  +++ FacadeManager.java	2000/09/24 18:02:05	1.8
  @@ -65,8 +65,6 @@
   import java.net.*;
   import java.security.*;
   import java.util.*;
  -import javax.servlet.*;
  -import javax.servlet.http.*;
   
   // XXX Do we need this ?
   // For the webapp -> core communication we use a Context attribute to
  @@ -79,23 +77,37 @@
   // Removing it will also make things simpler.
   
   /**
  - *   Control for facades - this is the only "gate" between servlets
  - *   and tomcat.
  + *   Used to control for facades - and was the only "gate" between servlets
  + *   and tomcat.core - the layers of tomcat.
  + *  
  + *   DEPRECATED. This was a workaround to allow the refactoring and
  + *   separation of tomcat's layers. As this is finished this will disapear.
  + *   To get the real request in a trusted servlet it's enough to use
  + *   getAttribute(). The uppper layer will use the normal interceptor
  + *   interface to set itself up, and no calls from core to upper layer
  + *   should happen ( or we are still in a mess )
  + * 
  + *   We use Object instead of real interface to delay the binding,
  + *   and to permit multiple "versions" ( ClassLoader + interface ), and
  + *   late binding as part of the context ( where we know the servlet
  + *   facade ). This is another temporary fix to move to the next stage
  + *   without brakning functionality.
  + *
    */
   public interface FacadeManager {
       public static final String FACADE_ATTRIBUTE="org.apache.tomcat.facade";
       
  -    public ServletContext createServletContextFacade(Context ctx);
  +    public Object createServletContextFacade(Context ctx);
       
  -    public Context getRealContext( ServletContext ctx );
  +    public Context getRealContext( Object ctx );
   
  -    public  Request getRealRequest( HttpServletRequest req ); 
  +    public  Request getRealRequest( Object req ); 
   
   
   
  -    public  HttpServletRequest createHttpServletRequestFacade(Request req);
  +    public  Object createHttpServletRequestFacade(Request req);
   
  -    public  HttpServletResponse createHttpServletResponseFacade(Response res);
  +    public  Object createHttpServletResponseFacade(Response res);
   
       /** Create a new handler
        */
  
  
  
  1.14      +0 -7      jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java
  
  Index: Handler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Handler.java	2000/09/10 21:41:08	1.13
  +++ Handler.java	2000/09/24 18:02:05	1.14
  @@ -1,8 +1,4 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v 1.13 2000/09/10 21:41:08 larryi Exp $
  - * $Revision: 1.13 $
  - * $Date: 2000/09/10 21:41:08 $
  - *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -62,14 +58,11 @@
    */ 
   package org.apache.tomcat.core;
   
  -//import org.apache.tomcat.facade.*;
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.logging.*;
   import java.io.*;
   import java.net.*;
   import java.util.*;
  -import javax.servlet.*;
  -import javax.servlet.http.*;
   
   /**
    * The class that will generate the actual response.
  
  
  
  1.59      +50 -35    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.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- Request.java	2000/09/17 06:47:23	1.58
  +++ Request.java	2000/09/24 18:02:05	1.59
  @@ -68,10 +68,7 @@
   import java.net.*;
   import java.security.*;
   import java.util.*;
  -import javax.servlet.*;
  -import javax.servlet.http.*;
   
  -
   /**
    *
    * @author James Duncan Davidson [duncan@eng.sun.com]
  @@ -93,6 +90,7 @@
       // byte->char conversion so we can add the encoding
       // that is known only after header parsing. Work in progress.
       protected MessageBytes schemeMB=new MessageBytes();
  +
       protected MessageBytes methodMB=new MessageBytes();
       protected MessageBytes uriMB=new MessageBytes();
       protected MessageBytes queryMB=new MessageBytes();
  @@ -108,7 +106,6 @@
   
       protected Hashtable attributes = new Hashtable();
       protected MimeHeaders headers;
  -    protected Vector cookies = new Vector();
   
       // Processed information ( redundant ! )
       protected Hashtable parameters = new Hashtable();
  @@ -135,23 +132,24 @@
   
       protected boolean didReadFormData;
       protected boolean didParameters;
  -    protected boolean didCookies;
       // end "Request" variables
   
       // @deprecated
  -    protected HttpServletRequest requestFacade;
  +    protected Object requestFacade;
   
       // Session
       // set by interceptors - the session id
       protected String reqSessionId;
       protected String sessionIdSource;
  +    protected String sessionId;
  +        
       // cache- avoid calling SessionManager for each getSession()
  -    protected HttpSession serverSession;
  +    protected Object serverSession;
   
       protected Handler handler = null;
       Container container;
   
  -    protected ServletInputStream in;
  +    //protected ServletInputStream in;
   
       // sub-request support 
       Request top;
  @@ -163,8 +161,8 @@
       protected String requestURI;
       protected String queryString;
       protected String protocol;
  -    protected String servletName;
       
  +    protected String servletName;
       protected String mappedPath = null;
       protected String contextPath;
       protected String lookupPath; // everything after contextPath before ?
  @@ -305,6 +303,7 @@
   	return contentLength;
       }
   
  +    // XXX XXX POSSIBLE BUG - should trim the charset encoding ( or not ? )
       public String getContentType() {
   	if(contentType != null) return contentType;
   	contentType = getHeader("content-type");
  @@ -414,7 +413,7 @@
       // End hints
   
       // -------------------- Request methods ( high level )
  -    public HttpServletRequest getFacade() {
  +    public Object getFacade() {
   	// some requests are internal, and will never need a
   	// facade - no need to create a new object unless needed.
           if( requestFacade==null ) {
  @@ -445,7 +444,9 @@
       }
   
       public void setJvmRoute(String jvmRoute) {
  -	    this.jvmRoute=jvmRoute;
  +	if( jvmRoute==null || "".equals(jvmRoute))
  +	    this.jvmRoute=null;
  +	this.jvmRoute=jvmRoute;
       }
   
       public String getRequestedSessionId() {
  @@ -463,13 +464,28 @@
       public void setSessionIdSource(String s) {
   	sessionIdSource=s;
       }
  +
  +    public void setSessionId( String id ) {
  +	if( ! response.isIncluded() ) sessionId=id;
  +    }
  +
  +    public String getSessionId() {
  +	return sessionId;
  +    }
   
  -    public void setSession(HttpSession serverSession) {
  -	//	context.log("Request: set session ! ");
  +    /** Set the session associated with this request. This can be
  +	the current session or a new session, set by a session
  +	interceptor.
  +
  +	Important: you also need to set the session id ( this is needed to
  +	cleanly separate the layers, and will be improved soon - the
  +	whole session management will follow after core is done )
  +    */
  +    public void setSession(Object serverSession) {
   	this.serverSession = serverSession;
       }
   
  -    public HttpSession getSession(boolean create) {
  +    public Object getSession(boolean create) {
   	if( serverSession!=null ) {
   	    // if not null, it is validated by the session module
   	    return serverSession;
  @@ -483,32 +499,35 @@
   	    return null;
   	}
   
  -	reqSessionId = serverSession.getId();
  -	response.setSessionId( reqSessionId );
  -
   	return serverSession;
       }
  +
  +    // -------------------- Cookies --------------------
  +    protected Vector cookies = new Vector();
  +    protected boolean didCookies;
   
  -    // --------------------
       public int getCookieCount() {
   	if( ! didCookies ) {
   	    didCookies=true;
  -	    RequestUtil.processCookies( this, cookies );
  +	    RequestUtil.processCookies( this );
   	}
   	return cookies.size();
       }
   
  -    public Cookie getCookie( int idx ) {
  +    public ServerCookie getCookie( int idx ) {
   	if( ! didCookies ) {
  -	    didCookies=true;
  -	    RequestUtil.processCookies( this, cookies );
  +	    getCookieCount(); // will also update the cookies
   	}
  -	return (Cookie)cookies.elementAt(idx);
  +	return (ServerCookie)cookies.elementAt(idx);
       }
   
  -    public Cookie[] getCookies() {
  +    public void addCookie( ServerCookie c ) {
  +	cookies.addElement( c );
  +    }
  +
  +    private ServerCookie[] getCookies() {
   	int count=getCookieCount();
  -	Cookie[] cookieArray = new Cookie[ count ];
  +	ServerCookie[] cookieArray = new ServerCookie[ count ];
   
   	for (int i = 0; i < count; i ++) {
   	    cookieArray[i] = getCookie( i );
  @@ -724,6 +743,7 @@
           pathInfo=null;
           pathTranslatedIsSet=false;
           sessionIdSource = null;
  +	sessionId=null;
   
           // XXX a request need to override those if it cares
           // about security
  @@ -738,7 +758,7 @@
           notAuthenticated=true;
   	userRoles=null;
   	reqRoles=null;
  -	in=null;
  +	//	in=null;
   
   	uriMB.recycle();
   	contextMB.recycle();
  @@ -763,15 +783,10 @@
           return headers.names();
       }
   
  -    public ServletInputStream getInputStream() throws IOException {
  -	// will be removed from here
  -	return getFacade().getInputStream();
  -	// 	if( in==null ) {
  -	// 	    in=new BufferedServletInputStream( this );
  -	// 	    ((BufferedServletInputStream)in).initLimit();
  -	// 	}
  -	//     	return in;
  -    }
  +    // Bad design, use upper layer. We already have doRead()
  +//     public ServletInputStream getInputStream() throws IOException {
  +// 	return getFacade().getInputStream();
  +//     }
   
       public int getServerPort() {
           return serverPort;
  
  
  
  1.36      +14 -37    jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java
  
  Index: Response.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- Response.java	2000/09/14 00:53:59	1.35
  +++ Response.java	2000/09/24 18:02:05	1.36
  @@ -1,8 +1,4 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v 1.35 2000/09/14 00:53:59 larryi Exp $
  - * $Revision: 1.35 $
  - * $Date: 2000/09/14 00:53:59 $
  - *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -67,11 +63,8 @@
   import java.io.*;
   import java.net.*;
   import java.util.*;
  -import javax.servlet.*;
  -import javax.servlet.http.*;
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.helper.*;
  -//import org.apache.tomcat.facade.*;
   import org.apache.tomcat.logging.*;
   
   /**
  @@ -92,13 +85,12 @@
           StringManager.getManager("org.apache.tomcat.resources");
   
       protected Request request;
  -    protected HttpServletResponse responseFacade;
  +    protected Object responseFacade;
   
       protected Vector userCookies = new Vector();
       protected String contentType = DEFAULT_CONTENT_TYPE;
       protected String contentLanguage = null;
       protected String characterEncoding = DEFAULT_CHAR_ENCODING;
  -    protected String sessionId;
       protected int contentLength = -1;
       protected int status = 200;
       private Locale locale = DEFAULT_LOCALE;
  @@ -133,13 +125,14 @@
   	oBuffer=new OutputBuffer( this );
       }
       
  -    public HttpServletResponse getFacade() {
  +    public Object getFacade() {
           if( responseFacade==null ) {
   	    Context ctx= request.getContext();
   	    if( ctx == null ) {
   		ctx=request.getContextManager().getContext("");
   	    }
  -	    responseFacade = ctx.getFacadeManager().createHttpServletResponseFacade(this);
  +	    responseFacade = ctx.getFacadeManager().
  +		createHttpServletResponseFacade(this);
   	}
   	return responseFacade;
       }
  @@ -188,7 +181,6 @@
   	status = 200;
   	usingWriter = false;
   	usingStream = false;
  -	sessionId=null;
   	writer=null;
   	started = false;
   	commited = false;
  @@ -380,32 +372,17 @@
   	// No action.. 
       }
   
  -    public void addCookie(Cookie cookie) {
  -	addHeader( CookieTools.getCookieHeaderName(cookie),
  -			    CookieTools.getCookieHeaderValue(cookie));
  -	if( cookie.getVersion() == 1 ) {
  -	    // add a version 0 header too.
  -	    // XXX what if the user set both headers??
  -	    Cookie c0 = (Cookie)cookie.clone();
  -	    c0.setVersion(0);
  -	    addHeader( CookieTools.getCookieHeaderName(c0),
  -				CookieTools.getCookieHeaderValue(c0));
  -	}
  -	if( ! included ) userCookies.addElement(cookie);
  -    }
  -
  -    public Enumeration getCookies() {
  -	return userCookies.elements();
  -    }
  +//     public void addUserCookie(Object cookie) {
  +// 	if( ! included ) userCookies.addElement(cookie);
  +//     }
  +
  +//     /** All cookies set explicitely by users with addCookie()
  +//      *  - I'm not sure if it's used or needed
  +//      */
  +//     public Enumeration getUserCookies() {
  +// 	return userCookies.elements();
  +//     }
   
  -    public void setSessionId( String id ) {
  -	if( ! included ) sessionId=id;
  -    }
  -
  -    public String getSessionId() {
  -	return sessionId;
  -    }
  -    
       public Locale getLocale() {
           return locale;
       }