1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
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 | |
|
28 | |
|
29 | 80 | public class HttpSessionHandler implements UMOSessionHandler |
30 | |
{ |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 80 | protected transient Log logger = LogFactory.getLog(getClass()); |
36 | |
|
37 | |
public void retrieveSessionInfoFromMessage(UMOMessage message, UMOSession session) throws UMOException |
38 | |
{ |
39 | 256 | Cookie[] cookies = (Cookie[])message.getProperty(HttpConnector.HTTP_COOKIES_PROPERTY); |
40 | 256 | 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 | 256 | } |
53 | |
|
54 | |
public void storeSessionInfoToMessage(UMOSession session, UMOMessage message) throws UMOException |
55 | |
{ |
56 | |
Object name; |
57 | |
Object value; |
58 | 126 | List cookies = new ArrayList(); |
59 | 126 | for (Iterator iterator = session.getPropertyNames(); iterator.hasNext();) |
60 | |
{ |
61 | 12 | name = iterator.next(); |
62 | 12 | value = session.getProperty(name); |
63 | |
|
64 | 12 | cookies.add(new Cookie(null, name.toString(), value.toString())); |
65 | |
} |
66 | 126 | if (cookies.size() > 0) |
67 | |
{ |
68 | 12 | message.setProperty(HttpConnector.HTTP_COOKIES_PROPERTY, |
69 | |
cookies.toArray(new Cookie[cookies.size()])); |
70 | |
} |
71 | 126 | } |
72 | |
|
73 | |
public String getSessionIDKey() |
74 | |
{ |
75 | 256 | return "ID"; |
76 | |
} |
77 | |
} |