Search in sources :

Example 16 with IPortletWindowId

use of org.apereo.portal.portlet.om.IPortletWindowId in project uPortal by Jasig.

the class PortletExecutionManager method startPortletRenderInternal.

/**
 * create and submit the portlet content rendering job to the thread pool
 */
protected IPortletRenderExecutionWorker startPortletRenderInternal(IPortletWindowId portletWindowId, HttpServletRequest request, HttpServletResponse response) {
    // first check to see if there is a Throwable in the session for this IPortletWindowId
    final Map<IPortletWindowId, Exception> portletFailureMap = getPortletErrorMap(request);
    final Exception cause = portletFailureMap.remove(portletWindowId);
    final IPortletRenderExecutionWorker portletRenderExecutionWorker;
    if (null != cause) {
        // previous action failed, dispatch to errorPortlet immediately
        portletRenderExecutionWorker = this.portletWorkerFactory.createFailureWorker(request, response, portletWindowId, cause);
    } else {
        IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(request, portletWindowId);
        IPortletDefinition portletDef = portletWindow.getPortletEntity().getPortletDefinition();
        if (portletDef.getLifecycleState().equals(PortletLifecycleState.MAINTENANCE)) {
            // Prevent the portlet from rendering;  replace with a helpful "Out of Service"
            // message
            final IPortletDefinitionParameter messageParam = portletDef.getParameter(PortletLifecycleState.CUSTOM_MAINTENANCE_MESSAGE_PARAMETER_NAME);
            final Exception mme = messageParam != null && StringUtils.isNotBlank(messageParam.getValue()) ? new MaintenanceModeException(messageParam.getValue()) : new MaintenanceModeException();
            portletRenderExecutionWorker = this.portletWorkerFactory.createFailureWorker(request, response, portletWindowId, mme);
        } else {
            // Happy path
            portletRenderExecutionWorker = this.portletWorkerFactory.createRenderWorker(request, response, portletWindowId);
        }
    }
    portletRenderExecutionWorker.submit();
    final Map<IPortletWindowId, IPortletRenderExecutionWorker> portletRenderingMap = this.getPortletRenderingMap(request);
    portletRenderingMap.put(portletWindowId, portletRenderExecutionWorker);
    return portletRenderExecutionWorker;
}
Also used : MaintenanceModeException(org.apereo.portal.portlets.error.MaintenanceModeException) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) IPortletRenderExecutionWorker(org.apereo.portal.portlet.rendering.worker.IPortletRenderExecutionWorker) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IOException(java.io.IOException) MaintenanceModeException(org.apereo.portal.portlets.error.MaintenanceModeException) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 17 with IPortletWindowId

use of org.apereo.portal.portlet.om.IPortletWindowId in project uPortal by Jasig.

the class PortletExecutionManager method doPortletEvents.

public void doPortletEvents(PortletEventQueue eventQueue, HttpServletRequest request, HttpServletResponse response) {
    if (eventQueue.getUnresolvedEvents().isEmpty()) {
        return;
    }
    final Map<IPortletWindowId, IPortletExecutionWorker<Long>> eventWorkers = new LinkedHashMap<IPortletWindowId, IPortletExecutionWorker<Long>>();
    // TODO what to do if we hit the max iterations?
    int iteration = 0;
    for (; iteration < this.maxEventIterations; iteration++) {
        // Make sure all queued events have been resolved
        this.eventCoordinationService.resolvePortletEvents(request, eventQueue);
        // Create and submit an event worker for each window with a queued event
        for (final IPortletWindowId eventWindowId : eventQueue) {
            if (eventWorkers.containsKey(eventWindowId)) {
                /*
                     * PLT.15.2.5 says that event processing per window must be serialized, if there
                     * is already a working in the map for the window ID skip it for now. we'll get back to it eventually
                     */
                continue;
            }
            final QueuedEvent queuedEvent = eventQueue.pollEvent(eventWindowId);
            if (queuedEvent != null) {
                final Event event = queuedEvent.getEvent();
                final IPortletExecutionWorker<Long> portletEventExecutionWorker = this.portletWorkerFactory.createEventWorker(request, response, eventWindowId, event);
                eventWorkers.put(eventWindowId, portletEventExecutionWorker);
                portletEventExecutionWorker.submit();
            }
        }
        // If no event workers exist we're done with event processing!
        if (eventWorkers.isEmpty()) {
            return;
        }
        // See if any of the events have completed
        int completedEventWorkers = 0;
        final Set<Entry<IPortletWindowId, IPortletExecutionWorker<Long>>> entrySet = eventWorkers.entrySet();
        for (final Iterator<Entry<IPortletWindowId, IPortletExecutionWorker<Long>>> eventWorkerEntryItr = entrySet.iterator(); eventWorkerEntryItr.hasNext(); ) {
            final Entry<IPortletWindowId, IPortletExecutionWorker<Long>> eventWorkerEntry = eventWorkerEntryItr.next();
            final IPortletExecutionWorker<Long> eventWorker = eventWorkerEntry.getValue();
            if (eventWorker.isComplete()) {
                final IPortletWindowId portletWindowId = eventWorkerEntry.getKey();
                // TODO return number of new queued events, use to break the loop earlier
                waitForEventWorker(request, eventQueue, eventWorker, portletWindowId);
                eventWorkerEntryItr.remove();
                completedEventWorkers++;
            }
        }
        /*
             * If no event workers have completed without waiting wait for the first one and then loop again
             * Not waiting for all events since each event may spawn more events and we want to start them
             * processing as soon as possible
             */
        if (completedEventWorkers == 0) {
            final Iterator<Entry<IPortletWindowId, IPortletExecutionWorker<Long>>> eventWorkerEntryItr = entrySet.iterator();
            final Entry<IPortletWindowId, IPortletExecutionWorker<Long>> eventWorkerEntry = eventWorkerEntryItr.next();
            eventWorkerEntryItr.remove();
            final IPortletWindowId portletWindowId = eventWorkerEntry.getKey();
            final IPortletExecutionWorker<Long> eventWorker = eventWorkerEntry.getValue();
            waitForEventWorker(request, eventQueue, eventWorker, portletWindowId);
        }
    }
    if (iteration == this.maxEventIterations) {
        this.logger.error("The Event dispatching iteration maximum of " + this.maxEventIterations + " was hit, consider either raising this limit or reviewing the portlets that use events to reduce the number of events spawned");
    }
}
Also used : IPortletExecutionWorker(org.apereo.portal.portlet.rendering.worker.IPortletExecutionWorker) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) Event(javax.portlet.Event) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 18 with IPortletWindowId

use of org.apereo.portal.portlet.om.IPortletWindowId in project uPortal by Jasig.

the class PortletExecutionManager method startPortletHeaderRenderInternal.

/**
 * create and submit the portlet header rendering job to the thread pool
 *
 * @param portletWindowId
 * @param request
 * @param response
 * @return
 */
protected IPortletRenderExecutionWorker startPortletHeaderRenderInternal(IPortletWindowId portletWindowId, HttpServletRequest request, HttpServletResponse response) {
    IPortletRenderExecutionWorker portletHeaderRenderWorker = this.portletWorkerFactory.createRenderHeaderWorker(request, response, portletWindowId);
    portletHeaderRenderWorker.submit();
    final Map<IPortletWindowId, IPortletRenderExecutionWorker> portletHeaderRenderingMap = this.getPortletHeaderRenderingMap(request);
    portletHeaderRenderingMap.put(portletWindowId, portletHeaderRenderWorker);
    return portletHeaderRenderWorker;
}
Also used : IPortletRenderExecutionWorker(org.apereo.portal.portlet.rendering.worker.IPortletRenderExecutionWorker) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 19 with IPortletWindowId

use of org.apereo.portal.portlet.om.IPortletWindowId in project uPortal by Jasig.

the class PortletExecutionManager method getRenderedPortletHeaderWorker.

protected IPortletRenderExecutionWorker getRenderedPortletHeaderWorker(IPortletWindowId portletWindowId, HttpServletRequest request, HttpServletResponse response) {
    final Map<IPortletWindowId, IPortletRenderExecutionWorker> portletHeaderRenderingMap = this.getPortletHeaderRenderingMap(request);
    IPortletRenderExecutionWorker portletHeaderRenderWorker = portletHeaderRenderingMap.get(portletWindowId);
    if (portletHeaderRenderWorker == null) {
        portletHeaderRenderWorker = this.startPortletHeaderRenderInternal(portletWindowId, request, response);
    }
    return portletHeaderRenderWorker;
}
Also used : IPortletRenderExecutionWorker(org.apereo.portal.portlet.rendering.worker.IPortletRenderExecutionWorker) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 20 with IPortletWindowId

use of org.apereo.portal.portlet.om.IPortletWindowId in project uPortal by Jasig.

the class PortletRendererImpl method publishResourceEvent.

/**
 * Publish the portlet resource event
 */
protected void publishResourceEvent(IPortletWindow portletWindow, HttpServletRequest httpServletRequest, long executionTime, boolean usedBrowserCache, boolean usedPortalCache) {
    final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
    this.portalEventFactory.publishPortletResourceExecutionEvent(httpServletRequest, this, portletWindowId, executionTime, usedBrowserCache, usedPortalCache);
}
Also used : IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Aggregations

IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)85 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)31 Test (org.junit.Test)19 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)19 MockPortletWindowId (org.apereo.portal.mock.portlet.om.MockPortletWindowId)15 WindowState (javax.portlet.WindowState)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)9 PortletMode (javax.portlet.PortletMode)8 IPortalRequestInfo (org.apereo.portal.url.IPortalRequestInfo)8 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)7 IPortletRenderExecutionWorker (org.apereo.portal.portlet.rendering.worker.IPortletRenderExecutionWorker)7 IPortletUrlBuilder (org.apereo.portal.url.IPortletUrlBuilder)7 LinkedHashMap (java.util.LinkedHashMap)6 IPerson (org.apereo.portal.security.IPerson)6 IPortalUrlBuilder (org.apereo.portal.url.IPortalUrlBuilder)6 IOException (java.io.IOException)5 List (java.util.List)5 IUserInstance (org.apereo.portal.user.IUserInstance)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5