Package org.springframework.web.portlet.context

Examples of org.springframework.web.portlet.context.PortletRequestAttributes


    LocaleContext previousLocaleContext = LocaleContextHolder.getLocaleContext();
    LocaleContextHolder.setLocaleContext(buildLocaleContext(request), this.threadContextInheritable);

    // Expose current RequestAttributes to current thread.
    RequestAttributes previousRequestAttributes = RequestContextHolder.getRequestAttributes();
    PortletRequestAttributes requestAttributes = null;
    if (previousRequestAttributes == null || previousRequestAttributes.getClass().equals(PortletRequestAttributes.class)) {
      requestAttributes = new PortletRequestAttributes(request);
      RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);
    }

    if (logger.isTraceEnabled()) {
      logger.trace("Bound request context to thread: " + request);
    }

    try {
      String phase = (String) request.getAttribute(PortletRequest.LIFECYCLE_PHASE);
      if (PortletRequest.ACTION_PHASE.equals(phase)) {
        doActionService((ActionRequest) request, (ActionResponse) response);
      }
      else if (PortletRequest.RENDER_PHASE.equals(phase)) {
        doRenderService((RenderRequest) request, (RenderResponse) response);
      }
      else if (PortletRequest.RESOURCE_PHASE.equals(phase)) {
        doResourceService((ResourceRequest) request, (ResourceResponse) response);
      }
      else if (PortletRequest.EVENT_PHASE.equals(phase)) {
        doEventService((EventRequest) request, (EventResponse) response);
      }
      else {
        throw new IllegalStateException("Invalid portlet request phase: " + phase);
      }
    }
    catch (PortletException ex) {
      failureCause = ex;
      throw ex;
    }
    catch (IOException ex) {
      failureCause = ex;
      throw ex;
    }
    catch (Throwable ex) {
      failureCause = ex;
      throw new PortletException("Request processing failed", ex);
    }

    finally {
      // Clear request attributes and reset thread-bound context.
      LocaleContextHolder.setLocaleContext(previousLocaleContext, this.threadContextInheritable);
      if (requestAttributes != null) {
        RequestContextHolder.setRequestAttributes(previousRequestAttributes, this.threadContextInheritable);
        requestAttributes.requestCompleted();
      }
      if (logger.isTraceEnabled()) {
        logger.trace("Cleared thread-bound resource request context: " + request);
      }
View Full Code Here


    LocaleContext previousLocaleContext = LocaleContextHolder.getLocaleContext();
    LocaleContextHolder.setLocaleContext(buildLocaleContext(request), this.threadContextInheritable);

    // Expose current RequestAttributes to current thread.
    RequestAttributes previousRequestAttributes = RequestContextHolder.getRequestAttributes();
    PortletRequestAttributes requestAttributes = new PortletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);

    if (logger.isDebugEnabled()) {
      logger.debug("Bound action request context to thread: " + request);
    }

    ActionRequest processedRequest = request;
    HandlerExecutionChain mappedHandler = null;
    int interceptorIndex = -1;

    try {
      processedRequest = checkMultipart(request);

      // Determine handler for the current request.
      mappedHandler = getHandler(processedRequest, false);
      if (mappedHandler == null || mappedHandler.getHandler() == null) {
        noHandlerFound(processedRequest, response);
        return;
      }

      // Apply preHandle methods of registered interceptors.
      HandlerInterceptor[] interceptors = mappedHandler.getInterceptors();
      if (interceptors != null) {
        for (int i = 0; i < interceptors.length; i++) {
          HandlerInterceptor interceptor = interceptors[i];
          if (!interceptor.preHandleAction(processedRequest, response, mappedHandler.getHandler())) {
            triggerAfterActionCompletion(mappedHandler, interceptorIndex, processedRequest, response, null);
            return;
          }
          interceptorIndex = i;
        }
      }

      // Actually invoke the handler.
      HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());
      ha.handleAction(processedRequest, response, mappedHandler.getHandler());

      // Trigger after-completion for successful outcome.
      triggerAfterActionCompletion(mappedHandler, interceptorIndex, processedRequest, response, null);
    }

    catch (Exception ex) {
      // Trigger after-completion for thrown exception.
      triggerAfterActionCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex);
      // Forward the exception to the render phase to be displayed.
      try {
        response.setRenderParameter(ACTION_EXCEPTION_RENDER_PARAMETER, ex.toString());
        request.getPortletSession().setAttribute(ACTION_EXCEPTION_SESSION_ATTRIBUTE, ex);
        logger.debug("Caught exception during action phase - forwarding to render phase", ex);
      }
      catch (IllegalStateException ex2) {
        // Probably sendRedirect called... need to rethrow exception immediately.
        throw ex;
      }
    }
    catch (Error err) {
      PortletException ex =
          new PortletException("Error occured during request processing: " + err.getMessage(), err);
      // Trigger after-completion for thrown exception.
      triggerAfterActionCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex);
      throw ex;
    }

    finally {
      // Clean up any resources used by a multipart request.
      if (processedRequest instanceof MultipartActionRequest && processedRequest != request) {
        this.multipartResolver.cleanupMultipart((MultipartActionRequest) processedRequest);
      }

      // Reset thread-bound context.
      RequestContextHolder.setRequestAttributes(previousRequestAttributes, this.threadContextInheritable);
      LocaleContextHolder.setLocaleContext(previousLocaleContext, this.threadContextInheritable);

      // Clear request attributes.
      requestAttributes.requestCompleted();
      if (logger.isDebugEnabled()) {
        logger.debug("Cleared thread-bound action request context: " + request);
      }
    }
  }
View Full Code Here

    LocaleContext previousLocaleContext = LocaleContextHolder.getLocaleContext();
    LocaleContextHolder.setLocaleContext(buildLocaleContext(request), this.threadContextInheritable);

    // Expose current RequestAttributes to current thread.
    RequestAttributes previousRequestAttributes = RequestContextHolder.getRequestAttributes();
    PortletRequestAttributes requestAttributes = new PortletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);

    if (logger.isDebugEnabled()) {
      logger.debug("Bound render request context to thread: " + request);
    }

    RenderRequest processedRequest = request;
    HandlerExecutionChain mappedHandler = null;
    int interceptorIndex = -1;

    try {
      ModelAndView mv = null;
      try {
        // Check for forwarded exception from the action phase
        PortletSession session = request.getPortletSession(false);
        if (session != null) {
          if (request.getParameter(ACTION_EXCEPTION_RENDER_PARAMETER) != null) {
            Exception ex = (Exception) session.getAttribute(ACTION_EXCEPTION_SESSION_ATTRIBUTE);
            if (ex != null) {
              logger.debug("Render phase found exception caught during action phase - rethrowing it");
              throw ex;
            }
          }
          else {
            session.removeAttribute(ACTION_EXCEPTION_SESSION_ATTRIBUTE);
          }
        }
       
        // Determine handler for the current request.
        mappedHandler = getHandler(processedRequest, false);
        if (mappedHandler == null || mappedHandler.getHandler() == null) {
          noHandlerFound(processedRequest, response);
          return;
        }

        // Apply preHandle methods of registered interceptors.
        HandlerInterceptor[] interceptors = mappedHandler.getInterceptors();
        if (interceptors != null) {
          for (int i = 0; i < interceptors.length; i++) {
            HandlerInterceptor interceptor = interceptors[i];
            if (!interceptor.preHandleRender(processedRequest, response, mappedHandler.getHandler())) {
              triggerAfterRenderCompletion(mappedHandler, interceptorIndex, processedRequest, response, null);
              return;
            }
            interceptorIndex = i;
          }
        }

        // Actually invoke the handler.
        HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());
        mv = ha.handleRender(processedRequest, response, mappedHandler.getHandler());

        // Apply postHandle methods of registered interceptors.
        if (interceptors != null) {
          for (int i = interceptors.length - 1; i >= 0; i--) {
            HandlerInterceptor interceptor = interceptors[i];
            interceptor.postHandleRender(processedRequest, response, mappedHandler.getHandler(), mv);
          }
        }
      }
      catch (ModelAndViewDefiningException ex) {
        logger.debug("ModelAndViewDefiningException encountered", ex);
        mv = ex.getModelAndView();
      }
      catch (Exception ex) {
        Object handler = (mappedHandler != null ? mappedHandler.getHandler() : null);
        mv = processHandlerException(request, response, handler, ex);
      }

      // Did the handler return a view to render?
      if (mv != null && !mv.isEmpty()) {
        render(mv, processedRequest, response);
      }
      else {
        if (logger.isDebugEnabled()) {
          logger.debug("Null ModelAndView returned to DispatcherPortlet with name '" +
              getPortletName() + "': assuming HandlerAdapter completed request handling");
        }
      }

      // Trigger after-completion for successful outcome.
      triggerAfterRenderCompletion(mappedHandler, interceptorIndex, processedRequest, response, null);
    }

    catch (Exception ex) {
      // Trigger after-completion for thrown exception.
      triggerAfterRenderCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex);
      throw ex;
    }
    catch (Error err) {
      PortletException ex =
          new PortletException("Error occured during request processing: " + err.getMessage(), err);
      // Trigger after-completion for thrown exception.
      triggerAfterRenderCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex);
      throw ex;
    }

    finally {
      // Reset thread-bound context.
      RequestContextHolder.setRequestAttributes(previousRequestAttributes, this.threadContextInheritable);
      LocaleContextHolder.setLocaleContext(previousLocaleContext, this.threadContextInheritable);

      // Clear request attributes.
      requestAttributes.requestCompleted();
      if (logger.isDebugEnabled()) {
        logger.debug("Cleared thread-bound render request context: " + request);
      }
    }
  }
View Full Code Here

    LocaleContext previousLocaleContext = LocaleContextHolder.getLocaleContext();
    LocaleContextHolder.setLocaleContext(buildLocaleContext(request), this.threadContextInheritable);

    // Expose current RequestAttributes to current thread.
    RequestAttributes previousRequestAttributes = RequestContextHolder.getRequestAttributes();
    PortletRequestAttributes requestAttributes = new PortletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);

    if (logger.isDebugEnabled()) {
      logger.debug("Bound action request context to thread: " + request);
    }

    ActionRequest processedRequest = request;
    HandlerExecutionChain mappedHandler = null;
    int interceptorIndex = -1;

    try {
      processedRequest = checkMultipart(request);

      // Determine handler for the current request.
      mappedHandler = getHandler(processedRequest, false);
      if (mappedHandler == null || mappedHandler.getHandler() == null) {
        noHandlerFound(processedRequest, response);
        return;
      }

      // Apply preHandle methods of registered interceptors.
      HandlerInterceptor[] interceptors = mappedHandler.getInterceptors();
      if (interceptors != null) {
        for (int i = 0; i < interceptors.length; i++) {
          HandlerInterceptor interceptor = interceptors[i];
          if (!interceptor.preHandleAction(processedRequest, response, mappedHandler.getHandler())) {
            triggerAfterActionCompletion(mappedHandler, interceptorIndex, processedRequest, response, null);
            return;
          }
          interceptorIndex = i;
        }
      }

      // Actually invoke the handler.
      HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());
      ha.handleAction(processedRequest, response, mappedHandler.getHandler());

      // Trigger after-completion for successful outcome.
      triggerAfterActionCompletion(mappedHandler, interceptorIndex, processedRequest, response, null);
    }

    catch (Exception ex) {
      // Trigger after-completion for thrown exception.
      triggerAfterActionCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex);
      // Forward the exception to the render phase to be displayed.
      try {
        response.setRenderParameter(ACTION_EXCEPTION_RENDER_PARAMETER, ex.toString());
        request.getPortletSession().setAttribute(ACTION_EXCEPTION_SESSION_ATTRIBUTE, ex);
        logger.debug("Caught exception during action phase - forwarding to render phase", ex);
      }
      catch (IllegalStateException ex2) {
        // Probably sendRedirect called... need to rethrow exception immediately.
        throw ex;
      }
    }
    catch (Error err) {
      PortletException ex =
          new PortletException("Error occured during request processing: " + err.getMessage(), err);
      // Trigger after-completion for thrown exception.
      triggerAfterActionCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex);
      throw ex;
    }

    finally {
      // Clean up any resources used by a multipart request.
      if (processedRequest instanceof MultipartActionRequest && processedRequest != request) {
        this.multipartResolver.cleanupMultipart((MultipartActionRequest) processedRequest);
      }

      // Reset thread-bound context.
      RequestContextHolder.setRequestAttributes(previousRequestAttributes, this.threadContextInheritable);
      LocaleContextHolder.setLocaleContext(previousLocaleContext, this.threadContextInheritable);

      // Clear request attributes.
      requestAttributes.requestCompleted();
      if (logger.isDebugEnabled()) {
        logger.debug("Cleared thread-bound action request context: " + request);
      }
    }
  }
View Full Code Here

    LocaleContext previousLocaleContext = LocaleContextHolder.getLocaleContext();
    LocaleContextHolder.setLocaleContext(buildLocaleContext(request), this.threadContextInheritable);

    // Expose current RequestAttributes to current thread.
    RequestAttributes previousRequestAttributes = RequestContextHolder.getRequestAttributes();
    PortletRequestAttributes requestAttributes = new PortletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);

    if (logger.isDebugEnabled()) {
      logger.debug("Bound render request context to thread: " + request);
    }

    RenderRequest processedRequest = request;
    HandlerExecutionChain mappedHandler = null;
    int interceptorIndex = -1;

    try {
      ModelAndView mv = null;
      try {
        // Check for forwarded exception from the action phase
        PortletSession session = request.getPortletSession(false);
        if (session != null) {
          if (request.getParameter(ACTION_EXCEPTION_RENDER_PARAMETER) != null) {
            Exception ex = (Exception) session.getAttribute(ACTION_EXCEPTION_SESSION_ATTRIBUTE);
            if (ex != null) {
              logger.debug("Render phase found exception caught during action phase - rethrowing it");
              throw ex;
            }
          }
          else {
            session.removeAttribute(ACTION_EXCEPTION_SESSION_ATTRIBUTE);
          }
        }
       
        // Determine handler for the current request.
        mappedHandler = getHandler(processedRequest, false);
        if (mappedHandler == null || mappedHandler.getHandler() == null) {
          noHandlerFound(processedRequest, response);
          return;
        }

        // Apply preHandle methods of registered interceptors.
        HandlerInterceptor[] interceptors = mappedHandler.getInterceptors();
        if (interceptors != null) {
          for (int i = 0; i < interceptors.length; i++) {
            HandlerInterceptor interceptor = interceptors[i];
            if (!interceptor.preHandleRender(processedRequest, response, mappedHandler.getHandler())) {
              triggerAfterRenderCompletion(mappedHandler, interceptorIndex, processedRequest, response, null);
              return;
            }
            interceptorIndex = i;
          }
        }

        // Actually invoke the handler.
        HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());
        mv = ha.handleRender(processedRequest, response, mappedHandler.getHandler());

        // Apply postHandle methods of registered interceptors.
        if (interceptors != null) {
          for (int i = interceptors.length - 1; i >= 0; i--) {
            HandlerInterceptor interceptor = interceptors[i];
            interceptor.postHandleRender(processedRequest, response, mappedHandler.getHandler(), mv);
          }
        }
      }
      catch (ModelAndViewDefiningException ex) {
        logger.debug("ModelAndViewDefiningException encountered", ex);
        mv = ex.getModelAndView();
      }
      catch (Exception ex) {
        Object handler = (mappedHandler != null ? mappedHandler.getHandler() : null);
        mv = processHandlerException(request, response, handler, ex);
      }

      // Did the handler return a view to render?
      if (mv != null && !mv.isEmpty()) {
        render(mv, processedRequest, response);
      }
      else {
        if (logger.isDebugEnabled()) {
          logger.debug("Null ModelAndView returned to DispatcherPortlet with name '" +
              getPortletName() + "': assuming HandlerAdapter completed request handling");
        }
      }

      // Trigger after-completion for successful outcome.
      triggerAfterRenderCompletion(mappedHandler, interceptorIndex, processedRequest, response, null);
    }

    catch (Exception ex) {
      // Trigger after-completion for thrown exception.
      triggerAfterRenderCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex);
      throw ex;
    }
    catch (Error err) {
      PortletException ex =
          new PortletException("Error occured during request processing: " + err.getMessage(), err);
      // Trigger after-completion for thrown exception.
      triggerAfterRenderCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex);
      throw ex;
    }

    finally {
      // Reset thread-bound context.
      RequestContextHolder.setRequestAttributes(previousRequestAttributes, this.threadContextInheritable);
      LocaleContextHolder.setLocaleContext(previousLocaleContext, this.threadContextInheritable);

      // Clear request attributes.
      requestAttributes.requestCompleted();
      if (logger.isDebugEnabled()) {
        logger.debug("Cleared thread-bound render request context: " + request);
      }
    }
  }
View Full Code Here

    LocaleContext previousLocaleContext = LocaleContextHolder.getLocaleContext();
    LocaleContextHolder.setLocaleContext(buildLocaleContext(request), this.threadContextInheritable);

    // Expose current RequestAttributes to current thread.
    RequestAttributes previousRequestAttributes = RequestContextHolder.getRequestAttributes();
    PortletRequestAttributes requestAttributes = null;
    if (previousRequestAttributes == null || previousRequestAttributes.getClass().equals(PortletRequestAttributes.class) ||
        previousRequestAttributes.getClass().equals(ServletRequestAttributes.class)) {
      requestAttributes = new PortletRequestAttributes(request, response);
      RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable);
    }

    if (logger.isTraceEnabled()) {
      logger.trace("Bound request context to thread: " + request);
    }

    try {
      String phase = (String) request.getAttribute(PortletRequest.LIFECYCLE_PHASE);
      if (PortletRequest.ACTION_PHASE.equals(phase)) {
        doActionService((ActionRequest) request, (ActionResponse) response);
      }
      else if (PortletRequest.RENDER_PHASE.equals(phase)) {
        doRenderService((RenderRequest) request, (RenderResponse) response);
      }
      else if (PortletRequest.RESOURCE_PHASE.equals(phase)) {
        doResourceService((ResourceRequest) request, (ResourceResponse) response);
      }
      else if (PortletRequest.EVENT_PHASE.equals(phase)) {
        doEventService((EventRequest) request, (EventResponse) response);
      }
      else {
        throw new IllegalStateException("Invalid portlet request phase: " + phase);
      }
    }
    catch (PortletException ex) {
      failureCause = ex;
      throw ex;
    }
    catch (IOException ex) {
      failureCause = ex;
      throw ex;
    }
    catch (Throwable ex) {
      failureCause = ex;
      throw new PortletException("Request processing failed", ex);
    }

    finally {
      // Clear request attributes and reset thread-bound context.
      LocaleContextHolder.setLocaleContext(previousLocaleContext, this.threadContextInheritable);
      if (requestAttributes != null) {
        RequestContextHolder.setRequestAttributes(previousRequestAttributes, this.threadContextInheritable);
        requestAttributes.requestCompleted();
      }
      if (logger.isTraceEnabled()) {
        logger.trace("Cleared thread-bound resource request context: " + request);
      }
View Full Code Here

            final HttpServletRequest request = servletRequestAttributes.getRequest();
            return request.getContextPath();

        } else if (requestAttributes instanceof PortletRequestAttributes) {

            final PortletRequestAttributes portletRequestAttributes = (PortletRequestAttributes) requestAttributes;
            final PortletRequest request = portletRequestAttributes.getRequest();
            return request.getContextPath();

        } else {
            throw new IllegalStateException("Request attributes are an unrecognized implementation.");
        }
View Full Code Here

TOP

Related Classes of org.springframework.web.portlet.context.PortletRequestAttributes

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.