Search in sources :

Example 1 with CharacterEventBufferReader

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

the class CachingCharacterPipelineComponentTest method testCacheMiss.

@Test
public void testCacheMiss() {
    final MockHttpServletRequest mockReq = new MockHttpServletRequest();
    final MockHttpServletResponse mockRes = new MockHttpServletResponse();
    final CacheKey cacheKey = CacheKey.build("testCacheKey");
    final List<CharacterEvent> eventBuffer = Collections.emptyList();
    final PipelineEventReader<CharacterEventReader, CharacterEvent> eventReader = new PipelineEventReaderImpl<CharacterEventReader, CharacterEvent>(new CharacterEventBufferReader(eventBuffer.listIterator()));
    final Ehcache cache = createMock(Ehcache.class);
    final CharacterPipelineComponent targetComponent = createMock(CharacterPipelineComponent.class);
    final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
    expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
    expect(targetComponent.getCacheKey(mockReq, mockRes)).andReturn(cacheKey);
    expect(cache.get(cacheKey)).andReturn(null);
    expect(targetComponent.getEventReader(mockReq, mockRes)).andReturn(eventReader);
    cache.put((Element) notNull());
    expectLastCall();
    replay(cache, targetComponent, elementsProvider);
    final CachingCharacterPipelineComponent cachingComponent = new CachingCharacterPipelineComponent();
    cachingComponent.setCache(cache);
    cachingComponent.setWrappedComponent(targetComponent);
    cachingComponent.setResourcesElementsProvider(elementsProvider);
    final PipelineEventReader<CharacterEventReader, CharacterEvent> actualEventReader = cachingComponent.getEventReader(mockReq, mockRes);
    Assert.assertNotNull(actualEventReader);
    Assert.assertNotNull(actualEventReader.getEventReader());
    Assert.assertFalse(actualEventReader.getEventReader().hasNext());
    verify(cache, targetComponent, elementsProvider);
}
Also used : CharacterPipelineComponent(org.apereo.portal.rendering.CharacterPipelineComponent) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) CharacterEventBufferReader(org.apereo.portal.character.stream.CharacterEventBufferReader) ResourcesElementsProvider(org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider) PipelineEventReaderImpl(org.apereo.portal.rendering.PipelineEventReaderImpl) Ehcache(net.sf.ehcache.Ehcache) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CacheKey(org.apereo.portal.utils.cache.CacheKey) Test(org.junit.Test)

Example 2 with CharacterEventBufferReader

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

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

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

the class StAXSerializingComponent method getEventReader.

@Override
public PipelineEventReader<CharacterEventReader, CharacterEvent> getEventReader(HttpServletRequest request, HttpServletResponse response) {
    final PipelineEventReader<XMLEventReader, XMLEvent> eventReader = this.wrappedComponent.getEventReader(request, response);
    //Writer shared by the ChunkingEventReader and the StAX Serializer
    final StringWriter writer = new StringWriter();
    final XMLOutputFactory outputFactory = this.xmlUtilities.getHtmlOutputFactory();
    final XMLEventWriter xmlEventWriter;
    try {
        xmlEventWriter = outputFactory.createXMLEventWriter(writer);
    } catch (XMLStreamException e) {
        throw new RuntimeException("Failed to create XMLEventWriter", e);
    }
    //Add the chunking wrapper to the XMLEventReader
    final XMLEventReader xmlEventReader = eventReader.getEventReader();
    final ChunkingEventReader chunkingEventReader = new ChunkingEventReader(request, this.chunkingElements, this.chunkingPatternEventSources, this.chunkingPatterns, xmlEventReader, xmlEventWriter, writer);
    try {
        xmlEventWriter.add(chunkingEventReader);
        xmlEventWriter.flush();
        xmlEventWriter.close();
        chunkingEventReader.close();
    } catch (XMLStreamException e) {
        throw new RuntimeException("Failed to write events to Writer", e);
    }
    //Return the chunked data
    final List<CharacterEvent> characterEvents = chunkingEventReader.getCharacterEvents();
    final CharacterEventBufferReader characterEventReader = new CharacterEventBufferReader(characterEvents.listIterator());
    final Map<String, String> outputProperties = eventReader.getOutputProperties();
    return new PipelineEventReaderImpl<CharacterEventReader, CharacterEvent>(characterEventReader, outputProperties);
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) ChunkingEventReader(org.apereo.portal.xml.stream.ChunkingEventReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) CharacterEventBufferReader(org.apereo.portal.character.stream.CharacterEventBufferReader) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEventWriter(javax.xml.stream.XMLEventWriter) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader)

Aggregations

CharacterEventBufferReader (org.apereo.portal.character.stream.CharacterEventBufferReader)4 CharacterEvent (org.apereo.portal.character.stream.events.CharacterEvent)4 CharacterEventReader (org.apereo.portal.character.stream.CharacterEventReader)3 Test (org.junit.Test)2 StringWriter (java.io.StringWriter)1 LinkedList (java.util.LinkedList)1 NoSuchElementException (java.util.NoSuchElementException)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLEventWriter (javax.xml.stream.XMLEventWriter)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLEvent (javax.xml.stream.events.XMLEvent)1 Ehcache (net.sf.ehcache.Ehcache)1 PortletContentPlaceholderEvent (org.apereo.portal.character.stream.events.PortletContentPlaceholderEvent)1 PortletHeaderPlaceholderEvent (org.apereo.portal.character.stream.events.PortletHeaderPlaceholderEvent)1 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)1 CharacterPipelineComponent (org.apereo.portal.rendering.CharacterPipelineComponent)1 PipelineEventReaderImpl (org.apereo.portal.rendering.PipelineEventReaderImpl)1 CacheKey (org.apereo.portal.utils.cache.CacheKey)1 ChunkingEventReader (org.apereo.portal.xml.stream.ChunkingEventReader)1