Search in sources :

Example 1 with PortletRenderResult

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

the class PortletRenderHeaderExecutionWorker method callInternal.

/**
     * Obtain the RENDER_HEADER output. Note that uPortal supports the model of obtaining HTML
     * markup from the portlet, whether from a Spring view or servlet output and inserting it within
     * the HTML HEAD section of the page. uPortal does not support the model where the portlet
     * creates DOM elements to be written to the HEAD section and constructs the HTML output; e.g.
     * the following does NOT work in uPortal:
     *
     * <p>
     *
     * <pre>
     * Element linkElement = response.createElement(HTML.Tag.SCRIPT.toString());
     * linkElement.setAttribute(HTML.Attribute.TYPE.toString(), "text/javascript");
     * linkElement.setAttribute(HTML.Attribute.SRC.toString(), cssUrl);
     * linkElement.setTextContent(" ");
     * response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, linkElement);
     * </pre>
     *
     * @see PortletExecutionWorker#callInternal()
     */
@Override
protected PortletRenderResult callInternal() throws Exception {
    final String characterEncoding = response.getCharacterEncoding();
    final RenderPortletOutputHandler renderPortletOutputHandler = new RenderPortletOutputHandler(characterEncoding);
    final PortletRenderResult result = portletRenderer.doRenderHeader(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 2 with PortletRenderResult

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

the class PortletCacheControlServiceImplTest method testDetermineCacheScopePortletDefinitionPrivate.

@Test
public void testDetermineCacheScopePortletDefinitionPrivate() {
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    MockPortletWindowId portletWindowId = new MockPortletWindowId("123");
    MockPortletDefinitionId portletDefinitionId = new MockPortletDefinitionId(789);
    PortletDefinition portletDefinition = mock(PortletDefinition.class);
    when(portletDefinition.getCacheScope()).thenReturn("private");
    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(portletDefinition);
    when(urlSyntaxProvider.getPortalRequestInfo(httpRequest)).thenReturn(portalRequestInfo);
    cacheControlService.setPortletWindowRegistry(portletWindowRegistry);
    cacheControlService.setPortletDefinitionRegistry(portletDefinitionRegistry);
    final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
    final CacheControl cacheControl = cacheState.getCacheControl();
    assertFalse(cacheControl.isPublicScope());
}
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) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition) Test(org.junit.Test)

Example 3 with PortletRenderResult

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

the class PortletCacheControlServiceImplTest method testDetermineCacheScopePortletDefinitionPublic.

@Test
public void testDetermineCacheScopePortletDefinitionPublic() {
    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);
    cacheControlService.setPortletWindowRegistry(portletWindowRegistry);
    cacheControlService.setPortletDefinitionRegistry(portletDefinitionRegistry);
    final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
    final CacheControl cacheControl = cacheState.getCacheControl();
    assertTrue(cacheControl.isPublicScope());
}
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 4 with PortletRenderResult

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

the class PortletCacheControlServiceImplTest method testGetCacheControlDataExistsInPrivateCache.

@Test
public void testGetCacheControlDataExistsInPrivateCache() {
    // mock 2 requests, have to share sessionId for private cache
    MockHttpSession mockSession = new MockHttpSession();
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    httpRequest.setSession(mockSession);
    MockHttpServletRequest nextHttpRequest = new MockHttpServletRequest();
    nextHttpRequest.setSession(mockSession);
    MockPortletWindowId portletWindowId = new MockPortletWindowId("123");
    MockPortletDefinitionId portletDefinitionId = new MockPortletDefinitionId(789);
    // use private cache
    when(portletDescriptor.getCacheScope()).thenReturn("private");
    when(portletDescriptor.getExpirationCache()).thenReturn(300);
    when(portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId)).thenReturn(portletWindow);
    when(portletWindowRegistry.getPortletWindow(nextHttpRequest, 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);
    final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
    final CacheControl cacheControl = cacheState.getCacheControl();
    assertFalse(cacheControl.isPublicScope());
    cacheControl.setETag("123456");
    final PortletRenderResult portletResult = new PortletRenderResult("title", null, 0, 1);
    final String content = "<p>Cached content</p>";
    final CachedPortletData<PortletRenderResult> cachedPortletData = new CachedPortletData<PortletRenderResult>(portletResult, content, null, null, cacheControl.isPublicScope(), cacheControl.getETag(), -2);
    cacheControlService.cachePortletRenderOutput(portletWindowId, nextHttpRequest, cacheState, cachedPortletData);
    when(urlSyntaxProvider.getPortalRequestInfo(nextHttpRequest)).thenReturn(portalRequestInfo);
    final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> afterCacheState = cacheControlService.getPortletRenderState(nextHttpRequest, portletWindowId);
    // retrieve cachecontrol again, and return should have etag set
    // note using 'nextHttpRequest'
    Assert.assertEquals("123456", afterCacheState.getCacheControl().getETag());
}
Also used : MockPortletDefinitionId(org.apereo.portal.mock.portlet.om.MockPortletDefinitionId) PortletRenderResult(org.apereo.portal.portlet.rendering.PortletRenderResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpSession(org.springframework.mock.web.MockHttpSession) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) CacheControl(javax.portlet.CacheControl) Test(org.junit.Test)

Example 5 with PortletRenderResult

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

the class PortletCacheControlServiceImpl method getPortletRenderHeaderState.

@Override
public CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> getPortletRenderHeaderState(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-header cache key
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    final Locale locale = RequestContextUtils.getLocale(request);
    final PublicPortletCacheKey publicCacheKey = PublicPortletCacheKey.createPublicPortletRenderHeaderCacheKey(portletWindow, portalRequestInfo, locale);
    return this.<CachedPortletData<PortletRenderResult>, PortletRenderResult>getPortletState(request, portletWindow, publicCacheKey, this.publicScopePortletRenderHeaderOutputCache, this.privateScopePortletRenderHeaderOutputCache, 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)

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