public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpServletRequest wrappedRequest = ServletObjectAccess.getServletRequest(request, portletWindow);
ServletResponseImpl wrappedResponse = (ServletResponseImpl)ServletObjectAccess.getServletResponse(response);
PrintWriter responseWriter = response.getWriter();
StringWriter storedWriter = new StringWriter();
// load the Portlet
// If there is an error loading, then we will save the error message and attempt
// to render it inside the Portlet, so the Portal has a chance of still looking
// okay
String errorMsg = null;
try {
PortletContainerFactory.getPortletContainer().portletLoad(portletWindow, wrappedRequest, response);
} catch (PortletContainerException e) {
log.error("Error in Portlet", e);
errorMsg = getErrorMsg();
} catch (Throwable t) {
// If we catch any throwable, we want to try to continue
// so that the rest of the portal renders correctly
log.error("Error in Portlet", t);
if (t instanceof VirtualMachineError) {
// if the Throwable is a VirtualMachineError then
// it is very unlikely (!) that the portal is going
// to render correctly.
throw (Error) t;
} else {
errorMsg = getErrorMsg();
}
}
PortalEnvironment env = (PortalEnvironment) request.getAttribute(PortalEnvironment.REQUEST_PORTALENV);
PortalURL thisURL = env.getRequestedPortalURL();
PortalControlParameter thisControl = new PortalControlParameter(thisURL);
if (thisControl.isOnePortletWindowMaximized()) {
WindowState currentState = thisControl.getState(portletWindow);
if (!WindowState.MAXIMIZED.equals(currentState)) {
return;
}
}
PortletDefinition portletDefinition = portletWindow.getPortletEntity().getPortletDefinition();
LanguageSet languageSet = portletDefinition.getLanguageSet();
Language lang = languageSet.get(request.getLocale());
String title = lang != null ? lang.getTitle() : "no title available";
// create a PortletInfo object. This is used to communicate with
// the header and footer JSP pages for this portlet
PortletInfo portletInfo = new PortletInfo();
ServletDefinition servletDefinition = portletWindow.getPortletEntity().getPortletDefinition().getServletDefinition();
if (servletDefinition != null && !servletDefinition.isUnavailable()) {
PrintWriter writer2 = new PrintWriter(storedWriter);
// create a wrapped response which the Portlet will be rendered to
wrappedResponse = (ServletResponseImpl)ServletObjectAccess.getStoredServletResponse(response, writer2);
try {
// render the Portlet to the wrapped response, to be output later.
PortletContainerFactory.getPortletContainer().renderPortlet(portletWindow, wrappedRequest, wrappedResponse);
} catch (UnavailableException e) {
log.error("Portlet is Unavailable", e);
writer2.println("the portlet is currently unavailable!");
ServletDefinitionCtrl servletDefinitionCtrl = (ServletDefinitionCtrl) ControllerObjectAccess.get(portletWindow.getPortletEntity().getPortletDefinition().getServletDefinition());
if (e.isPermanent()) {
servletDefinitionCtrl.setAvailable(Long.MAX_VALUE);
} else {
int unavailableSeconds = e.getUnavailableSeconds();
if (unavailableSeconds <= 0) {
unavailableSeconds = 60; // arbitrary default
}
servletDefinitionCtrl.setAvailable(System.currentTimeMillis() + unavailableSeconds * 1000);
}
} catch (Exception e) {
log.error("Error in Portlet", e);
writer2.println(getErrorMsg());
}
String dyn_title = ((DynamicTitleServiceImpl) FactoryAccess.getDynamicTitleContainerService()).getDynamicTitle(portletWindow, request);
if (dyn_title != null) {
title = dyn_title;
}
}
// set the title, so the header JSP page can use it when rendering
portletInfo.setTitle(title);
DynamicInformationProvider provider = FactoryAccess.getDynamicProvider(request);
ContentType supported = portletDefinition.getContentTypeSet().get(wrappedResponse.getContentType());
PortalContextProvider portalContextProvider = FactoryAccess.getStaticProvider().getPortalContextProvider();
// get the list of modes this Portlet supports
if (supported != null && portalContextProvider != null) {
// if portlet supports portlet modes