Search in sources :

Example 6 with PortletRenderResult

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

the class PortletCacheControlServiceImpl method getPortletRenderState.

@Override
public CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> getPortletRenderState(HttpServletRequest request, IPortletWindowId portletWindowId) {
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, portletWindowId);
    if (portletWindow == null) {
        logger.warn("portletWindowRegistry returned null for {}, returning default cacheControl and no cached portlet data", portletWindowId);
        return new CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult>();
    }
    //Generate the public render cache key
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    final Locale locale = RequestContextUtils.getLocale(request);
    final PublicPortletCacheKey publicCacheKey = PublicPortletCacheKey.createPublicPortletRenderCacheKey(portletWindow, portalRequestInfo, locale);
    return this.<CachedPortletData<PortletRenderResult>, PortletRenderResult>getPortletState(request, portletWindow, publicCacheKey, this.publicScopePortletRenderOutputCache, this.privateScopePortletRenderOutputCache, false);
}
Also used : Locale(java.util.Locale) IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) PortletRenderResult(org.apereo.portal.portlet.rendering.PortletRenderResult) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow)

Example 7 with PortletRenderResult

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

the class PortletRenderExecutionWorker method callInternal.

@Override
protected PortletRenderResult callInternal() throws Exception {
    final String characterEncoding = response.getCharacterEncoding();
    final RenderPortletOutputHandler renderPortletOutputHandler = new RenderPortletOutputHandler(characterEncoding);
    final PortletRenderResult result = portletRenderer.doRenderMarkup(portletWindowId, request, response, renderPortletOutputHandler);
    this.output = renderPortletOutputHandler.getOutput();
    return result;
}
Also used : RenderPortletOutputHandler(org.apereo.portal.portlet.rendering.RenderPortletOutputHandler) PortletRenderResult(org.apereo.portal.portlet.rendering.PortletRenderResult)

Example 8 with PortletRenderResult

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

the class PortletCacheControlServiceImplTest method testCachePrivateRenderRoundTrip.

@Test
public void testCachePrivateRenderRoundTrip() {
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    MockPortletWindowId portletWindowId = new MockPortletWindowId("123");
    MockPortletDefinitionId portletDefinitionId = new MockPortletDefinitionId(789);
    when(portletDescriptor.getCacheScope()).thenReturn(MimeResponse.PUBLIC_SCOPE);
    when(portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId)).thenReturn(portletWindow);
    when(portletWindow.getPortletWindowId()).thenReturn(portletWindowId);
    when(portletWindow.getPortletEntity()).thenReturn(portletEntity);
    when(portletWindow.getWindowState()).thenReturn(WindowState.NORMAL);
    when(portletWindow.getPortletMode()).thenReturn(PortletMode.VIEW);
    when(portletEntity.getPortletDefinitionId()).thenReturn(portletDefinitionId);
    when(portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId)).thenReturn(portletDescriptor);
    when(urlSyntaxProvider.getPortalRequestInfo(httpRequest)).thenReturn(portalRequestInfo);
    when(this.urlSyntaxProvider.getPortalRequestInfo(httpRequest)).thenReturn(portalRequestInfo);
    when(portalRequestInfo.getPortletRequestInfoMap()).thenReturn(Collections.EMPTY_MAP);
    //Get the initial cache state
    final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> firstCacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
    //Fake Render execution
    final CacheControl cacheControl = firstCacheState.getCacheControl();
    cacheControl.setExpirationTime(300);
    final PortletRenderResult renderResult = new PortletRenderResult("title", null, 0, 1000l);
    final String output = "{ \"hello\": \"world\" }";
    final CachedPortletData<PortletRenderResult> cachedPortletData = new CachedPortletData<PortletRenderResult>(renderResult, output, null, null, false, cacheControl.getETag(), cacheControl.getExpirationTime());
    firstCacheState.setCachedPortletData(cachedPortletData);
    assertTrue(cacheControlService.shouldOutputBeCached(cacheControl));
    //Cache the results
    cacheControlService.cachePortletRenderOutput(portletWindowId, httpRequest, firstCacheState, cachedPortletData);
    //Check the cached results
    final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> secondCacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
    assertNotNull(secondCacheState);
    final CachedPortletData<PortletRenderResult> actualCachedPortletData = secondCacheState.getCachedPortletData();
    assertNotNull(actualCachedPortletData);
}
Also used : MockPortletDefinitionId(org.apereo.portal.mock.portlet.om.MockPortletDefinitionId) PortletRenderResult(org.apereo.portal.portlet.rendering.PortletRenderResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) CacheControl(javax.portlet.CacheControl) Test(org.junit.Test)

Example 9 with PortletRenderResult

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

the class PortletCacheControlServiceImplTest method testGetCacheControlDefault.

@Test
public void testGetCacheControlDefault() {
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    MockPortletWindowId portletWindowId = new MockPortletWindowId("123");
    MockPortletDefinitionId portletDefinitionId = new MockPortletDefinitionId(789);
    when(portletDescriptor.getCacheScope()).thenReturn(null);
    final IPortletWindowRegistry portletWindowRegistry = mock(IPortletWindowRegistry.class);
    final IPortletWindow portletWindow = mock(IPortletWindow.class);
    final IPortletEntity portletEntity = mock(IPortletEntity.class);
    when(portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId)).thenReturn(portletWindow);
    when(portletWindow.getPortletEntity()).thenReturn(portletEntity);
    when(portletWindow.getWindowState()).thenReturn(WindowState.NORMAL);
    when(portletWindow.getPortletMode()).thenReturn(PortletMode.VIEW);
    when(portletEntity.getPortletDefinitionId()).thenReturn(portletDefinitionId);
    when(portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId)).thenReturn(portletDescriptor);
    final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
    final CacheControl cacheControl = cacheState.getCacheControl();
    assertFalse(cacheControl.isPublicScope());
    assertNull(cacheControl.getETag());
}
Also used : MockPortletDefinitionId(org.apereo.portal.mock.portlet.om.MockPortletDefinitionId) IPortletWindowRegistry(org.apereo.portal.portlet.registry.IPortletWindowRegistry) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) PortletRenderResult(org.apereo.portal.portlet.rendering.PortletRenderResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) CacheControl(javax.portlet.CacheControl) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) Test(org.junit.Test)

Aggregations

PortletRenderResult (org.apereo.portal.portlet.rendering.PortletRenderResult)9 CacheControl (javax.portlet.CacheControl)5 MockPortletDefinitionId (org.apereo.portal.mock.portlet.om.MockPortletDefinitionId)5 MockPortletWindowId (org.apereo.portal.mock.portlet.om.MockPortletWindowId)5 Test (org.junit.Test)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)3 Locale (java.util.Locale)2 RenderPortletOutputHandler (org.apereo.portal.portlet.rendering.RenderPortletOutputHandler)2 IPortalRequestInfo (org.apereo.portal.url.IPortalRequestInfo)2 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)1 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)1 IPortletWindowRegistry (org.apereo.portal.portlet.registry.IPortletWindowRegistry)1 MockHttpSession (org.springframework.mock.web.MockHttpSession)1