private ConversationState getCurrentState(ExoContainer container, HttpServletRequest httpRequest)
{
ConversationRegistry conversationRegistry =
(ConversationRegistry)container.getComponentInstanceOfType(ConversationRegistry.class);
IdentityRegistry identityRegistry =
(IdentityRegistry)container.getComponentInstanceOfType(IdentityRegistry.class);
ConversationState state = null;
String userId = httpRequest.getRemoteUser();
// only if user authenticated, otherwise there is no reason to do anythings
if (userId != null)
{
HttpSession httpSession = httpRequest.getSession();
StateKey stateKey = new HttpSessionStateKey(httpSession);
if (log.isDebugEnabled())
{
log.debug("Looking for Conversation State " + httpSession.getId());
}
state = conversationRegistry.getState(stateKey);
if (state == null)
{
if (log.isDebugEnabled())
{
log.debug("Conversation State not found, try create new one.");
}
Identity identity = identityRegistry.getIdentity(userId);
if (identity != null)
{
state = new ConversationState(identity);
// keep subject as attribute in ConversationState
state.setAttribute(ConversationState.SUBJECT, identity.getSubject());