Coverage Report - org.mule.providers.http.HttpSessionHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
HttpSessionHandler
0%
0/19
0%
0/5
2.667
 
 1  
 /*
 2  
  * $Id: HttpSessionHandler.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 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.providers.http;
 12  
 
 13  
 import org.mule.umo.UMOException;
 14  
 import org.mule.umo.UMOMessage;
 15  
 import org.mule.umo.UMOSession;
 16  
 import org.mule.umo.provider.UMOSessionHandler;
 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 Session
 28  
  * 
 29  
  * @author <a href="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
 30  
  * @version $Revision: 7976 $
 31  
  */
 32  0
 public class HttpSessionHandler implements UMOSessionHandler
 33  
 {
 34  
 
 35  
     /**
 36  
      * logger used by this class
 37  
      */
 38  0
     protected transient Log logger = LogFactory.getLog(getClass());
 39  
 
 40  
     public void retrieveSessionInfoFromMessage(UMOMessage message, UMOSession session) throws UMOException
 41  
     {
 42  0
         Cookie[] cookies = (Cookie[])message.getProperty(HttpConnector.HTTP_COOKIES_PROPERTY);
 43  0
         if (cookies != null)
 44  
         {
 45  0
             for (int i = 0; i < cookies.length; i++)
 46  
             {
 47  0
                 Cookie cookie = cookies[i];
 48  0
                 session.setProperty(cookie.getName(), cookie.getValue());
 49  0
                 if (logger.isDebugEnabled())
 50  
                 {
 51  0
                     logger.debug("Added cookie to session: " + cookie.toString());
 52  
                 }
 53  
             }
 54  
         }
 55  0
     }
 56  
 
 57  
     public void storeSessionInfoToMessage(UMOSession session, UMOMessage message) throws UMOException
 58  
     {
 59  
         Object name;
 60  
         Object value;
 61  0
         List cookies = new ArrayList();
 62  0
         for (Iterator iterator = session.getPropertyNames(); iterator.hasNext();)
 63  
         {
 64  0
             name = iterator.next();
 65  0
             value = session.getProperty(name);
 66  
             // TODO handle domain, path, secure (https) and expiry
 67  0
             cookies.add(new Cookie(null, name.toString(), value.toString()));
 68  
         }
 69  0
         if (cookies.size() > 0)
 70  
         {
 71  0
             message.setProperty(HttpConnector.HTTP_COOKIES_PROPERTY,
 72  
                 cookies.toArray(new Cookie[cookies.size()]));
 73  
         }
 74  0
     }
 75  
 
 76  
     public String getSessionIDKey()
 77  
     {
 78  0
         return "ID";
 79  
     }
 80  
 }