if (PortletWindow.Action.ACTION != action && PortletWindow.Action.RENDER != action)
{
return;
}
PortletWindowImpl window = (PortletWindowImpl)requestContext.getPortletWindow();
PortletApplication pa = portletDefinition.getApplication();
pa.setLocalContextPath(portalContext.getContextPath());
ClassLoader paClassLoader = portletFactory.getPortletApplicationClassLoader(pa);
PortletInstance portletInstance = portletFactory.getPortletInstance(jetspeedContext, portletDefinition);
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
try
{
PortletResponseContext responseContext = (PortletResponseContext)portletRequest.getAttribute(PortletInvokerService.RESPONSE_CONTEXT);
((JetspeedRequestContext)window.getRequestContext()).setCurrentPortletWindow(window);
window.setInvocationState(action, requestContext, responseContext, portletRequest, portletResponse, portletInstance);
window.setAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE, window.getFragment());
window.setAttribute(PortalReservedParameters.PORTLET_WINDOW_ATTRIBUTE, window);
window.setAttribute(PortalReservedParameters.PORTLET_DEFINITION_ATTRIBUTE, portletDefinition);
// initialize request/response for portletRequestContext
HttpServletRequest request = requestContext.getContainerRequest();
HttpServletResponse response = requestContext.getContainerResponse();
request = (HttpServletRequest) requestResponseUnwrapper.unwrapContainerRequest(request);
response = (HttpServletResponse) requestResponseUnwrapper.unwrapContainerResponse(response);
requestContext.init(window.getPortletInstance().getConfig(), this.jetspeedContext, request, response);
window.getPortletResponseContext().init(request, response);
Thread.currentThread().setContextClassLoader(paClassLoader);
if (PortletWindow.Action.ACTION == action)
{
ActionRequest actionRequest = (ActionRequest) portletRequest;
ActionResponse actionResponse = (ActionResponse) portletResponse;
portletInstance.processAction(actionRequest, actionResponse);
}
else // if (PortletWindow.Action.RENDER == action)
{
RenderRequest renderRequest = (RenderRequest) portletRequest;
RenderResponse renderResponse = (RenderResponse) portletResponse;
renderResponse.setContentType(window.getRequestContext().getMimeType());
portletInstance.render(renderRequest, renderResponse);
}
}
catch (Throwable t)
{
if ( t instanceof UnavailableException )
{
// take it out of service
try
{
portletInstance.destroy();
}
catch (Throwable ignore)
{
// never mind, it won't be used anymore
}
}
if ( t instanceof PortletException )
{
throw (PortletException)t;
}
if ( t instanceof IOException )
{
throw (IOException)t;
}
else
{
throw new PortletException(t);
}
}
finally
{
((JetspeedRequestContext)window.getRequestContext()).setCurrentPortletWindow(null);
Thread.currentThread().setContextClassLoader(oldLoader);
}
}