You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/01/10 03:52:39 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/session LocalStrings.properties StandardSession.java

craigmcc    00/01/09 18:52:39

  Modified:    src/share/org/apache/tomcat/session LocalStrings.properties
                        StandardSession.java
  Log:
  Complete the implementation of IllegalStateException checks for various
  method calls of the HttpSession() interface, and implement a dummy
  HttpSessionContext object -- the previous application was returning null.
  
  This cleans up seven of the eight Watchdog tests that were failing with
  the initial implementation.  The last one will require an extension to
  Costin's SessionManager interface, to allow the Context to tell the
  SessionManager what the default session timeout (from the deployment
  descriptor) should be.
  
  Revision  Changes    Path
  1.4       +8 -0      jakarta-tomcat/src/share/org/apache/tomcat/session/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/LocalStrings.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocalStrings.properties	2000/01/09 05:44:32	1.3
  +++ LocalStrings.properties	2000/01/10 02:52:38	1.4
  @@ -12,6 +12,14 @@
   standardManager.notStarted=Manager has not yet been started
   standardSession.invalidate.ise=invalidate: Session already invalidated
   standardSession.isNew.ise=isNew: Session already invalidated
  +standardSession.getAttribute.ise=getAttribute: Session already invalidated
  +standardSession.getAttributeNames.ise=getAttributeNames: Session already invalidated
  +standardSession.getCreationTime.ise=getCreationTime: Session already invalidated
  +standardSession.getMaxInactiveInterval.ise=getMaxInactiveInterval: Session already invalidated
  +standardSession.getValueNames.ise=getAttributeNames: Session already invalidated
   standardSession.removeAttribute.ise=removeAttribute: Session already invalidated
   standardSession.setAttribute.ise=setAttribute: Non-serializable attribute
   standardSession.setAttribute.ise=setAttribute: Session already invalidated
  +
  +
  +
  
  
  
  1.2       +109 -5    jakarta-tomcat/src/share/org/apache/tomcat/session/StandardSession.java
  
  Index: StandardSession.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardSession.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardSession.java	2000/01/09 03:23:22	1.1
  +++ StandardSession.java	2000/01/10 02:52:38	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardSession.java,v 1.1 2000/01/09 03:23:22 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/01/09 03:23:22 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardSession.java,v 1.2 2000/01/10 02:52:38 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/01/10 02:52:38 $
    *
    * ====================================================================
    *
  @@ -94,7 +94,7 @@
    * HttpSession view of this instance back to a Session view.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/01/09 03:23:22 $
  + * @version $Revision: 1.2 $ $Date: 2000/01/10 02:52:38 $
    */
   
   final class StandardSession
  @@ -185,6 +185,12 @@
   
   
       /**
  +     * The HTTP session context associated with this session.
  +     */
  +    private static HttpSessionContext sessionContext = null;
  +
  +
  +    /**
        * The current accessed time for this session.
        */
       private long thisAccessedTime = creationTime;
  @@ -288,9 +294,16 @@
        * Return the maximum time interval, in seconds, between client requests
        * before the servlet container will invalidate the session.  A negative
        * time indicates that the session should never time out.
  +     *
  +     * @exception IllegalStateException if this method is called on
  +     *  an invalidated session
        */
       public int getMaxInactiveInterval() {
   
  +	if (!isValid())
  +	    throw new IllegalStateException
  +		(sm.getString("standardSession.getMaxInactiveInterval.ise"));
  +
   	return (this.maxInactiveInterval);
   
       }
  @@ -431,9 +444,16 @@
       /**
        * 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() {
   
  +	if (!isValid())
  +	    throw new IllegalStateException
  +		(sm.getString("standardSession.getCreationTime.ise"));
  +
   	return (this.creationTime);
   
       }
  @@ -448,7 +468,9 @@
        */
       public HttpSessionContext getSessionContext() {
   
  -	return (null);
  +	if (sessionContext == null)
  +	    sessionContext = new StandardSessionContext();
  +	return (sessionContext);
   
       }
   
  @@ -461,9 +483,16 @@
        * <code>null</code> if no object is bound with that name.
        *
        * @param name Name of the attribute to be returned
  +     *
  +     * @exception IllegalStateException if this method is called on an
  +     *  invalidated session
        */
       public Object getAttribute(String name) {
   
  +	if (!isValid())
  +	    throw new IllegalStateException
  +		(sm.getString("standardSession.getAttribute.ise"));
  +
   	return (attributes.get(name));
   
       }
  @@ -472,9 +501,16 @@
       /**
        * 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() {
   
  +	if (!isValid())
  +	    throw new IllegalStateException
  +		(sm.getString("standardSession.getAttributeNames.ise"));
  +
   	return (attributes.keys());
   
       }
  @@ -486,6 +522,9 @@
        *
        * @param name Name of the value to be returned
        *
  +     * @exception IllegalStateException if this method is called on an
  +     *  invalidated session
  +     *
        * @deprecated As of Version 2.2, this method is replaced by
        *  <code>getAttribute()</code>
        */
  @@ -500,11 +539,18 @@
        * Return the set of names of objects bound to this session.  If there
        * are no such objects, a zero-length array is returned.
        *
  +     * @exception IllegalStateException if this method is called on an
  +     *  invalidated session
  +     *
        * @deprecated As of Version 2.2, this method is replaced by
        *  <code>getAttributeNames()</code>
        */
       public String[] getValueNames() {
   
  +	if (!isValid())
  +	    throw new IllegalStateException
  +		(sm.getString("standardSession.getValueNames.ise"));
  +
   	Vector results = new Vector();
   	Enumeration attrs = getAttributeNames();
   	while (attrs.hasMoreElements()) {
  @@ -570,6 +616,9 @@
        * @param name Name to which the object is bound, cannot be null
        * @param value Object to be bound, cannot be null
        *
  +     * @exception IllegalStateException if this method is called on an
  +     *  invalidated session
  +     *
        * @deprecated As of Version 2.2, this method is replaced by
        *  <code>setAttribute()</code>
        */
  @@ -649,7 +698,7 @@
        * @param name Name to which the object is bound, cannot be null
        * @param value Object to be bound, cannot be null
        *
  -     * @excpetion IllegalArgumentException if an attempt is made to add a
  +     * @exception IllegalArgumentException if an attempt is made to add a
        *  non-serializable object in an environment marked distributable.
        * @exception IllegalStateException if this method is called on an
        *  invalidated session
  @@ -762,6 +811,61 @@
   
   
       }
  +
  +
  +}
  +
  +
  +// -------------------------------------------------------------- Private Class
  +
  +
  +/**
  + * This class is a dummy implementation of the <code>HttpSessionContext</code>
  + * interface, to conform to the requirement that such an object be returned
  + * when <code>HttpSession.getSessionContext()</code> is called.
  + *
  + * @author Craig R. McClanahan
  + *
  + * @deprecated As of Java Servlet API 2.1 with no replacement.  The
  + *  interface will be removed in a future version of this API.
  + */
  +
  +final class StandardSessionContext implements HttpSessionContext {
  +
  +
  +    private Vector dummy = new Vector();
  +
  +    /**
  +     * Return the session identifiers of all sessions defined
  +     * within this context.
  +     *
  +     * @deprecated As of Java Servlet API 2.1 with no replacement.
  +     *  This method must return an empty <code>Enumeration</code>
  +     *  and will be removed in a future version of the API.
  +     */
  +    public Enumeration getIds() {
  +
  +	return (dummy.elements());
  +
  +    }
  +
  +
  +    /**
  +     * Return the <code>HttpSession</code> associated with the
  +     * specified session identifier.
  +     *
  +     * @param id Session identifier for which to look up a session
  +     *
  +     * @deprecated As of Java Servlet API 2.1 with no replacement.
  +     *  This method must return null and will be removed in a
  +     *  future version of the API.
  +     */
  +    public HttpSession getSession(String id) {
  +
  +	return (null);
  +
  +    }
  +
   
   
   }