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;
}
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());
}
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());
}
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());
}
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);
}
Aggregations