Search in sources :

Example 1 with PortletException

use of javax.portlet.PortletException in project uPortal by Jasig.

the class PortletRendererImpl method doAction.

/*
     * PLT 22.1 If the content of a portlet is cached and the portlet is target of request
     * with an action-type semantic (e.g. an action or event call), the portlet container should discard the cache and
     * invoke the corresponding request handling methods of the portlet like processAction,or processEvent.
     */
@Override
public long doAction(IPortletWindowId portletWindowId, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
    this.portletCacheControlService.purgeCachedPortletData(portletWindowId, httpServletRequest);
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpServletRequest, portletWindowId);
    enforceConfigPermission(httpServletRequest, portletWindow);
    httpServletRequest = this.setupPortletRequest(httpServletRequest);
    httpServletResponse = new PortletHttpServletResponseWrapper(httpServletResponse, portletWindow);
    // Execute the action,
    this.logger.debug("Executing portlet action for window '{}'", portletWindow);
    final long start = System.nanoTime();
    try {
        this.portletContainer.doAction(portletWindow.getPlutoPortletWindow(), httpServletRequest, httpServletResponse);
    } catch (PortletException pe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing action.", portletWindow, pe);
    } catch (PortletContainerException pce) {
        throw new PortletDispatchException("The portlet container threw an exception while executing action on portlet window '" + portletWindow + "'.", portletWindow, pce);
    } catch (IOException ioe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing action.", portletWindow, ioe);
    }
    final long executionTime = System.nanoTime() - start;
    this.portalEventFactory.publishPortletActionExecutionEvent(httpServletRequest, this, portletWindowId, executionTime);
    return executionTime;
}
Also used : PortletException(javax.portlet.PortletException) PortletDispatchException(org.apereo.portal.portlet.PortletDispatchException) IOException(java.io.IOException) PortletHttpServletResponseWrapper(org.apereo.portal.utils.web.PortletHttpServletResponseWrapper) PortletContainerException(org.apache.pluto.container.PortletContainerException) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow)

Example 2 with PortletException

use of javax.portlet.PortletException in project uPortal by Jasig.

the class PortletRendererImpl method doEvent.

/*
     * PLT 22.1 If the content of a portlet is cached and the portlet is target of request
     * with an action-type semantic (e.g. an action or event call), the portlet container should discard the cache and
     * invoke the corresponding request handling methods of the portlet like processAction,or processEvent.
     *
     * (non-Javadoc)
     * @see org.apereo.portal.portlet.rendering.IPortletRenderer#doEvent(org.apereo.portal.portlet.om.IPortletWindowId, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.portlet.Event)
     */
@Override
public long doEvent(IPortletWindowId portletWindowId, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Event event) {
    this.portletCacheControlService.purgeCachedPortletData(portletWindowId, httpServletRequest);
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpServletRequest, portletWindowId);
    enforceConfigPermission(httpServletRequest, portletWindow);
    httpServletRequest = this.setupPortletRequest(httpServletRequest);
    httpServletResponse = new PortletHttpServletResponseWrapper(httpServletResponse, portletWindow);
    // Execute the action,
    this.logger.debug("Executing portlet event for window '{}'", portletWindow);
    final long start = System.nanoTime();
    try {
        this.portletContainer.doEvent(portletWindow.getPlutoPortletWindow(), httpServletRequest, httpServletResponse, event);
    } catch (PortletException pe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing event.", portletWindow, pe);
    } catch (PortletContainerException pce) {
        throw new PortletDispatchException("The portlet container threw an exception while executing event on portlet window '" + portletWindow + "'.", portletWindow, pce);
    } catch (IOException ioe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing event.", portletWindow, ioe);
    }
    final long executionTime = System.nanoTime() - start;
    this.portalEventFactory.publishPortletEventExecutionEvent(httpServletRequest, this, portletWindowId, executionTime, event.getQName());
    return executionTime;
}
Also used : PortletException(javax.portlet.PortletException) PortletDispatchException(org.apereo.portal.portlet.PortletDispatchException) IOException(java.io.IOException) PortletHttpServletResponseWrapper(org.apereo.portal.utils.web.PortletHttpServletResponseWrapper) PortletContainerException(org.apache.pluto.container.PortletContainerException) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow)

Example 3 with PortletException

use of javax.portlet.PortletException in project uPortal by Jasig.

the class PortletRendererImpl method doServeResource.

@Override
public long doServeResource(IPortletWindowId portletWindowId, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, PortletResourceOutputHandler portletOutputHandler) throws IOException {
    final CacheState<CachedPortletResourceData<Long>, Long> cacheState = this.portletCacheControlService.getPortletResourceState(httpServletRequest, portletWindowId);
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpServletRequest, portletWindowId);
    enforceConfigPermission(httpServletRequest, portletWindow);
    if (cacheState.isUseBrowserData()) {
        logger.trace("doServeResource-Reusing browser data");
        return doResourceReplayBrowserContent(portletWindow, httpServletRequest, cacheState, portletOutputHandler);
    }
    if (cacheState.isUseCachedData()) {
        logger.trace("doServeResource-Reusing cached data");
        return doResourceReplayCachedContent(portletWindow, httpServletRequest, cacheState, portletOutputHandler, 0);
    }
    final int cacheSizeThreshold = this.portletCacheControlService.getCacheSizeThreshold();
    final CachingPortletResourceOutputHandler cachingPortletOutputHandler = new CachingPortletResourceOutputHandler(portletOutputHandler, cacheSizeThreshold);
    CacheControl cacheControl = cacheState.getCacheControl();
    // Wrap the cache control so it immediately sets the caching related response headers
    cacheControl = new HeaderSettingCacheControl(cacheControl, cachingPortletOutputHandler);
    // Setup the request and response
    httpServletRequest = this.setupPortletRequest(httpServletRequest);
    httpServletResponse = new PortletResourceHttpServletResponseWrapper(httpServletResponse, portletWindow, portletOutputHandler, cacheControl);
    httpServletRequest.setAttribute(IPortletRenderer.ATTRIBUTE__PORTLET_CACHE_CONTROL, cacheControl);
    httpServletRequest.setAttribute(IPortletRenderer.ATTRIBUTE__PORTLET_OUTPUT_HANDLER, cachingPortletOutputHandler);
    this.logger.debug("Executing resource request for window {}", portletWindow);
    final long start = System.nanoTime();
    try {
        this.portletContainer.doServeResource(portletWindow.getPlutoPortletWindow(), httpServletRequest, httpServletResponse);
    } catch (PortletException pe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing serveResource.", portletWindow, pe);
    } catch (PortletContainerException pce) {
        throw new PortletDispatchException("The portlet container threw an exception while executing serveResource on portlet window '" + portletWindow + "'.", portletWindow, pce);
    } catch (IOException ioe) {
        throw new PortletDispatchException("The portlet window '" + portletWindow + "' threw an exception while executing serveResource.", portletWindow, ioe);
    }
    final long executionTime = System.nanoTime() - start;
    // See if the portlet signaled to use the cached content
    final boolean useCachedContent = cacheControl.useCachedContent();
    if (useCachedContent) {
        final CachedPortletResourceData<Long> cachedPortletResourceData = cacheState.getCachedPortletData();
        if (cachedPortletResourceData != null) {
            // Update the expiration time and re-store in the cache
            final CachedPortletData<Long> cachedPortletData = cachedPortletResourceData.getCachedPortletData();
            cachedPortletData.updateExpirationTime(cacheControl.getExpirationTime());
            this.portletCacheControlService.cachePortletResourceOutput(portletWindowId, httpServletRequest, cacheState, cachedPortletResourceData);
        }
        if (cacheState.isBrowserSetEtag()) {
            logger.trace("doServeResource-useCachedContent, Reusing browser data");
            // Browser-side content matches, send a 304
            return doResourceReplayBrowserContent(portletWindow, httpServletRequest, cacheState, portletOutputHandler);
        }
        logger.trace("doServeResource-useCachedContent, Reusing cached data");
        return doResourceReplayCachedContent(portletWindow, httpServletRequest, cacheState, cachingPortletOutputHandler, executionTime);
    }
    publishResourceEvent(portletWindow, httpServletRequest, executionTime, false, false);
    if (cacheState != null) {
        boolean shouldCache = this.portletCacheControlService.shouldOutputBeCached(cacheControl);
        if (shouldCache) {
            final CachedPortletResourceData<Long> cachedPortletResourceData = cachingPortletOutputHandler.getCachedPortletResourceData(executionTime, cacheControl);
            if (cachedPortletResourceData != null) {
                this.portletCacheControlService.cachePortletResourceOutput(portletWindowId, httpServletRequest, cacheState, cachedPortletResourceData);
            }
        }
    }
    return executionTime;
}
Also used : PortletException(javax.portlet.PortletException) CachedPortletResourceData(org.apereo.portal.portlet.container.cache.CachedPortletResourceData) IOException(java.io.IOException) PortletContainerException(org.apache.pluto.container.PortletContainerException) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) PortletDispatchException(org.apereo.portal.portlet.PortletDispatchException) CachingPortletResourceOutputHandler(org.apereo.portal.portlet.container.cache.CachingPortletResourceOutputHandler) HeaderSettingCacheControl(org.apereo.portal.portlet.container.cache.HeaderSettingCacheControl) CacheControl(javax.portlet.CacheControl) HeaderSettingCacheControl(org.apereo.portal.portlet.container.cache.HeaderSettingCacheControl)

Example 4 with PortletException

use of javax.portlet.PortletException in project acs-community-packaging by Alfresco.

the class AlfrescoFacesPortlet method facesRender.

/**
 * @see org.apache.myfaces.portlet.MyFacesGenericPortlet#facesRender(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
 */
protected void facesRender(RenderRequest request, RenderResponse response) throws PortletException, IOException {
    Application.setInPortalServer(true);
    try {
        // Set the current locale
        I18NUtil.setLocale(getLanguage(request.getPortletSession()));
        if (request.getParameter(ERROR_OCCURRED) != null) {
            String errorPage = getErrorPage();
            if (logger.isDebugEnabled())
                logger.debug("An error has occurred, redirecting to error page: " + errorPage);
            response.setContentType("text/html");
            PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher(errorPage);
            dispatcher.include(request, response);
        } else {
            WebApplicationContext ctx = (WebApplicationContext) getPortletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
            AuthenticationService auth = (AuthenticationService) ctx.getBean("AuthenticationService");
            // if we have no User object in the session then an HTTP Session timeout must have occured
            // use the viewId to check that we are not already on the login page
            PortletSession session = request.getPortletSession();
            String viewId = request.getParameter(VIEW_ID);
            // keep track of last view id so we can use it as return page from multi-part requests
            request.getPortletSession().setAttribute(SESSION_LAST_VIEW_ID, viewId);
            SessionUser sessionUser = (SessionUser) request.getPortletSession().getAttribute(AuthenticationHelper.AUTHENTICATION_USER, PortletSession.APPLICATION_SCOPE);
            User user = sessionUser instanceof User ? (User) sessionUser : null;
            if (user == null && (viewId == null || viewId.equals(getLoginPage()) == false)) {
                if (portalGuestAuthenticate(ctx, session, auth) != null) {
                    if (logger.isDebugEnabled())
                        logger.debug("Guest access successful.");
                    // perform the forward to the page processed by the Faces servlet
                    response.setContentType("text/html");
                    request.getPortletSession().setAttribute(PortletUtil.PORTLET_REQUEST_FLAG, "true");
                    // get the start location as configured by the web-client config
                    ConfigService configService = (ConfigService) ctx.getBean("webClientConfigService");
                    ClientConfigElement configElement = (ClientConfigElement) configService.getGlobalConfig().getConfigElement("client");
                    if (NavigationBean.LOCATION_MYALFRESCO.equals(configElement.getInitialLocation())) {
                        nonFacesRequest(request, response, "/jsp/dashboards/container.jsp");
                    } else {
                        nonFacesRequest(request, response, FacesHelper.BROWSE_VIEW_ID);
                    }
                } else {
                    if (logger.isDebugEnabled())
                        logger.debug("No valid User login, requesting login page. ViewId: " + viewId);
                    // set last used username as special session value used by the LoginBean
                    session.setAttribute(AuthenticationHelper.SESSION_USERNAME, request.getPreferences().getValue(PREF_ALF_USERNAME, null));
                    // login page is the default portal page
                    response.setContentType("text/html");
                    request.getPortletSession().setAttribute(PortletUtil.PORTLET_REQUEST_FLAG, "true");
                    nonFacesRequest(request, response);
                }
            } else {
                if (session.getAttribute(AuthenticationHelper.SESSION_INVALIDATED) != null) {
                    // remove the username preference value as explicit logout was requested by the user
                    if (request.getPreferences().isReadOnly(PREF_ALF_USERNAME) == false) {
                        request.getPreferences().reset(PREF_ALF_USERNAME);
                    }
                    session.removeAttribute(AuthenticationHelper.SESSION_INVALIDATED);
                }
                try {
                    if (user != null) {
                        if (logger.isDebugEnabled())
                            logger.debug("Validating ticket: " + user.getTicket());
                        // setup the authentication context
                        auth.validate(user.getTicket());
                    }
                    // do the normal JSF processing
                    super.facesRender(request, response);
                } catch (AuthenticationException authErr) {
                    // ticket is no longer valid!
                    if (logger.isDebugEnabled())
                        logger.debug("Invalid ticket, requesting login page.");
                    // remove User object as it's now useless
                    session.removeAttribute(AuthenticationHelper.AUTHENTICATION_USER, PortletSession.APPLICATION_SCOPE);
                    // login page is the default portal page
                    response.setContentType("text/html");
                    request.getPortletSession().setAttribute(PortletUtil.PORTLET_REQUEST_FLAG, "true");
                    nonFacesRequest(request, response);
                } catch (Throwable e) {
                    if (getErrorPage() != null) {
                        handleError(request, response, e);
                    } else {
                        logger.warn("No error page configured, re-throwing exception");
                        if (e instanceof PortletException) {
                            throw (PortletException) e;
                        } else if (e instanceof IOException) {
                            throw (IOException) e;
                        } else {
                            throw new PortletException(e);
                        }
                    }
                }
            }
        }
    } finally {
        Application.setInPortalServer(false);
    }
}
Also used : User(org.alfresco.web.bean.repository.User) SessionUser(org.alfresco.repo.SessionUser) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) PortletException(javax.portlet.PortletException) IOException(java.io.IOException) ClientConfigElement(org.alfresco.web.config.ClientConfigElement) WebApplicationContext(org.springframework.web.context.WebApplicationContext) PortletRequestDispatcher(javax.portlet.PortletRequestDispatcher) SessionUser(org.alfresco.repo.SessionUser) ConfigService(org.springframework.extensions.config.ConfigService) PortletSession(javax.portlet.PortletSession) AuthenticationService(org.alfresco.service.cmr.security.AuthenticationService)

Example 5 with PortletException

use of javax.portlet.PortletException in project liferay-ide by liferay.

the class RosterPortlet method processAction.

@Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException {
    try {
        String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            updateRoster(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteRoster(actionRequest);
        }
        if (Validator.isNotNull(cmd)) {
            if (SessionErrors.isEmpty(actionRequest)) {
                SessionMessages.add(actionRequest, "requestProcessed");
            }
            String redirect = ParamUtil.getString(actionRequest, "redirect");
            actionResponse.sendRedirect(redirect);
        }
    } catch (Exception e) {
        throw new PortletException(e);
    }
}
Also used : PortletException(javax.portlet.PortletException) IOException(java.io.IOException) PortletException(javax.portlet.PortletException)

Aggregations

PortletException (javax.portlet.PortletException)21 IOException (java.io.IOException)17 NoSuchArticleException (com.liferay.knowledgebase.NoSuchArticleException)5 NoSuchCommentException (com.liferay.knowledgebase.NoSuchCommentException)5 KBArticle (com.liferay.knowledgebase.model.KBArticle)5 NoSuchSubscriptionException (com.liferay.portal.NoSuchSubscriptionException)5 PortalException (com.liferay.portal.kernel.exception.PortalException)5 PrincipalException (com.liferay.portal.security.auth.PrincipalException)5 PortletContainerException (org.apache.pluto.container.PortletContainerException)5 PortletDispatchException (org.apereo.portal.portlet.PortletDispatchException)5 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)5 SystemException (com.liferay.portal.kernel.exception.SystemException)3 TException (org.apache.thrift.TException)3 PortletHttpServletResponseWrapper (org.apereo.portal.utils.web.PortletHttpServletResponseWrapper)3 User (org.eclipse.sw360.datahandler.thrift.users.User)3 CacheControl (javax.portlet.CacheControl)2 PortletSession (javax.portlet.PortletSession)2 SessionUser (org.alfresco.repo.SessionUser)2 AuthenticationException (org.alfresco.repo.security.authentication.AuthenticationException)2 AuthenticationService (org.alfresco.service.cmr.security.AuthenticationService)2