{
BlockingInteractionResponse blockingInteractionResponse = (BlockingInteractionResponse)response;
log.debug("Starting processing response");
String redirectURL = blockingInteractionResponse.getRedirectURL();
UpdateResponse updateResponse = blockingInteractionResponse.getUpdateResponse();
if (redirectURL != null && updateResponse != null)
{
return new ErrorResponse(new IllegalArgumentException("Response cannot both redirect and update state."));
}
if (redirectURL != null)
{
return new HTTPRedirectionResponse(redirectURL); // do we need to process URLs?
}
else
{
// updateResponse.getMarkupContext(); // ignore bundled markup for now.
UpdateNavigationalStateResponse result = new UpdateNavigationalStateResponse();
// new mode
String newMode = updateResponse.getNewMode();
if (newMode != null)
{
result.setMode(WSRPUtils.getJSR168PortletModeFromWSRPName(newMode));
}
// new window state
String newWindowState = updateResponse.getNewWindowState();
if (newWindowState != null)
{
result.setWindowState(WSRPUtils.getJSR168WindowStateFromWSRPName(newWindowState));
}
// navigational state
String navigationalState = updateResponse.getNavigationalState();
if (navigationalState != null)
{
result.setNavigationalState(new OpaqueStateString(navigationalState));
}
// check if the portlet was cloned
PortletContext portletContext = updateResponse.getPortletContext();
if (portletContext != null)
{
PortletContext originalContext = requestPrecursor.getPortletContext();
InstanceContext context = invocation.getInstanceContext();
String handle = portletContext.getPortletHandle();
if (!originalContext.getPortletHandle().equals(handle))
{
log.debug("Portlet '" + requestPrecursor.getPortletHandle() + "' was implicitely cloned. New handle is '"
+ handle + "'");
StateEvent event = new StateEvent(WSRPUtils.convertToPortalPortletContext(portletContext), StateEvent.Type.PORTLET_CLONED_EVENT);
context.onStateEvent(event);
}
else
{
// check if the state was modified
byte[] originalState = originalContext.getPortletState();
byte[] newState = portletContext.getPortletState();
if (!Arrays.equals(originalState, newState))
{
StateEvent event = new StateEvent(WSRPUtils.convertToPortalPortletContext(portletContext), StateEvent.Type.PORTLET_MODIFIED_EVENT);
context.onStateEvent(event);
}
}
// update the session information associated with the portlet handle
consumer.getSessionHandler().updateSessionInfoFor(originalContext.getPortletHandle(), handle, invocation);
}
else
{
portletContext = requestPrecursor.getPortletContext();
}
// update the session info, using either the original or cloned portlet context, as appropriate
consumer.getSessionHandler().updateSessionIfNeeded(updateResponse.getSessionContext(), invocation,
portletContext.getPortletHandle());
log.debug("Response processed");
return result;
}