Search in sources :

Example 1 with ParameterMap

use of org.apereo.portal.url.ParameterMap in project uPortal by Jasig.

the class PortletErrorController method renderError.

/**
     * Render the error portlet view.
     *
     * @param request
     * @param response
     * @param model
     * @return the name of the view to display
     * @throws Exception
     */
@RequestMapping("VIEW")
public String renderError(RenderRequest request, RenderResponse response, ModelMap model) throws Exception {
    HttpServletRequest httpRequest = this.portalRequestUtils.getPortletHttpRequest(request);
    IPortletWindowId currentFailedPortletWindowId = (IPortletWindowId) request.getAttribute(REQUEST_ATTRIBUTE__CURRENT_FAILED_PORTLET_WINDOW_ID);
    model.addAttribute("portletWindowId", currentFailedPortletWindowId);
    Exception cause = (Exception) request.getAttribute(REQUEST_ATTRIBUTE__CURRENT_EXCEPTION_CAUSE);
    model.addAttribute("exception", cause);
    final String rootCauseMessage = ExceptionUtils.getRootCauseMessage(cause);
    model.addAttribute("rootCauseMessage", rootCauseMessage);
    // Maintenance Mode?
    if (cause != null && cause instanceof MaintenanceModeException) {
        return "/jsp/PortletError/maintenance";
    }
    IUserInstance userInstance = this.userInstanceManager.getUserInstance(httpRequest);
    if (hasAdminPrivileges(userInstance)) {
        IPortletWindow window = this.portletWindowRegistry.getPortletWindow(httpRequest, currentFailedPortletWindowId);
        window.setRenderParameters(new ParameterMap());
        IPortalUrlBuilder adminRetryUrl = this.portalUrlProvider.getPortalUrlBuilderByPortletWindow(httpRequest, currentFailedPortletWindowId, UrlType.RENDER);
        model.addAttribute("adminRetryUrl", adminRetryUrl.getUrlString());
        final IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(httpRequest, currentFailedPortletWindowId);
        final IPortletEntity parentPortletEntity = portletWindow.getPortletEntity();
        final IPortletDefinition parentPortletDefinition = parentPortletEntity.getPortletDefinition();
        model.addAttribute("channelDefinition", parentPortletDefinition);
        StringWriter stackTraceWriter = new StringWriter();
        cause.printStackTrace(new PrintWriter(stackTraceWriter));
        model.addAttribute("stackTrace", stackTraceWriter.toString());
        return "/jsp/PortletError/detailed";
    }
    // no admin privileges, return generic view
    return "/jsp/PortletError/generic";
}
Also used : ParameterMap(org.apereo.portal.url.ParameterMap) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) StringWriter(java.io.StringWriter) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PrintWriter(java.io.PrintWriter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ParameterMap

use of org.apereo.portal.url.ParameterMap in project uPortal by Jasig.

the class PortletRendererImpl method doReset.

/*
     * (non-Javadoc)
     * @see org.apereo.portal.portlet.rendering.IPortletRenderer#doReset(org.apereo.portal.portlet.om.IPortletWindowId, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
public void doReset(IPortletWindowId portletWindowId, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
    // Don't enforce config mode restriction because this is going to snap the portlet window back into view mode.
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpServletRequest, portletWindowId);
    if (portletWindow != null) {
        portletWindow.setPortletMode(PortletMode.VIEW);
        portletWindow.setRenderParameters(new ParameterMap());
        portletWindow.setExpirationCache(null);
        httpServletRequest = this.setupPortletRequest(httpServletRequest);
        httpServletResponse = new PortletHttpServletResponseWrapper(httpServletResponse, portletWindow);
        httpServletRequest.setAttribute(AdministrativeRequestListenerController.DEFAULT_LISTENER_KEY_ATTRIBUTE, "sessionActionListener");
        httpServletRequest.setAttribute(PortletSessionAdministrativeRequestListener.ACTION, PortletSessionAdministrativeRequestListener.SessionAction.CLEAR);
        httpServletRequest.setAttribute(PortletSessionAdministrativeRequestListener.SCOPE, PortletSession.PORTLET_SCOPE);
        //TODO modify PortletContainer.doAdmin to create a specific "admin" req/res object and context so we don't have to fake it with a render req
        //These are required for a render request to be created and admin requests use a render request under the hood
        final String characterEncoding = httpServletResponse.getCharacterEncoding();
        httpServletRequest.setAttribute(IPortletRenderer.ATTRIBUTE__PORTLET_OUTPUT_HANDLER, new RenderPortletOutputHandler(characterEncoding));
        httpServletRequest.setAttribute(IPortletRenderer.ATTRIBUTE__PORTLET_CACHE_CONTROL, new CacheControlImpl());
        try {
            this.portletContainer.doAdmin(portletWindow.getPlutoPortletWindow(), httpServletRequest, httpServletResponse);
        } catch (PortletException pe) {
            throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing admin command to clear session.", portletWindow, pe);
        } catch (PortletContainerException pce) {
            throw new PortletDispatchException("The portlet container threw an exception while executing admin command to clear session on portlet window '" + portletWindow + "'.", portletWindow, pce);
        } catch (IOException ioe) {
            throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing admin command to clear session.", portletWindow, ioe);
        }
    } else {
        logger.debug("ignoring doReset as portletWindowRegistry#getPortletWindow returned a null result for portletWindowId {}", portletWindowId);
    }
}
Also used : CacheControlImpl(org.apereo.portal.portlet.container.cache.CacheControlImpl) PortletException(javax.portlet.PortletException) PortletDispatchException(org.apereo.portal.portlet.PortletDispatchException) ParameterMap(org.apereo.portal.url.ParameterMap) IOException(java.io.IOException) PortletHttpServletResponseWrapper(org.apereo.portal.utils.web.PortletHttpServletResponseWrapper) PortletContainerException(org.apache.pluto.container.PortletContainerException) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow)

Aggregations

IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)2 ParameterMap (org.apereo.portal.url.ParameterMap)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 PortletException (javax.portlet.PortletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 PortletContainerException (org.apache.pluto.container.PortletContainerException)1 PortletDispatchException (org.apereo.portal.portlet.PortletDispatchException)1 CacheControlImpl (org.apereo.portal.portlet.container.cache.CacheControlImpl)1 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)1 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)1 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)1 IPortalUrlBuilder (org.apereo.portal.url.IPortalUrlBuilder)1 IUserInstance (org.apereo.portal.user.IUserInstance)1 PortletHttpServletResponseWrapper (org.apereo.portal.utils.web.PortletHttpServletResponseWrapper)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1