Coverage Report - org.mule.transport.http.HttpSessionHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
HttpSessionHandler
74%
14/19
50%
5/10
2.667
 
 1  
 /*
 2  
  * $Id: HttpSessionHandler.java 10489 2008-01-23 17:53:38Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transport.http;
 12  
 
 13  
 import org.mule.api.MuleException;
 14  
 import org.mule.api.MuleMessage;
 15  
 import org.mule.api.MuleSession;
 16  
 import org.mule.api.transport.SessionHandler;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Iterator;
 20  
 import java.util.List;
 21  
 
 22  
 import org.apache.commons.httpclient.Cookie;
 23  
 import org.apache.commons.logging.Log;
 24  
 import org.apache.commons.logging.LogFactory;
 25  
 
 26  
 /**
 27  
  * Will read and write Http Cookie information to and from the Mule MuleSession
 28  
  */
 29  152
 public class HttpSessionHandler implements SessionHandler
 30  
 {
 31  
 
 32  
     /**
 33  
      * logger used by this class
 34  
      */
 35  152
     protected transient Log logger = LogFactory.getLog(getClass());
 36  
 
 37  
     public void retrieveSessionInfoFromMessage(MuleMessage message, MuleSession session) throws MuleException
 38  
     {
 39  284
         Cookie[] cookies = (Cookie[])message.getProperty(HttpConnector.HTTP_COOKIES_PROPERTY);
 40  284
         if (cookies != null)
 41  
         {
 42  0
             for (int i = 0; i < cookies.length; i++)
 43  
             {
 44  0
                 Cookie cookie = cookies[i];
 45  0
                 session.setProperty(cookie.getName(), cookie.getValue());
 46  0
                 if (logger.isDebugEnabled())
 47  
                 {
 48  0
                     logger.debug("Added cookie to session: " + cookie.toString());
 49  
                 }
 50  
             }
 51  
         }
 52  284
     }
 53  
 
 54  
     public void storeSessionInfoToMessage(MuleSession session, MuleMessage message) throws MuleException
 55  
     {
 56  
         Object name;
 57  
         Object value;
 58  128
         List cookies = new ArrayList();
 59  128
         for (Iterator iterator = session.getPropertyNames(); iterator.hasNext();)
 60  
         {
 61  2
             name = iterator.next();
 62  2
             value = session.getProperty(name);
 63  
             // TODO handle domain, path, secure (https) and expiry
 64  2
             cookies.add(new Cookie(null, name.toString(), value.toString()));
 65  
         }
 66  128
         if (cookies.size() > 0)
 67  
         {
 68  2
             message.setProperty(HttpConnector.HTTP_COOKIES_PROPERTY,
 69  
                 cookies.toArray(new Cookie[cookies.size()]));
 70  
         }
 71  128
     }
 72  
 
 73  
     public String getSessionIDKey()
 74  
     {
 75  284
         return "ID";
 76  
     }
 77  
 }