Search in sources :

Example 1 with PortletDelegationDispatcher

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

the class PortletAdministrationHelper method configModeAction.

public boolean configModeAction(ExternalContext externalContext, String fname) throws IOException {
    final ActionRequest actionRequest = (ActionRequest) externalContext.getNativeRequest();
    final ActionResponse actionResponse = (ActionResponse) externalContext.getNativeResponse();
    final IPortletWindowId portletWindowId = this.getDelegateWindowId(externalContext, fname);
    if (portletWindowId == null) {
        throw new IllegalStateException("Cannot execute configModeAciton without a delegate window ID in the session for key: " + RenderPortletTag.DEFAULT_SESSION_KEY_PREFIX + fname);
    }
    final PortletDelegationDispatcher requestDispatcher = this.portletDelegationLocator.getRequestDispatcher(actionRequest, portletWindowId);
    final DelegationActionResponse delegationResponse = requestDispatcher.doAction(actionRequest, actionResponse);
    final String redirectLocation = delegationResponse.getRedirectLocation();
    final DelegateState delegateState = delegationResponse.getDelegateState();
    if (redirectLocation != null || (delegationResponse.getPortletMode() != null && !IPortletRenderer.CONFIG.equals(delegationResponse.getPortletMode())) || !IPortletRenderer.CONFIG.equals(delegateState.getPortletMode())) {
        //The portlet sent a redirect OR changed it's mode away from CONFIG, assume it is done
        return true;
    }
    return false;
}
Also used : ActionRequest(javax.portlet.ActionRequest) PortletDelegationDispatcher(org.apereo.portal.api.portlet.PortletDelegationDispatcher) DelegateState(org.apereo.portal.api.portlet.DelegateState) ActionResponse(javax.portlet.ActionResponse) DelegationActionResponse(org.apereo.portal.api.portlet.DelegationActionResponse) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) DelegationActionResponse(org.apereo.portal.api.portlet.DelegationActionResponse)

Example 2 with PortletDelegationDispatcher

use of org.apereo.portal.api.portlet.PortletDelegationDispatcher 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 PortletDelegationDispatcher

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

the class RenderPortletTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    //From portlet:defineObjects
    final RenderRequest renderRequest = (RenderRequest) this.pageContext.getAttribute("renderRequest");
    final RenderResponse renderResponse = (RenderResponse) this.pageContext.getAttribute("renderResponse");
    final PortletDelegationLocator portletDelegationLocator = (PortletDelegationLocator) renderRequest.getAttribute(PortletDelegationLocator.PORTLET_DELECATION_LOCATOR_ATTR);
    final String sessionKey = this.sessionKeyPrefix + this.fname;
    final PortletSession portletSession = renderRequest.getPortletSession();
    IPortletWindowId portletWindowId = (IPortletWindowId) portletSession.getAttribute(sessionKey);
    final PortletDelegationDispatcher portletDelegationDispatcher;
    final DelegateState delegateState;
    //No id in session, create a new dispatcher
    if (portletWindowId == null) {
        portletDelegationDispatcher = portletDelegationLocator.createRequestDispatcher(renderRequest, this.fname);
        portletWindowId = portletDelegationDispatcher.getPortletWindowId();
        portletSession.setAttribute(sessionKey, portletWindowId);
        final PortletMode portletMode = PortletUtils.getPortletMode(this.portletMode);
        final WindowState windowState = PortletUtils.getWindowState(this.windowState);
        delegateState = new DelegateState(portletMode, windowState);
    } else //id in session, get the old dispatcher
    {
        portletDelegationDispatcher = portletDelegationLocator.getRequestDispatcher(renderRequest, portletWindowId);
        delegateState = null;
    }
    final DelegationRequest delegationRequest = new DelegationRequest();
    delegationRequest.setDelegateState(delegateState);
    //Setup base for portlet URLs
    delegationRequest.setParentPortletMode(this.parentUrlMode);
    delegationRequest.setParentWindowState(this.parentUrlState);
    delegationRequest.setParentParameters(this.parentUrlParameters);
    final JspWriter out = this.pageContext.getOut();
    try {
        portletDelegationDispatcher.doRender(renderRequest, renderResponse, delegationRequest, new JspWriterPortletOutputHandler(out, renderResponse));
    } catch (IOException e) {
        throw new JspException("Failed to execute delegate render on portlet '" + this.fname + "'", e);
    }
    return Tag.EVAL_PAGE;
}
Also used : WindowState(javax.portlet.WindowState) RenderRequest(javax.portlet.RenderRequest) DelegateState(org.apereo.portal.api.portlet.DelegateState) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) PortletMode(javax.portlet.PortletMode) JspException(javax.servlet.jsp.JspException) PortletSession(javax.portlet.PortletSession) PortletDelegationDispatcher(org.apereo.portal.api.portlet.PortletDelegationDispatcher) RenderResponse(javax.portlet.RenderResponse) PortletDelegationLocator(org.apereo.portal.api.portlet.PortletDelegationLocator) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) DelegationRequest(org.apereo.portal.api.portlet.DelegationRequest)

Aggregations

PortletDelegationDispatcher (org.apereo.portal.api.portlet.PortletDelegationDispatcher)3 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)3 RenderRequest (javax.portlet.RenderRequest)2 RenderResponse (javax.portlet.RenderResponse)2 DelegateState (org.apereo.portal.api.portlet.DelegateState)2 DelegationRequest (org.apereo.portal.api.portlet.DelegationRequest)2 IOException (java.io.IOException)1 ActionRequest (javax.portlet.ActionRequest)1 ActionResponse (javax.portlet.ActionResponse)1 PortletMode (javax.portlet.PortletMode)1 PortletRequest (javax.portlet.PortletRequest)1 PortletResponse (javax.portlet.PortletResponse)1 PortletSession (javax.portlet.PortletSession)1 WindowState (javax.portlet.WindowState)1 JspException (javax.servlet.jsp.JspException)1 JspWriter (javax.servlet.jsp.JspWriter)1 DelegationActionResponse (org.apereo.portal.api.portlet.DelegationActionResponse)1 DelegationResponse (org.apereo.portal.api.portlet.DelegationResponse)1 PortletDelegationLocator (org.apereo.portal.api.portlet.PortletDelegationLocator)1 PortletOutputHandler (org.apereo.portal.portlet.rendering.PortletOutputHandler)1