Search in sources :

Example 1 with RenderingPipelineConfigurationException

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

the class RenderingPipelineConfiguration method getPortalRenderingPipeline.

/**
 * This bean is the entry point into the uPortal Rendering Pipeline. It supports {@link
 * RenderingPipelineBranchPoint} beans, which are an extension point for adopters.
 */
@Bean(name = "portalRenderingPipeline")
@Qualifier(value = "main")
public IPortalRenderingPipeline getPortalRenderingPipeline() {
    // Rendering Pipeline Branches (adopter extension point)
    final List<RenderingPipelineBranchPoint> sortedList = (branchPoints != null) ? new LinkedList<>(branchPoints) : Collections.emptyList();
    Collections.sort(sortedList);
    final List<RenderingPipelineBranchPoint> branches = Collections.unmodifiableList(sortedList);
    /*
         * Sanity check:  if you have multiple RenderingPipelineBranchPoint beans, you can specify
         * an 'order' property on some or all of them to control the sequence of processing.
         * Having 2 RenderingPipelineBranchPoint beans with the same order value will produce
         * non-deterministic results and is a likely source of misconfiguration.
         */
    final Set<Integer> usedOderValues = new HashSet<>();
    boolean hasCollision = branches.stream().anyMatch(branchPoint -> {
        final boolean rslt = usedOderValues.contains(branchPoint.getOrder());
        usedOderValues.add(branchPoint.getOrder());
        return rslt;
    });
    if (hasCollision) {
        throw new RenderingPipelineConfigurationException("Multiple RenderingPipelineBranchPoint beans have the same 'order' value, which likely a misconfiguration");
    }
    // "Standard" Pipeline
    final IPortalRenderingPipeline standardRenderingPipeline = getStandardRenderingPipeline();
    return new IPortalRenderingPipeline() {

        @Override
        public void renderState(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
            for (RenderingPipelineBranchPoint branchPoint : branches) {
                if (branchPoint.renderStateIfApplicable(req, res)) {
                    /*
                         * Rendering bas been processed by the branch point -- no need to continue.
                         */
                    return;
                }
            }
            /*
                 * Reaching this point means that a branch was not followed; use the "standard"
                 * pipeline.
                 */
            standardRenderingPipeline.renderState(req, res);
        }
    };
}
Also used : IPortalRenderingPipeline(org.apereo.portal.rendering.IPortalRenderingPipeline) HttpServletRequest(javax.servlet.http.HttpServletRequest) RenderingPipelineBranchPoint(org.apereo.portal.rendering.RenderingPipelineBranchPoint) RenderingPipelineConfigurationException(org.apereo.portal.rendering.RenderingPipelineConfigurationException) HttpServletResponse(javax.servlet.http.HttpServletResponse) HashSet(java.util.HashSet) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Bean(org.springframework.context.annotation.Bean)

Example 2 with RenderingPipelineConfigurationException

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

the class JsonLayoutRenderingPipeline method renderState.

@Override
public void renderState(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException, IllegalStateException {
    // 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);
    // set the response mime type
    final String contentType = "application/json; charset=" + CHARACTER_SET;
    res.setContentType(contentType);
    final PrintWriter writer = res.getWriter();
    if (pipelineEventReader != null) {
        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();
        }
    } else {
        logger.warn("PipelineEventReader is null");
        throw new IllegalStateException("PipelineEventReader is null");
    }
    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) RenderingPipelineConfigurationException(org.apereo.portal.rendering.RenderingPipelineConfigurationException) CharacterDataEvent(org.apereo.portal.character.stream.events.CharacterDataEvent) PrintWriter(java.io.PrintWriter)

Aggregations

RenderingPipelineConfigurationException (org.apereo.portal.rendering.RenderingPipelineConfigurationException)2 PrintWriter (java.io.PrintWriter)1 HashSet (java.util.HashSet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 CharacterEventReader (org.apereo.portal.character.stream.CharacterEventReader)1 CharacterDataEvent (org.apereo.portal.character.stream.events.CharacterDataEvent)1 CharacterEvent (org.apereo.portal.character.stream.events.CharacterEvent)1 IPortalRenderingPipeline (org.apereo.portal.rendering.IPortalRenderingPipeline)1 RenderingPipelineBranchPoint (org.apereo.portal.rendering.RenderingPipelineBranchPoint)1 IPortalRequestInfo (org.apereo.portal.url.IPortalRequestInfo)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 Bean (org.springframework.context.annotation.Bean)1