Search in sources :

Example 1 with PortletDispatchException

use of org.apereo.portal.portlet.PortletDispatchException in project uPortal by Jasig.

the class PortletRendererImpl method doEvent.

/*
     * PLT 22.1 If the content of a portlet is cached and the portlet is target of request
     * with an action-type semantic (e.g. an action or event call), the portlet container should discard the cache and
     * invoke the corresponding request handling methods of the portlet like processAction,or processEvent.
     *
     * (non-Javadoc)
     * @see org.apereo.portal.portlet.rendering.IPortletRenderer#doEvent(org.apereo.portal.portlet.om.IPortletWindowId, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.portlet.Event)
     */
@Override
public long doEvent(IPortletWindowId portletWindowId, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Event event) {
    this.portletCacheControlService.purgeCachedPortletData(portletWindowId, httpServletRequest);
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpServletRequest, portletWindowId);
    enforceConfigPermission(httpServletRequest, portletWindow);
    httpServletRequest = this.setupPortletRequest(httpServletRequest);
    httpServletResponse = new PortletHttpServletResponseWrapper(httpServletResponse, portletWindow);
    //Execute the action,
    this.logger.debug("Executing portlet event for window '{}'", portletWindow);
    final long start = System.nanoTime();
    try {
        this.portletContainer.doEvent(portletWindow.getPlutoPortletWindow(), httpServletRequest, httpServletResponse, event);
    } catch (PortletException pe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing event.", portletWindow, pe);
    } catch (PortletContainerException pce) {
        throw new PortletDispatchException("The portlet container threw an exception while executing event on portlet window '" + portletWindow + "'.", portletWindow, pce);
    } catch (IOException ioe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing event.", portletWindow, ioe);
    }
    final long executionTime = System.nanoTime() - start;
    this.portalEventFactory.publishPortletEventExecutionEvent(httpServletRequest, this, portletWindowId, executionTime, event.getQName());
    return executionTime;
}
Also used : PortletException(javax.portlet.PortletException) PortletDispatchException(org.apereo.portal.portlet.PortletDispatchException) IOException(java.io.IOException) PortletHttpServletResponseWrapper(org.apereo.portal.utils.web.PortletHttpServletResponseWrapper) PortletContainerException(org.apache.pluto.container.PortletContainerException) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow)

Example 2 with PortletDispatchException

use of org.apereo.portal.portlet.PortletDispatchException in project uPortal by Jasig.

the class PortletRendererImpl method doServeResource.

@Override
public long doServeResource(IPortletWindowId portletWindowId, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, PortletResourceOutputHandler portletOutputHandler) throws IOException {
    final CacheState<CachedPortletResourceData<Long>, Long> cacheState = this.portletCacheControlService.getPortletResourceState(httpServletRequest, portletWindowId);
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpServletRequest, portletWindowId);
    enforceConfigPermission(httpServletRequest, portletWindow);
    if (cacheState.isUseBrowserData()) {
        logger.trace("doServeResource-Reusing browser data");
        return doResourceReplayBrowserContent(portletWindow, httpServletRequest, cacheState, portletOutputHandler);
    }
    if (cacheState.isUseCachedData()) {
        logger.trace("doServeResource-Reusing cached data");
        return doResourceReplayCachedContent(portletWindow, httpServletRequest, cacheState, portletOutputHandler, 0);
    }
    final int cacheSizeThreshold = this.portletCacheControlService.getCacheSizeThreshold();
    final CachingPortletResourceOutputHandler cachingPortletOutputHandler = new CachingPortletResourceOutputHandler(portletOutputHandler, cacheSizeThreshold);
    CacheControl cacheControl = cacheState.getCacheControl();
    //Wrap the cache control so it immediately sets the caching related response headers
    cacheControl = new HeaderSettingCacheControl(cacheControl, cachingPortletOutputHandler);
    //Setup the request and response
    httpServletRequest = this.setupPortletRequest(httpServletRequest);
    httpServletResponse = new PortletResourceHttpServletResponseWrapper(httpServletResponse, portletWindow, portletOutputHandler, cacheControl);
    httpServletRequest.setAttribute(IPortletRenderer.ATTRIBUTE__PORTLET_CACHE_CONTROL, cacheControl);
    httpServletRequest.setAttribute(IPortletRenderer.ATTRIBUTE__PORTLET_OUTPUT_HANDLER, cachingPortletOutputHandler);
    this.logger.debug("Executing resource request for window {}", portletWindow);
    final long start = System.nanoTime();
    try {
        this.portletContainer.doServeResource(portletWindow.getPlutoPortletWindow(), httpServletRequest, httpServletResponse);
    } catch (PortletException pe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing serveResource.", portletWindow, pe);
    } catch (PortletContainerException pce) {
        throw new PortletDispatchException("The portlet container threw an exception while executing serveResource on portlet window '" + portletWindow + "'.", portletWindow, pce);
    } catch (IOException ioe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing serveResource.", portletWindow, ioe);
    }
    final long executionTime = System.nanoTime() - start;
    //See if the portlet signaled to use the cached content
    final boolean useCachedContent = cacheControl.useCachedContent();
    if (useCachedContent) {
        final CachedPortletResourceData<Long> cachedPortletResourceData = cacheState.getCachedPortletData();
        if (cachedPortletResourceData != null) {
            //Update the expiration time and re-store in the cache
            final CachedPortletData<Long> cachedPortletData = cachedPortletResourceData.getCachedPortletData();
            cachedPortletData.updateExpirationTime(cacheControl.getExpirationTime());
            this.portletCacheControlService.cachePortletResourceOutput(portletWindowId, httpServletRequest, cacheState, cachedPortletResourceData);
        }
        if (cacheState.isBrowserSetEtag()) {
            logger.trace("doServeResource-useCachedContent, Reusing browser data");
            //Browser-side content matches, send a 304
            return doResourceReplayBrowserContent(portletWindow, httpServletRequest, cacheState, portletOutputHandler);
        }
        logger.trace("doServeResource-useCachedContent, Reusing cached data");
        return doResourceReplayCachedContent(portletWindow, httpServletRequest, cacheState, cachingPortletOutputHandler, executionTime);
    }
    publishResourceEvent(portletWindow, httpServletRequest, executionTime, false, false);
    if (cacheState != null) {
        boolean shouldCache = this.portletCacheControlService.shouldOutputBeCached(cacheControl);
        if (shouldCache) {
            final CachedPortletResourceData<Long> cachedPortletResourceData = cachingPortletOutputHandler.getCachedPortletResourceData(executionTime, cacheControl);
            if (cachedPortletResourceData != null) {
                this.portletCacheControlService.cachePortletResourceOutput(portletWindowId, httpServletRequest, cacheState, cachedPortletResourceData);
            }
        }
    }
    return executionTime;
}
Also used : PortletException(javax.portlet.PortletException) CachedPortletResourceData(org.apereo.portal.portlet.container.cache.CachedPortletResourceData) IOException(java.io.IOException) PortletContainerException(org.apache.pluto.container.PortletContainerException) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) PortletDispatchException(org.apereo.portal.portlet.PortletDispatchException) CachingPortletResourceOutputHandler(org.apereo.portal.portlet.container.cache.CachingPortletResourceOutputHandler) HeaderSettingCacheControl(org.apereo.portal.portlet.container.cache.HeaderSettingCacheControl) CacheControl(javax.portlet.CacheControl) HeaderSettingCacheControl(org.apereo.portal.portlet.container.cache.HeaderSettingCacheControl)

Example 3 with PortletDispatchException

use of org.apereo.portal.portlet.PortletDispatchException in project uPortal by Jasig.

the class PortletRendererImpl method doAction.

/*
     * PLT 22.1 If the content of a portlet is cached and the portlet is target of request
     * with an action-type semantic (e.g. an action or event call), the portlet container should discard the cache and
     * invoke the corresponding request handling methods of the portlet like processAction,or processEvent.
     */
@Override
public long doAction(IPortletWindowId portletWindowId, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
    this.portletCacheControlService.purgeCachedPortletData(portletWindowId, httpServletRequest);
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpServletRequest, portletWindowId);
    enforceConfigPermission(httpServletRequest, portletWindow);
    httpServletRequest = this.setupPortletRequest(httpServletRequest);
    httpServletResponse = new PortletHttpServletResponseWrapper(httpServletResponse, portletWindow);
    //Execute the action,
    this.logger.debug("Executing portlet action for window '{}'", portletWindow);
    final long start = System.nanoTime();
    try {
        this.portletContainer.doAction(portletWindow.getPlutoPortletWindow(), httpServletRequest, httpServletResponse);
    } catch (PortletException pe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing action.", portletWindow, pe);
    } catch (PortletContainerException pce) {
        throw new PortletDispatchException("The portlet container threw an exception while executing action on portlet window '" + portletWindow + "'.", portletWindow, pce);
    } catch (IOException ioe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing action.", portletWindow, ioe);
    }
    final long executionTime = System.nanoTime() - start;
    this.portalEventFactory.publishPortletActionExecutionEvent(httpServletRequest, this, portletWindowId, executionTime);
    return executionTime;
}
Also used : PortletException(javax.portlet.PortletException) PortletDispatchException(org.apereo.portal.portlet.PortletDispatchException) IOException(java.io.IOException) PortletHttpServletResponseWrapper(org.apereo.portal.utils.web.PortletHttpServletResponseWrapper) PortletContainerException(org.apache.pluto.container.PortletContainerException) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow)

Example 4 with PortletDispatchException

use of org.apereo.portal.portlet.PortletDispatchException in project uPortal by Jasig.

the class PortletRendererImpl method doRender.

protected PortletRenderResult doRender(IPortletWindowId portletWindowId, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, PortletOutputHandler portletOutputHandler, RenderPart renderPart) throws IOException {
    final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = renderPart.getCacheState(this.portletCacheControlService, httpServletRequest, portletWindowId);
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpServletRequest, portletWindowId);
    enforceConfigPermission(httpServletRequest, portletWindow);
    /*
         * If the portlet is rendering in EXCLUSIVE WindowState ignore the provided PortletOutputHandler and
         * write directly to the response.
         *
         * THIS IS VERY BAD AND SHOULD BE DEPRECATED ALONG WITH EXCLUSIVE WINDOW STATE
         */
    if (IPortletRenderer.EXCLUSIVE.equals(portletWindow.getWindowState())) {
        portletOutputHandler = new ResourcePortletOutputHandler(httpServletResponse);
    }
    if (cacheState.isUseCachedData()) {
        return doRenderReplayCachedContent(portletWindow, httpServletRequest, cacheState, portletOutputHandler, renderPart, 0);
    }
    final int cacheSizeThreshold = this.portletCacheControlService.getCacheSizeThreshold();
    final CachingPortletOutputHandler cachingPortletOutputHandler = new CachingPortletOutputHandler(portletOutputHandler, cacheSizeThreshold);
    final CacheControl cacheControl = cacheState.getCacheControl();
    //Setup the request and response
    httpServletRequest = this.setupPortletRequest(httpServletRequest);
    httpServletResponse = new PortletMimeHttpServletResponseWrapper(httpServletResponse, portletWindow, portletOutputHandler, cacheControl);
    httpServletRequest.setAttribute(IPortletRenderer.ATTRIBUTE__PORTLET_CACHE_CONTROL, cacheControl);
    httpServletRequest.setAttribute(IPortletRenderer.ATTRIBUTE__PORTLET_OUTPUT_HANDLER, cachingPortletOutputHandler);
    logger.debug("Rendering portlet {} for window {}", renderPart.name(), portletWindow);
    final long renderStartTime = System.nanoTime();
    try {
        httpServletRequest.setAttribute(PortletRequest.RENDER_PART, renderPart.getRenderPart());
        this.portletContainer.doRender(portletWindow.getPlutoPortletWindow(), httpServletRequest, httpServletResponse);
    } catch (PortletException pe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing renderMarkup.", portletWindow, pe);
    } catch (PortletContainerException pce) {
        throw new PortletDispatchException("The portlet container threw an exception while executing renderMarkup on portlet window '" + portletWindow + "'.", portletWindow, pce);
    } catch (IOException ioe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing renderMarkup.", portletWindow, ioe);
    }
    final long executionTime = System.nanoTime() - renderStartTime;
    //See if the portlet signaled to use the cached content
    final boolean useCachedContent = cacheControl.useCachedContent();
    if (useCachedContent) {
        final CachedPortletData<PortletRenderResult> cachedPortletData = cacheState.getCachedPortletData();
        if (cachedPortletData == null) {
            throw new PortletDispatchException("The portlet window '" + portletWindow + "' indicated via CacheControl#useCachedContent " + "that the portal should render cached content, however there is no cached content to return. " + "This is a portlet bug.", portletWindow);
        }
        //Update the expiration time and re-store in the cache
        cachedPortletData.updateExpirationTime(cacheControl.getExpirationTime());
        renderPart.cachePortletOutput(portletCacheControlService, portletWindowId, httpServletRequest, cacheState, cachedPortletData);
        return doRenderReplayCachedContent(portletWindow, httpServletRequest, cacheState, portletOutputHandler, renderPart, executionTime);
    }
    publishRenderEvent(portletWindow, httpServletRequest, renderPart, executionTime, false);
    //Build the render result
    final PortletRenderResult portletRenderResult = constructPortletRenderResult(httpServletRequest, executionTime);
    //Check if the portlet's output should be cached
    if (cacheState != null) {
        boolean shouldCache = this.portletCacheControlService.shouldOutputBeCached(cacheControl);
        if (shouldCache) {
            final CachedPortletData<PortletRenderResult> cachedPortletData = cachingPortletOutputHandler.getCachedPortletData(portletRenderResult, cacheControl);
            if (cachedPortletData != null) {
                renderPart.cachePortletOutput(portletCacheControlService, portletWindowId, httpServletRequest, cacheState, cachedPortletData);
            }
        }
    }
    return portletRenderResult;
}
Also used : CachingPortletOutputHandler(org.apereo.portal.portlet.container.cache.CachingPortletOutputHandler) PortletException(javax.portlet.PortletException) IOException(java.io.IOException) PortletContainerException(org.apache.pluto.container.PortletContainerException) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) CachedPortletData(org.apereo.portal.portlet.container.cache.CachedPortletData) PortletDispatchException(org.apereo.portal.portlet.PortletDispatchException) PortletMimeHttpServletResponseWrapper(org.apereo.portal.utils.web.PortletMimeHttpServletResponseWrapper) HeaderSettingCacheControl(org.apereo.portal.portlet.container.cache.HeaderSettingCacheControl) CacheControl(javax.portlet.CacheControl)

Example 5 with PortletDispatchException

use of org.apereo.portal.portlet.PortletDispatchException 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

IOException (java.io.IOException)5 PortletException (javax.portlet.PortletException)5 PortletContainerException (org.apache.pluto.container.PortletContainerException)5 PortletDispatchException (org.apereo.portal.portlet.PortletDispatchException)5 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)5 PortletHttpServletResponseWrapper (org.apereo.portal.utils.web.PortletHttpServletResponseWrapper)3 CacheControl (javax.portlet.CacheControl)2 HeaderSettingCacheControl (org.apereo.portal.portlet.container.cache.HeaderSettingCacheControl)2 CacheControlImpl (org.apereo.portal.portlet.container.cache.CacheControlImpl)1 CachedPortletData (org.apereo.portal.portlet.container.cache.CachedPortletData)1 CachedPortletResourceData (org.apereo.portal.portlet.container.cache.CachedPortletResourceData)1 CachingPortletOutputHandler (org.apereo.portal.portlet.container.cache.CachingPortletOutputHandler)1 CachingPortletResourceOutputHandler (org.apereo.portal.portlet.container.cache.CachingPortletResourceOutputHandler)1 ParameterMap (org.apereo.portal.url.ParameterMap)1 PortletMimeHttpServletResponseWrapper (org.apereo.portal.utils.web.PortletMimeHttpServletResponseWrapper)1