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 | |
|
30 | |
|
31 | |
|
32 | 0 | public class HttpSessionHandler implements UMOSessionHandler |
33 | |
{ |
34 | |
|
35 | |
|
36 | |
|
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 | |
|
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 | |
} |