Search in sources :

Example 36 with IPortletWindow

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

the class PortletExecutionManager method doPortletAction.

/* (non-Javadoc)
     * @see org.apereo.portal.portlet.rendering.IPortletExecutionManager#doPortletAction(org.apereo.portal.portlet.om.IPortletWindowId, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
public void doPortletAction(IPortletWindowId portletWindowId, HttpServletRequest request, HttpServletResponse response) {
    final long timeout = getPortletActionTimeout(portletWindowId, request);
    final IPortletExecutionWorker<Long> portletActionExecutionWorker = this.portletWorkerFactory.createActionWorker(request, response, portletWindowId);
    portletActionExecutionWorker.submit();
    try {
        portletActionExecutionWorker.get(timeout);
    } catch (Exception e) {
        // put the exception into the error map for the session
        final Map<IPortletWindowId, Exception> portletFailureMap = getPortletErrorMap(request);
        portletFailureMap.put(portletWindowId, e);
    }
    // If the worker is still running add it to the hung-workers queue
    if (!portletActionExecutionWorker.isComplete()) {
        cancelWorker(request, portletActionExecutionWorker);
    }
    // Is this portlet permitted to emit events?  (Or is it disablePortletEvents=true?)
    final IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(request, portletWindowId);
    IPortletDefinition portletDefinition = portletWindow.getPortletEntity().getPortletDefinition();
    IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(DISABLE_PORTLET_EVENTS_PARAMETER);
    if (disablePortletEvents != null && Boolean.parseBoolean(disablePortletEvents.getValue())) {
        logger.info("Ignoring portlet events for portlet '{}' because they have been disabled.", portletDefinition.getFName());
    } else {
        // Proceed with events...
        final PortletEventQueue portletEventQueue = this.eventCoordinationService.getPortletEventQueue(request);
        this.doPortletEvents(portletEventQueue, request, response);
    }
}
Also used : IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap) IOException(java.io.IOException) MaintenanceModeException(org.apereo.portal.portlets.error.MaintenanceModeException) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 37 with IPortletWindow

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

the class PortletExecutionManager method startPortletRenderInternal.

/**
 * create and submit the portlet content rendering job to the thread pool
 */
protected IPortletRenderExecutionWorker startPortletRenderInternal(IPortletWindowId portletWindowId, HttpServletRequest request, HttpServletResponse response) {
    // first check to see if there is a Throwable in the session for this IPortletWindowId
    final Map<IPortletWindowId, Exception> portletFailureMap = getPortletErrorMap(request);
    final Exception cause = portletFailureMap.remove(portletWindowId);
    final IPortletRenderExecutionWorker portletRenderExecutionWorker;
    if (null != cause) {
        // previous action failed, dispatch to errorPortlet immediately
        portletRenderExecutionWorker = this.portletWorkerFactory.createFailureWorker(request, response, portletWindowId, cause);
    } else {
        IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(request, portletWindowId);
        IPortletDefinition portletDef = portletWindow.getPortletEntity().getPortletDefinition();
        if (portletDef.getLifecycleState().equals(PortletLifecycleState.MAINTENANCE)) {
            // Prevent the portlet from rendering;  replace with a helpful "Out of Service"
            // message
            portletRenderExecutionWorker = this.portletWorkerFactory.createFailureWorker(request, response, portletWindowId, new MaintenanceModeException());
        } else {
            // Happy path
            portletRenderExecutionWorker = this.portletWorkerFactory.createRenderWorker(request, response, portletWindowId);
        }
    }
    portletRenderExecutionWorker.submit();
    final Map<IPortletWindowId, IPortletRenderExecutionWorker> portletRenderingMap = this.getPortletRenderingMap(request);
    portletRenderingMap.put(portletWindowId, portletRenderExecutionWorker);
    return portletRenderExecutionWorker;
}
Also used : MaintenanceModeException(org.apereo.portal.portlets.error.MaintenanceModeException) IPortletRenderExecutionWorker(org.apereo.portal.portlet.rendering.worker.IPortletRenderExecutionWorker) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IOException(java.io.IOException) MaintenanceModeException(org.apereo.portal.portlets.error.MaintenanceModeException) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 38 with IPortletWindow

use of org.apereo.portal.portlet.om.IPortletWindow 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 39 with IPortletWindow

use of org.apereo.portal.portlet.om.IPortletWindow 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 40 with IPortletWindow

use of org.apereo.portal.portlet.om.IPortletWindow 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)

Aggregations

IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)88 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)32 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)32 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)23 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 IPortalRequestInfo (org.apereo.portal.url.IPortalRequestInfo)12 IUserInstance (org.apereo.portal.user.IUserInstance)12 List (java.util.List)10 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)10 IPortletUrlBuilder (org.apereo.portal.url.IPortletUrlBuilder)9 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 IOException (java.io.IOException)8 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)7 WindowState (javax.portlet.WindowState)6 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)6 IPortalUrlBuilder (org.apereo.portal.url.IPortalUrlBuilder)6 LinkedHashMap (java.util.LinkedHashMap)5 Locale (java.util.Locale)5 PortletException (javax.portlet.PortletException)5 PortletMode (javax.portlet.PortletMode)5