1 10 11 package org.mule.providers.http; 12 13 import org.apache.commons.httpclient.Cookie; 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 16 import org.mule.umo.UMOException; 17 import org.mule.umo.UMOMessage; 18 import org.mule.umo.UMOSession; 19 import org.mule.umo.provider.UMOSessionHandler; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 31 public class HttpSessionHandler implements UMOSessionHandler 32 { 33 34 37 protected transient Log logger = LogFactory.getLog(getClass()); 38 39 public void retrieveSessionInfoFromMessage(UMOMessage message, UMOSession session) throws UMOException 40 { 41 Cookie[] cookies = (Cookie[])message.getProperty(HttpConnector.HTTP_COOKIES_PROPERTY); 42 if (cookies != null) 43 { 44 for (int i = 0; i < cookies.length; i++) 45 { 46 Cookie cookie = cookies[i]; 47 session.setProperty(cookie.getName(), cookie.getValue()); 48 if (logger.isDebugEnabled()) 49 { 50 logger.debug("Added cookie to session: " + cookie.toString()); 51 } 52 } 53 } 54 } 55 56 public void storeSessionInfoToMessage(UMOSession session, UMOMessage message) throws UMOException 57 { 58 Object name; 59 Object value; 60 List cookies = new ArrayList (); 61 for (Iterator iterator = session.getPropertyNames(); iterator.hasNext();) 62 { 63 name = iterator.next(); 64 value = session.getProperty(name); 65 cookies.add(new Cookie(null, name.toString(), value.toString())); 67 } 68 if (cookies.size() > 0) 69 { 70 message.setProperty(HttpConnector.HTTP_COOKIES_PROPERTY, 71 cookies.toArray(new Cookie[cookies.size()])); 72 } 73 } 74 75 public String getSessionIDKey() 76 { 77 return "ID"; 78 } 79 } 80 | Popular Tags |