private static Transformer encoder = new Base64Encoder();
private static Transformer decoder = new Base64Decoder();
public MuleSession retrieveSessionInfoFromMessage(MuleMessage message) throws MuleException
{
MuleSession session = new DefaultMuleSession();
String sessionId = message.getInboundProperty(MuleProperties.MULE_SESSION_ID_PROPERTY);
Object sessionHeader = message.getInboundProperty(MuleProperties.MULE_SESSION_PROPERTY);
if (sessionId != null)
{
throw new IllegalStateException(
"This session handler does not know how to look up session information for session id: "
+ sessionId);
}
if (sessionHeader != null)
{
String sessionString;
try
{
sessionString = new String((byte[]) decoder.transform(sessionHeader), message.getEncoding());
}
catch (UnsupportedEncodingException e)
{
sessionString = new String((byte[]) decoder.transform(sessionHeader));
}
if (logger.isDebugEnabled())
{
logger.debug("Parsing session header: " + sessionString);
}
String pair;
String name;
String value;
for (StringTokenizer stringTokenizer = new StringTokenizer(sessionString, ";"); stringTokenizer.hasMoreTokens();)
{
pair = stringTokenizer.nextToken();
int i = pair.indexOf("=");
if (i == -1)
{
throw new IllegalArgumentException(
CoreMessages.sessionValueIsMalformed(pair).toString());
}
name = pair.substring(0, i).trim();
value = pair.substring(i + 1).trim();
session.setProperty(name, value);
if (logger.isDebugEnabled())
{
logger.debug("Added MuleSession variable: " + pair);
}
}