Search in sources :

Example 1 with DelegationResponse

use of org.apereo.portal.api.portlet.DelegationResponse in project uPortal by Jasig.

the class PortletDelegationDispatcherImpl method doRender.

@Override
public DelegationResponse doRender(RenderRequest renderRequest, RenderResponse renderResponse, DelegationRequest delegationRequest, PortletOutputHandler portletOutputHandler) throws IOException {
    final HttpServletRequest request = this.portalRequestUtils.getPortletHttpRequest(renderRequest);
    final HttpServletResponse response = this.portalRequestUtils.getOriginalPortalResponse(renderRequest);
    //Sanity check that the dispatch is being called by the same user it was created for
    final IPerson person = this.personManager.getPerson(request);
    if (this.userId != person.getID()) {
        throw new IllegalStateException("This dispatcher was created for userId " + this.userId + " but is being executed for userId " + person.getID());
    }
    this.setupDelegateRequestInfo(request, delegationRequest);
    try {
        //TODO canRender permission checks!
        this.portletRenderer.doRenderMarkup(this.portletWindow.getPortletWindowId(), request, response, portletOutputHandler);
    } catch (RuntimeException e) {
        this.logger.error("Failed to render delegate", e);
        throw e;
    } finally {
        portletOutputHandler.flushBuffer();
    }
    return new DelegationResponse(this.getDelegateState());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) DelegationResponse(org.apereo.portal.api.portlet.DelegationResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 2 with DelegationResponse

use of org.apereo.portal.api.portlet.DelegationResponse in project uPortal by Jasig.

the class PortletDelegationView method render.

/* (non-Javadoc)
     * @see org.springframework.web.servlet.View#render(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    final IPortletWindowId portletWindowId = (IPortletWindowId) model.get(DELEGATE_PORTLET_WINDOW_ID);
    final DelegationRequest delegationRequest = (DelegationRequest) model.get(DELEGATE_REQUEST);
    final PortletRequest portletRequest = (PortletRequest) request.getAttribute(Constants.PORTLET_REQUEST);
    final PortletResponse portletResponse = (PortletResponse) request.getAttribute(Constants.PORTLET_RESPONSE);
    final PortletDelegationDispatcher requestDispatcher = portletDelegationLocator.getRequestDispatcher(portletRequest, portletWindowId);
    if (requestDispatcher == null) {
        throw new IllegalArgumentException("No PortletDelegationDispatcher exists for portlet window id: " + portletWindowId);
    }
    this.logger.debug("Found delegation dispatcher for portlet window id {} - {}", portletWindowId, requestDispatcher);
    final DelegationResponse delegationResponse;
    final String phase = (String) request.getAttribute(PortletRequest.LIFECYCLE_PHASE);
    if (PortletRequest.RENDER_PHASE.equals(phase)) {
        final PortletOutputHandler portletOutputHandler = (PortletOutputHandler) model.get(DELEGATE_RENDER_OUTPUT_HANDLER);
        if (portletOutputHandler != null) {
            this.logger.debug("Delegating RenderRequest with custom Writer and {}", delegationRequest);
            delegationResponse = requestDispatcher.doRender((RenderRequest) portletRequest, (RenderResponse) portletResponse, delegationRequest, portletOutputHandler);
        } else {
            this.logger.debug("Delegating RenderRequest with default Writer and {}", delegationRequest);
            delegationResponse = requestDispatcher.doRender((RenderRequest) portletRequest, (RenderResponse) portletResponse, delegationRequest);
        }
    } else if (PortletRequest.RESOURCE_PHASE.equals(phase)) {
        this.logger.debug("Delegating ResourceRequest and {}", delegationRequest);
        delegationResponse = requestDispatcher.doServeResource((ResourceRequest) portletRequest, (ResourceResponse) portletResponse, delegationRequest);
    } else {
        throw new UnsupportedOperationException("Portlet lifecycle phase " + phase + " is not supported by the delegation view");
    }
    this.logger.debug("{}", delegationResponse);
}
Also used : PortletRequest(javax.portlet.PortletRequest) PortletResponse(javax.portlet.PortletResponse) DelegationResponse(org.apereo.portal.api.portlet.DelegationResponse) RenderRequest(javax.portlet.RenderRequest) PortletDelegationDispatcher(org.apereo.portal.api.portlet.PortletDelegationDispatcher) RenderResponse(javax.portlet.RenderResponse) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) DelegationRequest(org.apereo.portal.api.portlet.DelegationRequest) PortletOutputHandler(org.apereo.portal.portlet.rendering.PortletOutputHandler)

Example 3 with DelegationResponse

use of org.apereo.portal.api.portlet.DelegationResponse in project uPortal by Jasig.

the class PortletDelegationDispatcherImpl method doServeResource.

@Override
public DelegationResponse doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse, DelegationRequest delegationRequest, PortletResourceOutputHandler portletOutputHandler) throws IOException {
    final HttpServletRequest request = this.portalRequestUtils.getPortletHttpRequest(resourceRequest);
    final HttpServletResponse response = this.portalRequestUtils.getOriginalPortalResponse(resourceRequest);
    //Sanity check that the dispatch is being called by the same user it was created for
    final IPerson person = this.personManager.getPerson(request);
    if (this.userId != person.getID()) {
        throw new IllegalStateException("This dispatcher was created for userId " + this.userId + " but is being executed for userId " + person.getID());
    }
    this.setupDelegateRequestInfo(request, delegationRequest);
    try {
        //TODO canRender permission checks!
        this.portletRenderer.doServeResource(this.portletWindow.getPortletWindowId(), request, response, portletOutputHandler);
    } catch (RuntimeException e) {
        this.logger.error("Failed to render delegate", e);
        throw e;
    }
    return new DelegationResponse(this.getDelegateState());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) DelegationResponse(org.apereo.portal.api.portlet.DelegationResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Aggregations

DelegationResponse (org.apereo.portal.api.portlet.DelegationResponse)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 IPerson (org.apereo.portal.security.IPerson)2 PortletRequest (javax.portlet.PortletRequest)1 PortletResponse (javax.portlet.PortletResponse)1 RenderRequest (javax.portlet.RenderRequest)1 RenderResponse (javax.portlet.RenderResponse)1 DelegationRequest (org.apereo.portal.api.portlet.DelegationRequest)1 PortletDelegationDispatcher (org.apereo.portal.api.portlet.PortletDelegationDispatcher)1 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)1 PortletOutputHandler (org.apereo.portal.portlet.rendering.PortletOutputHandler)1