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/service/http HttpRequestAdapter.java
Date Tue, 01 Feb 2000 21:39:40 GMT
costin      00/02/01 13:39:40

  Modified:    src/share/org/apache/tomcat/core
                        HttpServletResponseFacade.java RequestImpl.java
                        Response.java ResponseImpl.java
               src/share/org/apache/tomcat/request FixHeaders.java
                        SessionInterceptor.java
               src/share/org/apache/tomcat/service/http
                        HttpRequestAdapter.java
  Log:
  - Removed "error" methods from Response interface, the methods are just
  re-directs to the Error servlet ( the code is in ResponseFacade)
  
  - Removed "systemCookies" - the only system cookie was the session id,
  and it's simpler to use the session id property ( usefull for URL rewriting
  too). SessionInterceptor is now responsable for setting the header ( in
  "beforeBody" ) - that allow non-cookie based session managers to work
  without hardcoded cookie code in Request.
  
  Revision  Changes    Path
  1.3       +20 -6     jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletResponseFacade.java
  
  Index: HttpServletResponseFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletResponseFacade.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HttpServletResponseFacade.java	2000/02/01 07:37:36	1.2
  +++ HttpServletResponseFacade.java	2000/02/01 21:39:38	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletResponseFacade.java,v
1.2 2000/02/01 07:37:36 costin Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/02/01 07:37:36 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletResponseFacade.java,v
1.3 2000/02/01 21:39:38 costin Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/02/01 21:39:38 $
    *
    * ====================================================================
    *
  @@ -151,11 +151,24 @@
       }
   
       public void sendError(int sc) throws IOException {
  -	response.sendError(sc, "No detailed message");
  +	sendError(sc, "No detailed message");
       }
       
       public void sendError(int sc, String msg) throws IOException {
  -	response.sendError(sc, msg);
  +	setStatus( sc );
  +	Request request=response.getRequest();
  +	request.setAttribute("javax.servlet.error.status_code",
  +			     String.valueOf(sc));
  +	request.setAttribute("javax.servlet.error.message", msg);
  +
  +	// XXX need to customize it
  +	Servlet errorP=new org.apache.tomcat.servlets.DefaultErrorPage();
  +	try {
  +	    errorP.service(request.getFacade(),this);
  +	} catch (ServletException ex ) {
  +	    // shouldn't happen!
  +	    ex.printStackTrace();
  +	}
       }
   
       public void sendRedirect(String location)
  @@ -165,7 +178,8 @@
               String msg = sm.getString("hsrf.redirect.iae");
               throw new IllegalArgumentException(msg);
   	}
  -        response.sendRedirect(location);
  +	sendError(HttpServletResponse.SC_MOVED_TEMPORARILY,
  +		  location);
       }
       
       public void setContentLength(int len) {
  
  
  
  1.11      +5 -10     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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RequestImpl.java	2000/02/01 07:37:36	1.10
  +++ RequestImpl.java	2000/02/01 21:39:38	1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java,v
1.10 2000/02/01 07:37:36 costin Exp $
  - * $Revision: 1.10 $
  - * $Date: 2000/02/01 07:37:36 $
  + * $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 $
    *
    * ====================================================================
    *
  @@ -424,13 +424,8 @@
   	// SessionManager is just a repository and doesn't deal with
   	// request internals.
   	// hardcoded - will change!
  -	Cookie cookie = new Cookie(Constants.SESSION_COOKIE_NAME,
  -				   reqSessionId);
  -	cookie.setMaxAge(-1);
  -	cookie.setPath("/");
  -	cookie.setVersion(1);
  -	response.addSystemCookie(cookie);
  -
  +	response.setSessionId( reqSessionId );
  +	
   	return serverSession;
       }
   
  
  
  
  1.13      +21 -10    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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Response.java	2000/02/01 07:37:36	1.12
  +++ Response.java	2000/02/01 21:39:38	1.13
  @@ -137,13 +137,12 @@
   
       public void addCookie(Cookie cookie) ;
   
  -    public void addSystemCookie(Cookie cookie) ;
  -
       public Enumeration getCookies();
   
  -    public Enumeration getSystemCookies();
  -
       // -------------------- Response properties --------------------
  +    // Note: headers are not set when you invoke the methods, but
  +    // later, when final fixHeaders happens ( before sending the body )
  +    
       public Locale getLocale() ;
   
       public void setLocale(Locale locale) ;
  @@ -152,6 +151,8 @@
        */
       public String getCharacterEncoding() ;
   
  +    /** Set content type - this might also set encoding, if specified
  +     */
       public void setContentType(String contentType) ;
   
       public String getContentType();
  @@ -163,20 +164,30 @@
       public void setStatus(int status);
   
       public int getStatus() ;
  -    
  -    // -------------------- Error --------------------
  -    // XXX, not needed, can be in Facade!!
  -    public void sendError(int sc, String msg) throws IOException ;
  -
  -    public void sendRedirect(String location) throws IOException ;
   
  +    /** Will set the session id. The session interceptor might
  +     *  process it and add a Cookie header, and it can be used to
  +     *  rewrite URLs.
  +     *  This replace "system cookies" ( it was the only use for them )
  +     */
  +    public void setSessionId(String sId );
  +    
  +    public String getSessionId( );
  +    
       // -------------------- Internal methods --------------------
  +    /** One-to-one with Facade.
  +     *  You can use HttpResponseFacade.
  +     */
       public HttpServletResponseFacade getFacade() ;
   
  +    /** One-to-one relation with Request
  +     */
       public void setRequest(Request request) ;
       
       public Request getRequest() ;
   
  +    /** Response objects will be pool-able
  +     */
       public void recycle() ;
   
   
  
  
  
  1.11      +10 -30    jakarta-tomcat/src/share/org/apache/tomcat/core/ResponseImpl.java
  
  Index: ResponseImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ResponseImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ResponseImpl.java	2000/02/01 07:37:36	1.10
  +++ ResponseImpl.java	2000/02/01 21:39:39	1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ResponseImpl.java,v
1.10 2000/02/01 07:37:36 costin Exp $
  - * $Revision: 1.10 $
  - * $Date: 2000/02/01 07:37:36 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ResponseImpl.java,v
1.11 2000/02/01 21:39:39 costin Exp $
  + * $Revision: 1.11 $
  + * $Date: 2000/02/01 21:39:39 $
    *
    * ====================================================================
    *
  @@ -85,10 +85,10 @@
       protected Request request;
       protected HttpServletResponseFacade responseFacade;
       protected Vector userCookies = new Vector();
  -    protected Vector systemCookies = new Vector();
       protected String contentType = Constants.ContentType.Default;
       protected String contentLanguage = null;
       protected String characterEncoding = Constants.CharacterEncoding.Default;
  +    protected String sessionId;
       protected int contentLength = -1;
       protected int status = 200;
       private Locale locale = new Locale(Constants.LOCALE_DEFAULT, "");
  @@ -130,7 +130,6 @@
   
       public void recycle() {
   	userCookies.removeAllElements();
  -	systemCookies.removeAllElements();
   	contentType = Constants.ContentType.Default;
           locale = new Locale(Constants.LOCALE_DEFAULT, "");
   	characterEncoding = Constants.CharacterEncoding.Default;
  @@ -139,6 +138,7 @@
   	headers.clear();
   	usingWriter = false;
   	usingStream = false;
  +	sessionId=null;
   	writer=null;
   	out.recycle();
   	started = false;
  @@ -300,14 +300,14 @@
   	return userCookies.elements();
       }
   
  -    public Enumeration getSystemCookies() {
  -	return systemCookies.elements();
  +    public void setSessionId( String id ) {
  +	sessionId=id;
       }
   
  -    public void addSystemCookie(Cookie cookie) {
  -	systemCookies.addElement(cookie);
  +    public String getSessionId() {
  +	return sessionId;
       }
  -
  +    
       public Locale getLocale() {
           return locale;
       }
  @@ -376,26 +376,6 @@
           return status;
       }
   
  -    public void sendError(int sc, String msg) throws IOException {
  -	this.status = sc;
  -	request.setAttribute("javax.servlet.error.status_code",
  -			     String.valueOf(sc));
  -	request.setAttribute("javax.servlet.error.message", msg);
  -
  -	// XXX need to customize it
  -	Servlet errorP=new org.apache.tomcat.servlets.DefaultErrorPage();
  -	try {
  -	    errorP.service(request.getFacade(),getFacade());
  -	} catch (ServletException ex ) {
  -	    // shouldn't happen!
  -	    ex.printStackTrace();
  -	}
  -    }
  -
  -    public void sendRedirect(String location) throws IOException {
  -	sendError(HttpServletResponse.SC_MOVED_TEMPORARILY,
  -		  location);
  -    }
       
       /** Set the response status 
        */ 
  
  
  
  1.2       +1 -18     jakarta-tomcat/src/share/org/apache/tomcat/request/FixHeaders.java
  
  Index: FixHeaders.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/FixHeaders.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FixHeaders.java	2000/02/01 07:37:38	1.1
  +++ FixHeaders.java	2000/02/01 21:39:39	1.2
  @@ -107,25 +107,8 @@
               response.setHeader("Content-Length", Integer.toString(contentLength));
           }
   
  -        // write cookies
  -        Enumeration cookieEnum = null;
  -        cookieEnum = response.getSystemCookies();
  -        while (cookieEnum.hasMoreElements()) {
  -            Cookie c  = (Cookie)cookieEnum.nextElement();
  -            response.addHeader( CookieTools.getCookieHeaderName(c),
  -			       CookieTools.getCookieHeaderValue(c));
  -	    if( c.getVersion() == 1 ) {
  -		// add a version 0 header too.
  -		// XXX what if the user set both headers??
  -		Cookie c0 = (Cookie)c.clone();
  -		c0.setVersion(0);
  -		response.addHeader( CookieTools.getCookieHeaderName(c0),
  -				    CookieTools.getCookieHeaderValue(c0));
  -	    }
  -        }
  -	
   	// XXX duplicated code, ugly
  -        cookieEnum = response.getCookies();
  +        Enumeration cookieEnum = response.getCookies();
           while (cookieEnum.hasMoreElements()) {
               Cookie c  = (Cookie)cookieEnum.nextElement();
               response.addHeader( CookieTools.getCookieHeaderName(c),
  
  
  
  1.6       +16 -0     jakarta-tomcat/src/share/org/apache/tomcat/request/SessionInterceptor.java
  
  Index: SessionInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SessionInterceptor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SessionInterceptor.java	2000/02/01 07:37:38	1.5
  +++ SessionInterceptor.java	2000/02/01 21:39:39	1.6
  @@ -116,6 +116,22 @@
       }
   
       public int beforeBody( Request rrequest, Response response ) {
  +	String reqSessionId = response.getSessionId();
  +	if( reqSessionId==null)
  +	    return 0;
  +	
  +	Cookie cookie = new Cookie("JSESSIONID",
  +				   reqSessionId);
  +	cookie.setMaxAge(-1);
  +	cookie.setPath("/");
  +	cookie.setVersion(1);
  +
  +	response.addHeader( CookieTools.getCookieHeaderName(cookie),
  +			    CookieTools.getCookieHeaderValue(cookie));
  +	cookie.setVersion(0);
  +	response.addHeader( CookieTools.getCookieHeaderName(cookie),
  +			    CookieTools.getCookieHeaderValue(cookie));
  +
   	return 0;
       }
   
  
  
  
  1.6       +4 -4      jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java
  
  Index: HttpRequestAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HttpRequestAdapter.java	2000/01/15 23:30:26	1.5
  +++ HttpRequestAdapter.java	2000/02/01 21:39:40	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java,v
1.5 2000/01/15 23:30:26 costin Exp $
  - * $Revision: 1.5 $
  - * $Date: 2000/01/15 23:30:26 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java,v
1.6 2000/02/01 21:39:40 costin Exp $
  + * $Revision: 1.6 $
  + * $Date: 2000/02/01 21:39:40 $
    *
    * ====================================================================
    *
  @@ -228,7 +228,7 @@
   
   	if (requestErrorCode != 0) {
               try {
  -	        response.sendError(requestErrorCode, msg);
  +	        response.getFacade().sendError(requestErrorCode, msg);
   	    } catch (IOException ioe) {
               }
   
  
  
  

Mime
View raw message