Search in sources :

Example 6 with CharacterEventReader

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

the class JsonWrapperFilteringCharacterEventReaderTest method testFilteringEvents.

@Test
public void testFilteringEvents() {
    final CharacterEventReader baseEventReader = new CharacterEventBufferReader(Arrays.asList(CharacterDataEventImpl.create("<layout>"), JsonLayoutPlaceholderEventImpl.INSTANCE, CharacterDataEventImpl.create("{'yay':json}"), JsonLayoutPlaceholderEventImpl.INSTANCE, CharacterDataEventImpl.create("</layout>")).listIterator());
    final JsonWrapperFilteringCharacterEventReader jsonWrapperFilteringCharacterEventReader = new JsonWrapperFilteringCharacterEventReader(baseEventReader);
    CharacterEvent event;
    assertTrue(jsonWrapperFilteringCharacterEventReader.hasNext());
    event = jsonWrapperFilteringCharacterEventReader.peek();
    assertNotNull(event);
    assertEquals(CharacterEventTypes.CHARACTER, event.getEventType());
    assertTrue(jsonWrapperFilteringCharacterEventReader.hasNext());
    event = jsonWrapperFilteringCharacterEventReader.peek();
    assertNotNull(event);
    assertEquals(CharacterEventTypes.CHARACTER, event.getEventType());
    assertTrue(jsonWrapperFilteringCharacterEventReader.hasNext());
    event = jsonWrapperFilteringCharacterEventReader.next();
    assertNotNull(event);
    assertEquals(CharacterEventTypes.CHARACTER, event.getEventType());
    assertFalse(jsonWrapperFilteringCharacterEventReader.hasNext());
    try {
        event = jsonWrapperFilteringCharacterEventReader.peek();
        fail();
    } catch (NoSuchElementException e) {
    }
    try {
        event = jsonWrapperFilteringCharacterEventReader.next();
        fail();
    } catch (NoSuchElementException e) {
    }
}
Also used : CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) CharacterEventBufferReader(org.apereo.portal.character.stream.CharacterEventBufferReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 7 with CharacterEventReader

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

the class PortletRenderingIncorporationComponent 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 PortletIncorporatingEventReader portletIncorporatingEventReader = new PortletIncorporatingEventReader(eventReader, request, response);
    final Map<String, String> outputProperties = pipelineEventReader.getOutputProperties();
    return new PipelineEventReaderImpl<CharacterEventReader, CharacterEvent>(portletIncorporatingEventReader, outputProperties);
}
Also used : FilteringCharacterEventReader(org.apereo.portal.character.stream.FilteringCharacterEventReader) CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent)

Example 8 with CharacterEventReader

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

the class PortletRenderingInitiationCharacterComponent 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 List<CharacterEvent> eventBuffer = new LinkedList<CharacterEvent>();
    while (eventReader.hasNext()) {
        final CharacterEvent event = eventReader.next();
        switch(event.getEventType()) {
            case PORTLET_HEADER:
                {
                    final PortletHeaderPlaceholderEvent headerEvent = (PortletHeaderPlaceholderEvent) event;
                    final IPortletWindowId portletWindowId = headerEvent.getPortletWindowId();
                    if (!this.portletExecutionManager.isPortletRenderHeaderRequested(portletWindowId, request, response)) {
                        this.portletExecutionManager.startPortletHeaderRender(portletWindowId, request, response);
                    }
                    break;
                }
            case PORTLET_CONTENT:
                {
                    final PortletContentPlaceholderEvent headerEvent = (PortletContentPlaceholderEvent) event;
                    final IPortletWindowId portletWindowId = headerEvent.getPortletWindowId();
                    if (!this.portletExecutionManager.isPortletRenderRequested(portletWindowId, request, response)) {
                        this.portletExecutionManager.startPortletRender(portletWindowId, request, response);
                    }
                    break;
                }
        }
        eventBuffer.add(event);
    }
    final Map<String, String> outputProperties = pipelineEventReader.getOutputProperties();
    final CharacterEventBufferReader bufferEventReader = new CharacterEventBufferReader(eventBuffer.listIterator());
    return new PipelineEventReaderImpl<CharacterEventReader, CharacterEvent>(bufferEventReader, outputProperties);
}
Also used : CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) CharacterEventBufferReader(org.apereo.portal.character.stream.CharacterEventBufferReader) PortletHeaderPlaceholderEvent(org.apereo.portal.character.stream.events.PortletHeaderPlaceholderEvent) PortletContentPlaceholderEvent(org.apereo.portal.character.stream.events.PortletContentPlaceholderEvent) LinkedList(java.util.LinkedList) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 9 with CharacterEventReader

use of org.apereo.portal.character.stream.CharacterEventReader 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 10 with CharacterEventReader

use of org.apereo.portal.character.stream.CharacterEventReader 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)

Aggregations

CharacterEventReader (org.apereo.portal.character.stream.CharacterEventReader)11 CharacterEvent (org.apereo.portal.character.stream.events.CharacterEvent)11 Test (org.junit.Test)4 CharacterEventBufferReader (org.apereo.portal.character.stream.CharacterEventBufferReader)3 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 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 NoSuchElementException (java.util.NoSuchElementException)1 StartElement (javax.xml.stream.events.StartElement)1 Element (net.sf.ehcache.Element)1