Search in sources :

Example 6 with PortletContainerException

use of org.apache.pluto.container.PortletContainerException in project uPortal by Jasig.

the class PortletAdministrationHelper method getPortletDescriptor.

/**
 * Get a portlet descriptor matching the current portlet definition form. If the current form
 * does not represent a portlet, the application or portlet name fields are blank, or the
 * portlet description cannot be retrieved, the method will return <code>null</code>.
 *
 * @param form
 * @return
 */
public PortletDefinition getPortletDescriptor(PortletDefinitionForm form) {
    final Tuple<String, String> portletDescriptorKeys = this.getPortletDescriptorKeys(form);
    if (portletDescriptorKeys == null) {
        return null;
    }
    final String portletAppId = portletDescriptorKeys.first;
    final String portletName = portletDescriptorKeys.second;
    final PortletRegistryService portletRegistryService = portalDriverContainerServices.getPortletRegistryService();
    try {
        return portletRegistryService.getPortlet(portletAppId, portletName);
    } catch (PortletContainerException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : PortletRegistryService(org.apache.pluto.container.driver.PortletRegistryService) PortletContainerException(org.apache.pluto.container.PortletContainerException)

Example 7 with PortletContainerException

use of org.apache.pluto.container.PortletContainerException in project uPortal by Jasig.

the class LocalPortletContextManager method register.

// Public Methods ----------------------------------------------------------
/**
 * Retrieves the PortletContext associated with the given ServletContext. If one does not exist,
 * it is created.
 *
 * @param config the servlet config.
 * @return the InternalPortletContext associated with the ServletContext.
 * @throws PortletContainerException
 */
@Override
public synchronized String register(ServletConfig config) throws PortletContainerException {
    ServletContext servletContext = config.getServletContext();
    String contextPath = servletContext.getContextPath();
    if (!portletContexts.containsKey(contextPath)) {
        PortletApplicationDefinition portletApp = this.getPortletAppDD(servletContext, contextPath, contextPath);
        DriverPortletContext portletContext = new DriverPortletContextImpl(servletContext, portletApp, requestDispatcherService);
        portletContext.setAttribute(PlatformApiBroker.PORTLET_CONTEXT_ATTRIBUTE_NAME, platformApiBroker);
        portletContexts.put(contextPath, portletContext);
        fireRegistered(portletContext);
        if (logger.isInfoEnabled()) {
            logger.info("Registered portlet application for context '" + contextPath + "'");
            logger.info("Registering " + portletApp.getPortlets().size() + " portlets for context " + portletContext.getApplicationName());
        }
        // TODO have the portlet servlet provide the portlet's classloader as parameter to this
        // method
        // This approach is needed as all pluto callbacks in uPortal have an aspect that
        // switches the thread classloader back
        // to uPortal's classloader.
        ClassLoader classLoader = ThreadContextClassLoaderAspect.getPreviousClassLoader();
        if (classLoader == null) {
            classLoader = Thread.currentThread().getContextClassLoader();
        }
        classLoaders.put(portletApp.getName(), classLoader);
        for (PortletDefinition portlet : portletApp.getPortlets()) {
            String appName = portletContext.getApplicationName();
            if (appName == null) {
                throw new PortletContainerException("Portlet application name should not be null.");
            }
            portletConfigs.put(portletContext.getApplicationName() + "/" + portlet.getPortletName(), new DriverPortletConfigImpl(portletContext, portlet));
        }
    } else {
        if (logger.isInfoEnabled()) {
            logger.info("Portlet application for context '" + contextPath + "' already registered.");
        }
    }
    return contextPath;
}
Also used : DriverPortletContext(org.apache.pluto.container.driver.DriverPortletContext) PortletApplicationDefinition(org.apache.pluto.container.om.portlet.PortletApplicationDefinition) DriverPortletConfigImpl(org.apache.pluto.driver.container.DriverPortletConfigImpl) ServletContext(javax.servlet.ServletContext) DriverPortletContextImpl(org.apache.pluto.driver.container.DriverPortletContextImpl) PortletContainerException(org.apache.pluto.container.PortletContainerException) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition)

Example 8 with PortletContainerException

use of org.apache.pluto.container.PortletContainerException 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 9 with PortletContainerException

use of org.apache.pluto.container.PortletContainerException 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 10 with PortletContainerException

use of org.apache.pluto.container.PortletContainerException 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

PortletContainerException (org.apache.pluto.container.PortletContainerException)17 PortletRegistryService (org.apache.pluto.container.driver.PortletRegistryService)6 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)6 IOException (java.io.IOException)5 PortletException (javax.portlet.PortletException)5 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)5 PortletDispatchException (org.apereo.portal.portlet.PortletDispatchException)5 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)5 PortletApplicationDefinition (org.apache.pluto.container.om.portlet.PortletApplicationDefinition)4 PortletHttpServletResponseWrapper (org.apereo.portal.utils.web.PortletHttpServletResponseWrapper)3 CacheControl (javax.portlet.CacheControl)2 DriverPortletConfig (org.apache.pluto.container.driver.DriverPortletConfig)2 DriverPortletContext (org.apache.pluto.container.driver.DriverPortletContext)2 Supports (org.apache.pluto.container.om.portlet.Supports)2 HeaderSettingCacheControl (org.apereo.portal.portlet.container.cache.HeaderSettingCacheControl)2 InputStream (java.io.InputStream)1 Serializable (java.io.Serializable)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1