* @throws IOException
*/
private void dispatch(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
InternalPortletRequest portletRequest = null;
InternalPortletResponse portletResponse = null;
try {
// Save portlet config into servlet request.
request.setAttribute(Constants.PORTLET_CONFIG, portletConfig);
// Retrieve attributes from the servlet request.
Integer methodId = (Integer) request.getAttribute(
Constants.METHOD_ID);
portletRequest = (InternalPortletRequest) request.getAttribute(
Constants.PORTLET_REQUEST);
portletResponse = (InternalPortletResponse) request.getAttribute(
Constants.PORTLET_RESPONSE);
portletRequest.init(portletContext, request);
// The requested method is RENDER: call Portlet.render(..)
if (methodId == Constants.METHOD_RENDER) {
RenderRequestImpl renderRequest =
(RenderRequestImpl) portletRequest;
RenderResponseImpl renderResponse =
(RenderResponseImpl) portletResponse;
portlet.render(renderRequest, renderResponse);
}
// The requested method is ACTION: call Portlet.processAction(..)
else if (methodId == Constants.METHOD_ACTION) {
ActionRequestImpl actionRequest =
(ActionRequestImpl) portletRequest;
ActionResponseImpl actionResponse =
(ActionResponseImpl) portletResponse;
portlet.processAction(actionRequest, actionResponse);
}
// The requested method is ADMIN: call handlers.
else if (methodId == Constants.METHOD_ADMIN) {
ContainerInvocation inv = ContainerInvocation.getInvocation();
PortalAdministrationService pas =
inv.getPortletContainer()
.getOptionalContainerServices()
.getPortalAdministrationService();
Iterator it = pas.getAdministrativeRequestListeners().iterator();
while(it.hasNext()) {
AdministrativeRequestListener l =(AdministrativeRequestListener)it.next();
l.administer(portletRequest, portletResponse);
}
}
// The requested method is NOOP: do nothing.
else if (methodId == Constants.METHOD_NOOP) {
// Do nothing.
}
} catch (javax.portlet.UnavailableException ex) {
ex.printStackTrace();
/*
if (e.isPermanent()) {
throw new UnavailableException(e.getMessage());
} else {
throw new UnavailableException(e.getMessage(), e.getUnavailableSeconds());
}*/
// Portlet.destroy() isn't called by Tomcat, so we have to fix it.
try {
portlet.destroy();
} catch (Throwable th) {
// Don't care for Exception
}
// TODO: Handle everything as permanently for now.
throw new javax.servlet.UnavailableException(ex.getMessage());
} catch (PortletException ex) {
ex.printStackTrace();
throw new ServletException(ex);
} finally {
request.removeAttribute(Constants.PORTLET_CONFIG);
if (portletRequest != null) {
portletRequest.release();
}
}
}