*/
public final void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
String portletName = null;
Integer method = ContainerConstants.METHOD_NOOP;
Portlet portlet = null;
boolean destroyPortlet = false;
boolean isParallelMode = false;
try
{
isParallelMode = (Thread.currentThread() instanceof Worker || CurrentWorkerContext.getCurrentWorkerContextUsed());
if (isParallelMode)
{
method = (Integer) CurrentWorkerContext.getAttribute(ContainerConstants.METHOD_ID);
}
else
{
method = (Integer) request.getAttribute(ContainerConstants.METHOD_ID);
}
if (method == ContainerConstants.METHOD_NOOP)
{
return;
}
if (isParallelMode)
{
portlet = (Portlet) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET);
portletName = (String) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_NAME);
}
else
{
portlet = (Portlet)request.getAttribute(ContainerConstants.PORTLET);
portletName = (String)request.getAttribute(ContainerConstants.PORTLET_NAME);
request.removeAttribute(ContainerConstants.PORTLET);
}
if (method == ContainerConstants.METHOD_ACTION)
{
ActionRequest actionRequest = (ActionRequest) request.getAttribute(ContainerConstants.PORTLET_REQUEST);
ActionResponse actionResponse = (ActionResponse) request.getAttribute(ContainerConstants.PORTLET_RESPONSE);
// inject the current request into the actionRequest handler (o.a.j.engine.servlet.ServletRequestImpl)
((HttpServletRequestWrapper)((HttpServletRequestWrapper)actionRequest).getRequest()).setRequest(request);
portlet.processAction(actionRequest, actionResponse);
}
else if (method == ContainerConstants.METHOD_RENDER)
{
RenderRequest renderRequest = null;
RenderResponse renderResponse = null;
if (isParallelMode)
{
renderRequest = (RenderRequest) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_REQUEST);
renderResponse = (RenderResponse) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_RESPONSE);
}
else
{
renderRequest = (RenderRequest) request.getAttribute(ContainerConstants.PORTLET_REQUEST);
renderResponse = (RenderResponse) request.getAttribute(ContainerConstants.PORTLET_RESPONSE);
}
// inject the current request into the renderRequest handler (o.a.j.engine.servlet.ServletRequestImpl)
((HttpServletRequestWrapper)((HttpServletRequestWrapper)renderRequest).getRequest()).setRequest(request);
portlet.render(renderRequest, renderResponse);
}
// if we get this far we are home free
return;
}
catch (Throwable t)
{
if ( t instanceof UnavailableException )
{
// destroy the portlet in the finally clause
destroyPortlet = true;
}
if (method != ContainerConstants.METHOD_ACTION)
{
ServletContext context = getServletContext();
context.log(JCS + "Error rendering portlet \"" + portletName + "\": " + t.toString(), t);
try
{
String errorTemplate = getInitParameter("portal.error.page");
if (errorTemplate == null)
{
errorTemplate = "/WEB-INF/templates/generic/html/error.vm";
}
if (null != context.getResource(errorTemplate))
{
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(errorTemplate);
request.setAttribute("e", t);
StringWriter stackTrace = new StringWriter();
t.printStackTrace(new PrintWriter(stackTrace));
request.setAttribute("stacktrace", stackTrace.toString());
dispatcher.include(request, response);
}
else
{
displayPortletNotAvailableMessage(t, response, portletName);
}
}
catch (Throwable e)
{
displayPortletNotAvailableMessage(t, response, portletName);
}
finally
{
t.printStackTrace();
}
}
else
{
if ( t instanceof RuntimeException )
{
throw (RuntimeException)t;
}
else if (t instanceof IOException )
{
throw (IOException)t;
}
else if (t instanceof ServletException)
{
throw (ServletException)t;
}
else
{
throw new ServletException(t);
}
}
}
finally
{
if ( destroyPortlet )
{
// portlet throwed UnavailableException: take it out of service
try
{
portlet.destroy();
}
catch (Exception e)
{
// never mind, it won't be used anymore.
}