Package javax.portlet

Examples of javax.portlet.CacheControl


  public void doServeResourceCachedContentReplayHeadersTest() throws PortletException, IOException, PortletContainerException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    TestingCacheState<CachedPortletResourceData<Long>, Long> cacheState = new TestingCacheState<CachedPortletResourceData<Long>, Long>();
    cacheState.setUseCachedData(true);
        CacheControl cacheControl = cacheState.getCacheControl();
    cacheControl.setUseCachedContent(true);
    cacheControl.setExpirationTime(300);
       
        final String output = "{ \"hello\": \"world\" }";
        final Map<String, List<Serializable>> headers = ImmutableMap.<String, List<Serializable>>of(
                "header1", Arrays.<Serializable>asList("value1"),
                "header2", Arrays.<Serializable>asList("value2", "value3"));
       
        final CachedPortletData<Long> cachedPortletData = new CachedPortletData<Long>(
                1000l, output, null, "application/json", false, cacheControl.getETag(), cacheControl.getExpirationTime());
        final CachedPortletResourceData<Long> cachedPortletResourceData = new CachedPortletResourceData<Long>(
                cachedPortletData, headers, null, null, null, null);
        cacheState.setCachedPortletData(cachedPortletResourceData);
   
    setupPortletExecutionMocks(request);
View Full Code Here


        }
       
        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(ATTRIBUTE__PORTLET_CACHE_CONTROL, cacheControl);
        httpServletRequest.setAttribute(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);
        }
View Full Code Here

        }
       
        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(ATTRIBUTE__PORTLET_CACHE_CONTROL, cacheControl);
        httpServletRequest.setAttribute(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");
View Full Code Here

                return cacheState;
            }
        }
       
        //Build CacheControl structure
        final CacheControl cacheControl = cacheState.getCacheControl();
       
        //Get the portlet descriptor
        final IPortletEntity entity = portletWindow.getPortletEntity();
        final IPortletDefinitionId definitionId = entity.getPortletDefinitionId();
        final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(definitionId);
       
        //Set the default scope
        final String cacheScopeValue = portletDescriptor.getCacheScope();
        if (MimeResponse.PUBLIC_SCOPE.equalsIgnoreCase(cacheScopeValue)) {
            cacheControl.setPublicScope(true);
        }
       
        //Set the default expiration time
        cacheControl.setExpirationTime(portletDescriptor.getExpirationCache());
       
        // Use the request etag if it exists (implies useHttpHeaders==true)
        if (etagHeader != null) {
            cacheControl.setETag(etagHeader);
            cacheState.setBrowserSetEtag(true);
        }
        // No browser-set etag, use the cached etag value if there is cached data
        else if (cachedPortletData != null) {
            logger.debug("setting cacheControl.eTag from cached data to {}", cachedPortletData.getEtag());
            cacheControl.setETag(cachedPortletData.getEtag());
        }
       
        return cacheState;
    }
View Full Code Here

    private <D extends CachedPortletResultHolder<T>, T extends Serializable> void cachePortletOutput(IPortletWindowId portletWindowId, HttpServletRequest httpRequest,
            CacheState<D, T> cacheState, D cachedPortletData, Ehcache publicOutputCache, Ehcache privateOutputCache) {
       
        final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId);
        final CacheControl cacheControl = cacheState.getCacheControl();
       
        if (cacheControl.isPublicScope()) {
            final PublicPortletCacheKey publicCacheKey = cacheState.getPublicPortletCacheKey();
            this.cacheElement(publicOutputCache, publicCacheKey, cachedPortletData, cacheControl);
            logger.debug("Cached public data under key {} for {}", publicCacheKey, portletWindow);
        }
        else {
View Full Code Here

TOP

Related Classes of javax.portlet.CacheControl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.