commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From morg...@apache.org
Subject cvs commit: jakarta-commons/latka/src/java/org/apache/commons/latka/jelly RequestTag.java SessionTag.java SuiteTag.java
Date Thu, 10 Oct 2002 19:18:36 GMT
morgand     2002/10/10 12:18:36

  Modified:    latka/src/java/org/apache/commons/latka/jelly
                        RequestTag.java SessionTag.java SuiteTag.java
  Log:
  added session caching and implemented part of request skipping
  
  Revision  Changes    Path
  1.5       +35 -8     jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/RequestTag.java
  
  Index: RequestTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/RequestTag.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RequestTag.java	8 Oct 2002 19:29:01 -0000	1.4
  +++ RequestTag.java	10 Oct 2002 19:18:36 -0000	1.5
  @@ -70,6 +70,7 @@
   import org.apache.commons.latka.LatkaException;
   import org.apache.commons.latka.event.LatkaEventInfo;
   import org.apache.commons.latka.event.RequestErrorEvent;
  +import org.apache.commons.latka.event.RequestSkippedEvent;
   import org.apache.commons.latka.event.RequestSucceededEvent;
   import org.apache.commons.latka.http.Proxy;
   import org.apache.commons.latka.http.Request;
  @@ -98,6 +99,8 @@
       
       protected Request  _request  = null;
       protected Response _response = null;
  +    protected Session  _session  = null;
  +    protected boolean  _requestExecuted = false;
   
       protected static final Category _log = Category.getInstance(RequestTag.class);
   
  @@ -116,6 +119,14 @@
           // may set headers and such
           invokeBody(xmlOutput);
   
  +        LatkaEventInfo listener =
  +            JellyUtils.getInstance().getLatkaEventInfo(getContext());
  +        if (listener.didSessionSucceed(findSession()) == false && 
  +            _requestExecuted == false) {
  +            listener.requestSkipped(new RequestSkippedEvent(createRequest(),null));
  +            return;
  +        }
  +
           // even when there are no validations, we execute the request
           // to make sure the URL is accessible
           
  @@ -123,7 +134,6 @@
           // be created, typically because of a malformed URL
           Response response = getResponse();
   
  -        LatkaEventInfo listener = JellyUtils.getInstance().getLatkaEventInfo(getContext());
           if (listener.didRequestSucceed(_request)) {
               listener.requestSucceeded(new RequestSucceededEvent(
                 response.getRequest(), response));            
  @@ -160,9 +170,7 @@
               }
           }
   
  -        // for now, create a new Session for each request
  -        _log.warn("broken, needs session handling");
  -        Session session = new SessionImpl();
  +        Session session = findSession();
   
           Proxy proxy = null;
           if (proxyHost != null) {
  @@ -178,6 +186,23 @@
           return session.createRequest(_label,url,_method,_httpVersion,_followRedirects,proxy);
       }
   
  +    protected Session findSession() {
  +        if (_session == null) {
  +            SessionTag tag = (SessionTag) findAncestorWithClass(SessionTag.class);
  +            if (tag == null) {
  +                _session = new SessionImpl();
  +            } else {
  +                _session = tag.getSession();
  +            }
  +        }
  +
  +        return _session;
  +    }
  +
  +    public boolean getRequestExecuted() {
  +        return _requestExecuted;
  +    }
  +
       /**
        * The first time this method is called, a live HTTP
        * call will be made to the server, returning null
  @@ -189,7 +214,9 @@
        *                   error creating the Request (unrecoverable)
        */
       public Response getResponse() throws LatkaException {
  -        if (_request == null) {
  +        if (_requestExecuted == false) {
  +            _requestExecuted = true;
  +
               _request = createRequest();
   
               LatkaEventInfo listener = 
  
  
  
  1.11      +31 -3     jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/SessionTag.java
  
  Index: SessionTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/SessionTag.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SessionTag.java	3 Oct 2002 18:10:19 -0000	1.10
  +++ SessionTag.java	10 Oct 2002 19:18:36 -0000	1.11
  @@ -61,9 +61,14 @@
   
   package org.apache.commons.latka.jelly;
   
  +import java.util.Map;
  +
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
   
  +import org.apache.commons.latka.http.Session;
  +import org.apache.commons.latka.http.SessionImpl;
  +
   /**
    *
    * @author  Morgan Delagrange
  @@ -72,6 +77,7 @@
           
       protected String _sessionId = null;
       protected String _label = null;
  +    protected Session _session = null;
   
       /** Creates a new instance of SuiteTag */
       public SessionTag() {
  @@ -84,7 +90,29 @@
        * @throws Exception when any error occurs
        */
       public void doTag(XMLOutput xmlOutput) throws Exception {
  +        _session = findSession(_sessionId);
           invokeBody(xmlOutput);
  +    }
  +
  +    public Session getSession() {
  +        return _session;
  +    }
  +
  +    protected Session findSession(String sessionId) {
  +        if (sessionId == null) {
  +            return new SessionImpl();
  +        }
  +
  +        SuiteTag tag = (SuiteTag) findAncestorWithClass(SuiteTag.class);
  +        Map sessionCache = tag.getSessionCache();
  +        Session cachedSession = (Session) sessionCache.get(sessionId);
  +        if (cachedSession == null) {
  +            Session session = new SessionImpl();
  +            sessionCache.put(sessionId,session);
  +            return session;
  +        } else {
  +            return cachedSession;
  +        }
       }
   
       /**
  
  
  
  1.17      +11 -3     jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/SuiteTag.java
  
  Index: SuiteTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/SuiteTag.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- SuiteTag.java	8 Oct 2002 20:48:38 -0000	1.16
  +++ SuiteTag.java	10 Oct 2002 19:18:36 -0000	1.17
  @@ -61,6 +61,9 @@
   
   package org.apache.commons.latka.jelly;
   
  +import java.util.HashMap;
  +import java.util.Map;
  +
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
   
  @@ -83,6 +86,7 @@
       protected String _label = null;
   
       protected SuiteSettings _settings = null;
  +    protected Map _sessionCache = null;
   
       /** Creates a new instance of SuiteTag */
       public SuiteTag() {
  @@ -124,6 +128,10 @@
   
       public SuiteSettings getSuiteSettings() {
           return _settings;
  +    }
  +
  +    public Map getSessionCache() {
  +        return _sessionCache;
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message