*
* @see AbstractEndpoint#setupFlexClient(String)
*/
public FlexClient setupFlexClient(String id)
{
FlexClient flexClient = super.setupFlexClient(id);
// Scan for duplicate HTTP-sessions and if found, invalidate them and throw a MessageException.
// A request attribute is used to deal with batched AMF messages that arrive in a single request by trigger multiple passes through this method.
boolean duplicateSessionDetected = (FlexContext.getHttpRequest().getAttribute(REQUEST_ATTR_DUPLICATE_SESSION_FLAG) != null)
? true : false;
if (!duplicateSessionDetected)
{
List sessions = flexClient.getFlexSessions();
int n = sessions.size();
if (n > 1)
{
int count = 0;
for (int i = 0; i < n; i++)
{
if (sessions.get(i) instanceof HttpFlexSession)
count++;
if (count > 1)
{
FlexContext.getHttpRequest().setAttribute(REQUEST_ATTR_DUPLICATE_SESSION_FLAG, Boolean.TRUE);
duplicateSessionDetected = true;
break;
}
}
}
}
// If more than one was found, remote host isn't using session cookies. Kill all duplicate sessions and return an error.
// Simplest to just re-scan the list given that it will be very short, but use an iterator for concurrent modification.
if (duplicateSessionDetected)
{
List sessions = flexClient.getFlexSessions();
for (Iterator iter = sessions.iterator(); iter.hasNext();)
{
FlexSession session = (FlexSession)iter.next();
if (session instanceof HttpFlexSession)
session.invalidate();