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/25 19:17:52 UTC

cvs commit: jakarta-tomcat/src/facade23/org/apache/tomcat/facade23 HttpServletRequestFacade.java HttpServletResponseFacade.java HttpSessionFacade.java

costin      00/09/25 10:17:52

  Modified:    .        build.xml
               src/facade23/org/apache/tomcat/facade23
                        HttpServletRequestFacade.java
                        HttpServletResponseFacade.java
                        HttpSessionFacade.java
  Added:       bin      servlet22.jar servlet23.jar
  Log:
  Ops, forgot that one too :-)
  
  - fix facade23 ( it compiles and should work 2.2 apps, the new 2.3 features
  need to be implemented - again, I'll try to stay away from this task
  as much as possible, it's better to have a fresh look at facade refactoring )
  
  Added a hack to allow compilation of both facades - checked in binaries.
  I know it's bad, but it's very hard to build tomcat when it requires 2
  different cvs branches that happen to build in the same dir.
  
  I'll try to make changes so that only servlet2.2 needs to be checked in (
  probably it'll not change - it's closed now ), and we can build 2.3
  , but right now I prefere a simpler solution.
  
  ( of course, I'll have to remove them if you -1 it ... )
  
  ( use tomcat-new target to build both !!!! )
  
  Revision  Changes    Path
  1.84      +30 -48    jakarta-tomcat/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/build.xml,v
  retrieving revision 1.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- build.xml	2000/09/25 07:20:03	1.83
  +++ build.xml	2000/09/25 17:17:50	1.84
  @@ -31,32 +31,20 @@
     <property name="jaxp" value="../jaxp1.0.1" />
   
     <!-- ========== Hack for building 2.2 and 2.3 versions ========== -->
  -  <!-- If "servlet23.jar" is defined it will be used to build
  -       a 2.3 container. 
  -       This will go away after we clean up tomcat so it can run both
  -       ( building both is not a problem, but the runtime needs some
  -        classloader tricks and cleanup )
  +  <!-- both servlet-2.2.jar and servlet-2.3.jar are checked in
  +       as binaries - checking out 2 revisions of servletapi and
  +       building is too complex ( plus they use the same directories ).
       -->
  -  <!-- Geting servlet 2.2:
  -       cvs co  jakarta-servletapi; 
  -       ant -Dservletapi.dist=../dist/servletapi dist 
  -  -->
  +
     <property name="servlet22.jar" 
  -    value="../dist/servletapi/lib/servlet.jar"/>
  +    value="bin/servlet22.jar"/>
   
  -  <!-- Geting servlet 2.3: 
  -       cvs co -r SERVLET_23_JSP_12 jakarta-servletapi; 
  -       ant  -Dservletapi.build=../build/servletapi23 -Dservletapi.dist=../dist/servletapi23 dist 
  -
  -       To use the new build system you need to use "ant tomcat-new"
  -  -->
  -  <!-- uncoment this or pass -Dservlet23.jar=... -Dservlet.jar=... params to and if 
  -       you want to build with servlet 2.3 facade
     <property name="servlet23.jar"
  -    value="../dist/servletapi23/lib/servlet.jar" />
  -  <property name="servlet.jar" value="${servlet23.jar}" />
  -    --> 
  +    value="bin/servlet23.jar" />
   
  +  <!-- default servlet.jar, used to compile webapps -->
  +  <!-- we use 2.2 because the api is backward compatible, but it
  +       may have problems in the reverse direction -->
     <property name="servlet.jar" value="${servlet22.jar}" />
   
     <!-- ==================== Initialization - guessing config ========== -->
  @@ -97,15 +85,18 @@
       <copyfile src="${jaxp}/jaxp.jar" dest="${tomcat.build}/lib/jaxp.jar"/>
       <copyfile src="${jaxp}/parser.jar" dest="${tomcat.build}/lib/parser.jar"/>
       
  -    <!-- XXX move it to lib/servlet22. This act as a "default" -->
  +    <!-- This act as a "default", Tomcat3.3 will not load it in
  +         classpath, just a hack to ease the transition
  +     -->
       <copyfile src="${servlet.jar}" dest="${tomcat.build}/lib/servlet.jar"/>
  -    <!-- new dir struct for running both 2.2 and 2.3
  -         <mkdir dir="${tomcat.build}/lib/servlet22"/>
  -         <mkdir dir="${tomcat.build}/lib/servlet23"/>
  -         <copyfile src="${servlet22.jar}" dest="${tomcat.build}/lib/servlet22/servlet22.jar"/>
  -         <copyfile src="${servlet23.jar}" dest="${tomcat.build}/lib/servlet23/servlet23.jar"/>
  -    -->
   
  +    <!-- new dir struct for running both 2.2 and 2.3 -->
  +    <mkdir dir="${tomcat.build}/lib/servlet22"/>
  +    <mkdir dir="${tomcat.build}/lib/servlet23"/>
  +    <copyfile src="${servlet22.jar}" 
  +      dest="${tomcat.build}/lib/servlet22/servlet22.jar"/>
  +    <copyfile src="${servlet23.jar}" 
  +      dest="${tomcat.build}/lib/servlet23/servlet23.jar"/>
   
       <fixcrlf srcdir="${tomcat.build}/bin" includes="**/*.sh" cr="remove"/>
       <fixcrlf srcdir="${tomcat.build}/bin" includes="**/*.bat" cr="add"/>
  @@ -215,7 +206,7 @@
     </target>
   
     <!-- ==================== Servlet 22 (default) implementation ========== -->
  -  <target name="facade22" depends="init" unless="servlet23.jar">
  +  <target name="facade22" depends="init" >
       <javac destdir="${tomcat.build}/classes"
         debug="${debug}" 
         optimize="${optimize}"
  @@ -229,14 +220,14 @@
         </classpath>
         <include name="org/apache/tomcat/facade/**" />    
       </javac>
  -    <jar jarfile="${tomcat.build}/lib/facade.jar"
  +    <jar jarfile="${tomcat.build}/lib/servlet22/facade22.jar"
         basedir="${tomcat.build}/classes" > 
         <include name="org/apache/tomcat/facade/**" /> 
       </jar>
     </target>
   
     <!-- ==================== Servlet 23 (default) implementation ========== -->
  -  <target name="facade23" depends="init" if="servlet23.jar">
  +  <target name="facade23" depends="init" >
       <javac destdir="${tomcat.build}/classes"
         debug="${debug}" 
         optimize="${optimize}"
  @@ -250,7 +241,7 @@
         </classpath>
         <include name="org/apache/tomcat/facade23/**" />    
       </javac>
  -    <jar jarfile="${tomcat.build}/lib/facade.jar"
  +    <jar jarfile="${tomcat.build}/lib/servlet23/facade23.jar"
         basedir="${tomcat.build}/classes" > 
         <include name="org/apache/tomcat/facade23/**" /> 
       </jar>
  @@ -298,7 +289,7 @@
         optimize="${optimize}"
         deprecation="off" >
         <classpath>
  -	<pathelement location="${servlet.jar}" />
  +	<pathelement location="${servlet22.jar}" />
         </classpath>
         <include name="org/apache/jasper/**" />    
       </javac>
  @@ -372,22 +363,13 @@
     <!-- ==================== Build all web applications ==================== -->
   
     <target name="webapps" depends="prepare">
  -    <!-- 
  -    <property name="app.srcBase" value="./src" />
  -    <ant 
  -      antfile="src/etc/ant/webapp.xml" 
  -      target="message" >
  -      <property name="appName" value="prof" />
  -      <property name="tomcat.home" value="${tomcat.build}" />
  -    </ant>
  -    -->
       <!-- Examples -->
       <mkdir dir="${tomcat.build}/webapps/examples"/>
       <copydir src="src/examples" dest="${tomcat.build}/webapps/examples"/>
       <javac srcdir="src/examples/WEB-INF/classes"
         optimize="${optimize}"
         destdir="${tomcat.build}/webapps/examples/WEB-INF/classes"
  -      classpath="${tomcat.build}/classes;${servlet.jar}"/>
  +      classpath="${tomcat.build}/classes;${servlet22.jar}"/>
       <javac srcdir="src/examples/jsp/plugin/applet"
         optimize="${optimize}"
         destdir="${tomcat.build}/webapps/examples/jsp/plugin/applet"/>
  @@ -398,7 +380,7 @@
       <javac srcdir="src/prof/WEB-INF/src"
         optimize="${optimize}"
         destdir="${tomcat.build}/webapps/prof/WEB-INF/classes"
  -      classpath="${tomcat.build}/classes;${servlet.jar}"/>
  +      classpath="${tomcat.build}/classes;${servlet22.jar}"/>
        -->
         <!-- Root context -->
       <mkdir dir="${tomcat.build}/webapps/ROOT"/>
  @@ -407,7 +389,7 @@
       <javac srcdir="src/webpages/WEB-INF/classes"
         optimize="${optimize}"
         destdir="${tomcat.build}/webapps/ROOT/WEB-INF/classes"
  -      classpath="${tomcat.build}/classes;${servlet.jar}"/>
  +      classpath="${tomcat.build}/classes;${servlet22.jar}"/>
   
         <!-- admin context -->
       <mkdir dir="${tomcat.build}/webapps/admin"/>
  @@ -415,7 +397,7 @@
       <javac srcdir="src/admin/WEB-INF/classes"
         optimize="${optimize}"
         destdir="${tomcat.build}/webapps/admin/WEB-INF/classes"
  -      classpath="${tomcat.build}/classes;${servlet.jar}"/>
  +      classpath="${tomcat.build}/classes;${servlet22.jar}"/>
   
     </target>
   
  @@ -432,7 +414,7 @@
       <javac srcdir="src/tests/webpages/WEB-INF/classes"
         optimize="${optimize}"
         destdir="${tomcat.build}/webapps/test/WEB-INF/classes"
  -      classpath="${tomcat.build}/classes;${servlet.jar}"/>
  +      classpath="${tomcat.build}/classes;${servlet22.jar}"/>
       <copydir src="${tomcat.build}/webapps/test" dest="${tomcat.dist}/webapps/test"/>
   
       <jar   jarfile="${tomcat.dist}/webapps/test.war"
  @@ -449,9 +431,9 @@
       <mkdir dir="${tomcat.dist}"/>
       <copydir src="${tomcat.build}" dest="${tomcat.dist}"/>
       <copydir src="src/share/org" dest="${tomcat.dist}/src/org"/>
  -    <copyfile src="${servlet.jar}" dest="${tomcat.dist}/lib/servlet.jar"/>
       <copyfile src="${jaxp}/jaxp.jar" dest="${tomcat.dist}/lib/jaxp.jar"/>
       <copyfile src="${jaxp}/parser.jar" dest="${tomcat.dist}/lib/parser.jar"/>
  +    <copyfile src="${servlet.jar}" dest="${tomcat.dist}/lib/servlet.jar"/>
       <copydir src="src/facade22/org" dest="${tomcat.dist}/src/org"/>
   
       <!-- Add Tomcat internal javadoc -->
  
  
  
  1.1                  jakarta-tomcat/bin/servlet22.jar
  
  	<<Binary file>>
  
  
  1.1                  jakarta-tomcat/bin/servlet23.jar
  
  	<<Binary file>>
  
  
  1.3       +5 -4      jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/HttpServletRequestFacade.java
  
  Index: HttpServletRequestFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/HttpServletRequestFacade.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HttpServletRequestFacade.java	2000/09/24 18:11:25	1.2
  +++ HttpServletRequestFacade.java	2000/09/25 17:17:52	1.3
  @@ -61,6 +61,7 @@
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.helper.RequestUtil;
   import org.apache.tomcat.core.*;
  +import org.apache.tomcat.session.*;
   import java.io.*;
   import java.net.*;
   import java.security.*;
  @@ -393,13 +394,14 @@
       // -------------------- Session --------------------
   
       public HttpSession getSession() {
  -        return (HttpSession)request.getSession(true);
  +        return getSession( true );
       }
   
       /** Create the Facade for session.
        */
       public HttpSession getSession(boolean create) {
  -	HttpSession realSession = (HttpSession)request.getSession( create );
  +	ServerSession realSession = (ServerSession)request.
  +	    getSession( create );
   	// No real session, return null
   	if( realSession == null ) {
   	    if( sessionFacade!= null) sessionFacade.recycle();
  @@ -418,8 +420,7 @@
       public boolean isRequestedSessionIdValid() {
   	// so here we just assume that if we have a session it's,
   	// all good, else not.
  -	HttpSession session = (HttpSession)request.getSession(false);
  -	return (session != null);
  +	return null != request.getSession(false);
       }
   
       /** Adapter - Request uses getSessionIdSource
  
  
  
  1.5       +26 -14    jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/HttpServletResponseFacade.java
  
  Index: HttpServletResponseFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/HttpServletResponseFacade.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- HttpServletResponseFacade.java	2000/09/24 18:11:26	1.4
  +++ HttpServletResponseFacade.java	2000/09/25 17:17:52	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/HttpServletResponseFacade.java,v 1.4 2000/09/24 18:11:26 costin Exp $
  - * $Revision: 1.4 $
  - * $Date: 2000/09/24 18:11:26 $
  + * $Header: /home/cvs/jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/HttpServletResponseFacade.java,v 1.5 2000/09/25 17:17:52 costin Exp $
  + * $Revision: 1.5 $
  + * $Date: 2000/09/25 17:17:52 $
    *
    * ====================================================================
    *
  @@ -109,17 +109,20 @@
       // -------------------- Public methods --------------------
   
       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));
  -	}
  +	// layer costs - this can be avoided, but it's not a
  +	// frequent operation ( for example sc can be reused )
  +	ServerCookie sc=new ServerCookie();
  +	cookie2serverCookie( cookie, sc);
  +	addHeader( CookieTools.getCookieHeaderName(cookie.getVersion()),
  +		   CookieTools.getCookieHeaderValue(sc));
  +	// This shouldn't be done - if the user asks for a specific
  +	// version, only that version should be set !!!
  +// 	if( cookie.getVersion() == 1 ) {
  +// 	    // sc is not reused
  +// 	    sc.setVersion(0);
  +// 	    addHeader( CookieTools.getCookieHeaderName(sc.getVersion()),
  +// 		       CookieTools.getCookieHeaderValue(sc));
  +// 	}
   	// Is it needed ? ( result of refactoring, that's how the code
   	// worked) 
   	//response.addUserCookie(cookie);
  @@ -453,5 +456,14 @@
   
       }
   
  +    private void cookie2serverCookie( Cookie cookie, ServerCookie sc ) {
  +	sc.getName().setString( cookie.getName() );
  +	sc.getValue().setString( cookie.getValue() );
  +	sc.getPath().setString(cookie.getPath());
  +	sc.getDomain().setString( cookie.getDomain());
  +	sc.getComment().setString( cookie.getComment());
  +	sc.setMaxAge( cookie.getMaxAge() );
  +	sc.setSecure( cookie.getSecure());
  +    }
   
   }
  
  
  
  1.2       +109 -13   jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/HttpSessionFacade.java
  
  Index: HttpSessionFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/HttpSessionFacade.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpSessionFacade.java	2000/08/23 04:06:42	1.1
  +++ HttpSessionFacade.java	2000/09/25 17:17:52	1.2
  @@ -89,14 +89,17 @@
    * @author costin@eng.sun.com
    */
   final class HttpSessionFacade implements HttpSession {
  -    HttpSession realSession;
  +    private static StringManager sm =
  +        StringManager.getManager("org.apache.tomcat.resources");
  +    ServerSession realSession;
       
       HttpSessionFacade() {
       }
   
  +    // -------------------- public facade --------------------
       /** Package-level method - accessible only by core
        */
  -    void setRealSession(HttpSession s) {
  +    void setRealSession(ServerSession s) {
    	realSession=s;
        }
   
  @@ -109,11 +112,20 @@
       // -------------------- public facade --------------------
   
       public String getId() {
  -	return realSession.getId();
  +	checkValid();
  +	return realSession.getId().toString();
       }
   
  +    /**
  +     * Return the time when this session was created, in milliseconds since
  +     * midnight, January 1, 1970 GMT.
  +     *
  +     * @exception IllegalStateException if this method is called on an
  +     *  invalidated session
  +     */
       public long getCreationTime() {
  -	return realSession.getCreationTime();
  +	checkValid();
  +	return realSession.getTimeStamp().getCreationTime();
       }
       
       /**
  @@ -127,36 +139,73 @@
       }
       
       public long getLastAccessedTime() {
  -	return realSession.getLastAccessedTime();
  +	checkValid();
  +	return realSession.getTimeStamp().getLastAccessedTime();
       }
   
  +    /**
  +     * Invalidates this session and unbinds any objects bound to it.
  +     *
  +     * @exception IllegalStateException if this method is called on
  +     *  an invalidated session
  +     */
       public void invalidate() {
  -	realSession.invalidate();
  +	checkValid();
  +	ServerSessionManager ssm=realSession.getSessionManager();
  +	ssm.removeSession( realSession );
  +	realSession.removeAllAttributes();
  +	realSession.getTimeStamp().setValid( false );
       }
   
  +    /**
  +     * Return <code>true</code> if the client does not yet know about the
  +     * session, or if the client chooses not to join the session.  For
  +     * example, if the server used only cookie-based sessions, and the client
  +     * has disabled the use of cookies, then a session would be new on each
  +     * request.
  +     *
  +     * @exception IllegalStateException if this method is called on an
  +     *  invalidated session
  +     */
       public boolean isNew() {
  -	return realSession.isNew();
  +	checkValid();
  +	return realSession.getTimeStamp().isNew();
       }
       
       /**
        * @deprecated
        */
       public void putValue(String name, Object value) {
  -	realSession.putValue(name, value);
  +	setAttribute(name, value);
       }
   
       public void setAttribute(String name, Object value) {
  +	checkValid();
  +
  +	ServerSessionManager ssm=realSession.getSessionManager();
  +	// Original code - it's up to session manager to decide
  +	// what it can handle. 
  +	// 	if (ssm.isDistributable() &&
  +	// 	  !(value instanceof Serializable))
  +	// 	    throw new IllegalArgumentException
  +	// 		(sm.getString("standardSession.setAttribute.iae"));
  +	
   	realSession.setAttribute( name, value );
  +	if (value instanceof HttpSessionBindingListener)
  +	    ((HttpSessionBindingListener) value).valueBound
  +		(new HttpSessionBindingEvent( this, name));
  +
       }
   
       /**
        * @deprecated
        */
       public Object getValue(String name) {
  -	return realSession.getValue(name);
  +	return getAttribute(name);
       }
   
       public Object getAttribute(String name) {
  +	checkValid();
   	return realSession.getAttribute(name);
       }
       
  @@ -164,10 +213,24 @@
        * @deprecated
        */
       public String[] getValueNames() {
  -	return realSession.getValueNames();
  +	checkValid();
  +	
  +	Enumeration attrs = getAttributeNames();
  +	String names[] = new String[realSession.getAttributeCount()];
  +	for (int i = 0; i < names.length; i++)
  +	    names[i] = (String)attrs.nextElement();
  +	return names;
       }
   
  +    /**
  +     * Return an <code>Enumeration</code> of <code>String</code> objects
  +     * containing the names of the objects bound to this session.
  +     *
  +     * @exception IllegalStateException if this method is called on an
  +     *  invalidated session
  +     */
       public Enumeration getAttributeNames() {
  +	checkValid();
   	return realSession.getAttributeNames();
       }
   
  @@ -175,18 +238,51 @@
        * @deprecated
        */
       public void removeValue(String name) {
  -	realSession.removeAttribute(name);
  +	removeAttribute(name);
       }
   
  +    /**
  +     * Remove the object bound with the specified name from this session.  If
  +     * the session does not have an object bound with this name, this method
  +     * does nothing.
  +     * <p>
  +     * After this method executes, and if the object implements
  +     * <code>HttpSessionBindingListener</code>, the container calls
  +     * <code>valueUnbound()</code> on the object.
  +     *
  +     * @param name Name of the object to remove from this session.
  +     *
  +     * @exception IllegalStateException if this method is called on an
  +     *  invalidated session
  +     */
       public void removeAttribute(String name) {
  +	checkValid();
  +	Object object=realSession.getAttribute( name );
   	realSession.removeAttribute(name);
  +	if (object instanceof HttpSessionBindingListener) {
  +	    ((HttpSessionBindingListener) object).valueUnbound
  +		(new HttpSessionBindingEvent( this, name));
  +	}
  +
       }
   
       public void setMaxInactiveInterval(int interval) {
  -	realSession.setMaxInactiveInterval( interval );
  +	realSession.getTimeStamp().setMaxInactiveInterval( interval * 1000 );
       }
   
       public int getMaxInactiveInterval() {
  -	return realSession.getMaxInactiveInterval();
  +	checkValid();
  +	// We use long because it's better to do /1000 here than
  +	// every time the internal code does expire
  +	return (int)realSession.getTimeStamp().getMaxInactiveInterval()/1000;
       }
  +
  +    // duplicated code, private
  +    private void checkValid() {
  +	if (!realSession.getTimeStamp().isValid()) {
  +	    throw new IllegalStateException
  +		(sm.getString("standardSession.getAttributeNames.ise"));
  +	}
  +    }
  +
   }