boolean actionRequest = ACTION_REQUEST.equals(requestType);
// save requestType early so getStrutsPageURL and getStrutsOrigURL can determine the type
req.setAttribute(StrutsPortlet.REQUEST_TYPE, requestType);
PortletSession portletSession = request.getPortletSession();
try
{
StrutsPortletErrorContext errorContext = (StrutsPortletErrorContext) portletSession.getAttribute(StrutsPortlet.ERROR_CONTEXT);
if (errorContext != null)
{
if (!actionRequest)
{
portletSession.removeAttribute(StrutsPortlet.ERROR_CONTEXT);
renderError(res, errorContext);
}
return;
}
String keepRenderAttributes = null;
if ( !actionRequest )
{
keepRenderAttributes = getKeepRenderAttributes(request);
}
if ( keepRenderAttributes == null )
{
strutsPortletConfig.getRenderContextAttributes().clearAttributes(portletSession);
}
else
{
strutsPortletConfig.getRenderContextAttributes().restoreAttributes(request);
}
String path = null;
String pageURL = getStrutsPageURL(request);
if (pageURL == null)
{
path = defaultPage;
}
else
{
path = pageURL;
}
if ( !actionRequest )
{
// restore possible render context from the session and store it as request attribute for the StrutsServlet to be able to find it
StrutsPortletRenderContext renderContext = (StrutsPortletRenderContext)portletSession.getAttribute(RENDER_CONTEXT);
if ( renderContext != null )
{
portletSession.removeAttribute(RENDER_CONTEXT);
req.setAttribute(RENDER_CONTEXT, renderContext);
}
}
if (log.isDebugEnabled())
log.debug("process path: " + path + ", requestType: " + requestType);
RequestDispatcher rd = servletContext.getRequestDispatcher(path);
if (rd != null)
{
if (actionRequest)
{
res = new EmptyHttpServletResponseWrapper(res);
// http://issues.apache.org/jira/browse/PB-2:
// provide servlet access to the Portlet components even from
// an actionRequest in extension to the JSR-168 requirement
// PLT.16.3.2 which (currently) only covers renderRequest
// servlet inclusion.
if ( req.getAttribute("javax.portlet.config") == null )
{
req.setAttribute("javax.portlet.config", getPortletConfig());
}
if ( req.getAttribute("javax.portlet.request") == null )
{
req.setAttribute("javax.portlet.request", request);
}
if ( req.getAttribute("javax.portlet.response") == null )
{
req.setAttribute("javax.portlet.response", response);
}
String origin = getStrutsOriginURL(request);
if ( origin == null )
{
origin = defaultPage;
}
request.setAttribute(StrutsPortlet.ORIGIN_URL, origin);
}
if (path != null)
{
req.setAttribute(StrutsPortlet.PAGE_URL, path);
}
HttpSession proxiedSession = null;
if ( portletScopeStrutsSession )
{
proxiedSession = (HttpSession)portletSession.getAttribute(SERVLET_PORTLET_SESSION_PROXY);
if (proxiedSession == null)
{
proxiedSession = ServletPortletSessionProxy.createProxy(req);
portletSession.setAttribute(SERVLET_PORTLET_SESSION_PROXY, proxiedSession);
}
}
req.setAttribute(SERVLET_PORTLET_APPLICATION_SESSION, req.getSession());
try
{
rd.include(new PortletServletRequestWrapper(servletContext, req, proxiedSession), res);
}
catch (ServletException e)
{
if (log.isErrorEnabled())
log.error("Include exception", e);
errorContext = new StrutsPortletErrorContext();
errorContext.setError(e);
req.setAttribute(StrutsPortlet.ERROR_CONTEXT, errorContext);
if (!actionRequest)
renderError(res, errorContext);
}
if (actionRequest)
{
String renderURL;
if (req.getAttribute(StrutsPortlet.ERROR_CONTEXT) != null)
{
pageURL = StrutsPortletURL.getOriginURL(req);
if ( pageURL != null )
{
((ActionResponse) response).setRenderParameter(StrutsPortletURL.PAGE+request.getPortletMode().toString(), pageURL);
}
if (log.isDebugEnabled())
log.debug("action render error context");
try
{
portletSession.setAttribute(StrutsPortlet.ERROR_CONTEXT,req.getAttribute(StrutsPortlet.ERROR_CONTEXT));
}
catch (IllegalStateException ise)
{
// catch Session already invalidated exception
// There isn't much we can do here other than
// redirecting the user to the start page
}
}
else
{
if ((renderURL = (String) req
.getAttribute(StrutsPortlet.REDIRECT_URL)) != null)
{
if (log.isDebugEnabled())
log.debug("action send redirect: " + renderURL);
((ActionResponse) response).sendRedirect(renderURL);
}
else
{
try
{
strutsPortletConfig.getRenderContextAttributes().saveAttributes(request);
}
catch (IllegalStateException ise)
{
// catch Session already invalidated exception
// There isn't much we can do here other than
// redirecting the user to the start page
return;
}
StrutsPortletRenderContext renderContext = (StrutsPortletRenderContext)req.getAttribute(RENDER_CONTEXT);
if ( renderContext != null )
{
portletSession.setAttribute(RENDER_CONTEXT, renderContext);
}
((ActionResponse) response).setRenderParameter(
StrutsPortletURL.KEEP_RENDER_ATTRIBUTES+request.getPortletMode().toString(), "1");
if ((renderURL = (String) req