Search in sources :

Example 11 with CharacterEvent

use of org.apereo.portal.character.stream.events.CharacterEvent in project uPortal by Jasig.

the class LoggingCharacterComponent method getEventReader.

/* (non-Javadoc)
     * @see org.apereo.portal.rendering.PipelineComponent#getEventReader(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
public PipelineEventReader<CharacterEventReader, CharacterEvent> getEventReader(HttpServletRequest request, HttpServletResponse response) {
    final PipelineEventReader<CharacterEventReader, CharacterEvent> pipelineEventReader = this.wrappedComponent.getEventReader(request, response);
    final CharacterEventReader eventReader = pipelineEventReader.getEventReader();
    final LoggingCharacterEventReader loggingEventReader = new LoggingCharacterEventReader(eventReader);
    final Map<String, String> outputProperties = pipelineEventReader.getOutputProperties();
    return new PipelineEventReaderImpl<CharacterEventReader, CharacterEvent>(loggingEventReader, outputProperties);
}
Also used : CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) FilteringCharacterEventReader(org.apereo.portal.character.stream.FilteringCharacterEventReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent)

Example 12 with CharacterEvent

use of org.apereo.portal.character.stream.events.CharacterEvent in project uPortal by Jasig.

the class DynamicRenderingPipeline method renderState.

@Override
public void renderState(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    //Disable page caching
    res.setHeader("pragma", "no-cache");
    res.setHeader("Cache-Control", "no-cache, max-age=0, must-revalidate");
    res.setDateHeader("Expires", 0);
    final long startTime = System.nanoTime();
    final PipelineEventReader<CharacterEventReader, CharacterEvent> pipelineEventReader = this.pipeline.getEventReader(req, res);
    final String mediaType = getMediaType(req, res, pipelineEventReader);
    // set the response mime type
    final String contentType = mediaType + "; charset=" + CHARACTER_SET;
    res.setContentType(contentType);
    final PrintWriter writer = res.getWriter();
    for (final CharacterEvent event : pipelineEventReader) {
        if (CharacterEventTypes.CHARACTER != event.getEventType()) {
            throw new RenderingPipelineConfigurationException("Only " + CharacterEventTypes.CHARACTER + " events are supported in the top level renderer. " + event.getEventType() + " is not supported.");
        }
        final String data = ((CharacterDataEvent) event).getData();
        writer.print(data);
        writer.flush();
        res.flushBuffer();
    }
    final long executionTime = System.nanoTime() - startTime;
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(req);
    this.portalEventFactory.publishPortalRenderEvent(req, this, req.getPathInfo(), executionTime, portalRequestInfo);
}
Also used : CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) CharacterDataEvent(org.apereo.portal.character.stream.events.CharacterDataEvent) PrintWriter(java.io.PrintWriter)

Example 13 with CharacterEvent

use of org.apereo.portal.character.stream.events.CharacterEvent in project uPortal by Jasig.

the class StAXSerializingComponentTest method testSerializing.

@Test
public void testSerializing() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final IPortletWindowRegistry portletWindowRegistry = mock(IPortletWindowRegistry.class);
    when(xmlUtilities.getHtmlOutputFactory()).thenReturn(XMLOutputFactory.newFactory());
    //Setup a simple pass-through parent
    staxSerializingComponent.setWrappedComponent(new SimpleStAXSource());
    staxSerializingComponent.setXmlUtilities(xmlUtilities);
    final IPortletWindow portletWindow = mock(IPortletWindow.class);
    when(portletWindowRegistry.getPortletWindow(Matchers.eq(request), Matchers.any(StartElement.class))).thenReturn(new Tuple<IPortletWindow, StartElement>(portletWindow, null));
    when(portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(Matchers.eq(request), Matchers.anyString())).thenReturn(portletWindow);
    final PortletContentPlaceholderEventSource contentPlaceholderEventSource = new PortletContentPlaceholderEventSource();
    contentPlaceholderEventSource.setPortletWindowRegistry(portletWindowRegistry);
    final PortletHeaderPlaceholderEventSource headerPlaceholderEventSource = new PortletHeaderPlaceholderEventSource();
    headerPlaceholderEventSource.setPortletWindowRegistry(portletWindowRegistry);
    final PortletTitlePlaceholderEventSource portletTitlePlaceholderEventSource = new PortletTitlePlaceholderEventSource();
    portletTitlePlaceholderEventSource.setPortletWindowRegistry(portletWindowRegistry);
    final PortletHelpPlaceholderEventSource portletHelpPlaceholderEventSource = new PortletHelpPlaceholderEventSource();
    portletHelpPlaceholderEventSource.setPortletWindowRegistry(portletWindowRegistry);
    final Map<String, CharacterEventSource> chunkingElements = new LinkedHashMap<String, CharacterEventSource>();
    chunkingElements.put("portlet", contentPlaceholderEventSource);
    chunkingElements.put("portlet-header", headerPlaceholderEventSource);
    staxSerializingComponent.setChunkingElements(chunkingElements);
    final Map<String, CharacterEventSource> chunkingPatterns = new LinkedHashMap<String, CharacterEventSource>();
    chunkingPatterns.put("\\{up-portlet-title\\(([^\\)]+)\\)\\}", portletTitlePlaceholderEventSource);
    chunkingPatterns.put("\\{up-portlet-help\\(([^\\)]+)\\)\\}", portletHelpPlaceholderEventSource);
    staxSerializingComponent.setChunkingPatterns(chunkingPatterns);
    final PipelineEventReader<CharacterEventReader, CharacterEvent> eventReader = staxSerializingComponent.getEventReader(request, response);
    //Expected events structure, leaving the data out to make it at least a little simpler
    final List<? extends CharacterEvent> expectedEvents = this.getExpectedEvents();
    final Iterator<CharacterEvent> eventItr = eventReader.iterator();
    final Iterator<? extends CharacterEvent> expectedEventsItr = expectedEvents.iterator();
    int eventCount = 0;
    while (expectedEventsItr.hasNext()) {
        eventCount++;
        assertTrue("The number of events returned by the eventReader less than the expected event count of: " + expectedEvents.size() + " was: " + eventCount, eventItr.hasNext());
        final CharacterEvent expectedEvent = expectedEventsItr.next();
        final CharacterEvent event = eventItr.next();
        assertEquals("Events at index " + eventCount + " do not match\n" + expectedEvent + "\n" + event, expectedEvent, event);
    }
    assertFalse("The number of events returned by the eventReader is more than the expected event count of: " + expectedEvents.size(), eventItr.hasNext());
}
Also used : PortletHeaderPlaceholderEventSource(org.apereo.portal.character.stream.PortletHeaderPlaceholderEventSource) IPortletWindowRegistry(org.apereo.portal.portlet.registry.IPortletWindowRegistry) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) LinkedHashMap(java.util.LinkedHashMap) StartElement(javax.xml.stream.events.StartElement) CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) PortletHelpPlaceholderEventSource(org.apereo.portal.character.stream.PortletHelpPlaceholderEventSource) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) PortletTitlePlaceholderEventSource(org.apereo.portal.character.stream.PortletTitlePlaceholderEventSource) CharacterEventSource(org.apereo.portal.character.stream.CharacterEventSource) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) PortletContentPlaceholderEventSource(org.apereo.portal.character.stream.PortletContentPlaceholderEventSource) Test(org.junit.Test)

Example 14 with CharacterEvent

use of org.apereo.portal.character.stream.events.CharacterEvent in project uPortal by Jasig.

the class FilteringCharacterEventReader method internalNext.

protected final CharacterEvent internalNext(boolean peek) {
    CharacterEvent event = null;
    if (peekedEvent != null) {
        event = peekedEvent;
        peekedEvent = null;
        return event;
    }
    do {
        event = super.next();
        event = this.filterEvent(event, peek);
    } while (event == null);
    return event;
}
Also used : CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent)

Aggregations

CharacterEvent (org.apereo.portal.character.stream.events.CharacterEvent)14 CharacterEventReader (org.apereo.portal.character.stream.CharacterEventReader)11 CharacterEventBufferReader (org.apereo.portal.character.stream.CharacterEventBufferReader)4 Test (org.junit.Test)4 FilteringCharacterEventReader (org.apereo.portal.character.stream.FilteringCharacterEventReader)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 PrintWriter (java.io.PrintWriter)2 Ehcache (net.sf.ehcache.Ehcache)2 CharacterDataEvent (org.apereo.portal.character.stream.events.CharacterDataEvent)2 CharacterPipelineComponent (org.apereo.portal.rendering.CharacterPipelineComponent)2 PipelineEventReaderImpl (org.apereo.portal.rendering.PipelineEventReaderImpl)2 IPortalRequestInfo (org.apereo.portal.url.IPortalRequestInfo)2 CacheKey (org.apereo.portal.utils.cache.CacheKey)2 ResourcesElementsProvider (org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider)2 StringWriter (java.io.StringWriter)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 NoSuchElementException (java.util.NoSuchElementException)1 XMLEventReader (javax.xml.stream.XMLEventReader)1