Package org.springframework.web.context.request

Examples of org.springframework.web.context.request.ServletRequestAttributes


  @Override
  public void tearDown() throws Exception {
    super.tearDown();
    /* Tear down the Spring web environment. */
    ServletRequestAttributes requestAttributes =
      (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    requestAttributes.requestCompleted();
    RequestContextHolder.setRequestAttributes(null);
    LocaleContextHolder.setLocale(null);
   
  }
View Full Code Here


          String value = ((String)appList.get(key)).trim();
          String jsp = "StartJNLPApplication.jsp?appName=" + key + "&appStartClass=" + value;
          /*
           * create launch URL
           */
          ServletRequestAttributes requestAttributes;
          try {
            requestAttributes = (ServletRequestAttributes)RequestContextHolder.currentRequestAttributes();
            /*
             * we are running distributed
             */
            HttpServletRequest request = requestAttributes.getRequest();
            value = request.getScheme() + "://" + InetAddress.getLocalHost().getHostName() + ":" + request.getServerPort() + request.getContextPath() + "/" + jsp;

          } catch (IllegalStateException e1) {
            /*
             * we are running locally
View Full Code Here

        String jsp = "StartJNLPApplication.jsp?appName=" + key
            + "&appStartClass=" + value;
        /*
         * create launch URL
         */
        ServletRequestAttributes requestAttributes;
        try {
          requestAttributes = (ServletRequestAttributes) RequestContextHolder
              .currentRequestAttributes();
          /*
           * we are running distributed
           */
          HttpServletRequest request = requestAttributes.getRequest();
          value = request.getScheme() + "://"
              + InetAddress.getLocalHost().getHostName() + ":"
              + request.getServerPort()
              + request.getContextPath() + "/" + jsp;

View Full Code Here

  @Override
  protected void doFilterInternal(
      HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
      throws ServletException, IOException {

    ServletRequestAttributes attributes = new ServletRequestAttributes(request);
    initContextHolders(request, attributes);

    try {
      filterChain.doFilter(request, response);
    }
    finally {
      resetContextHolders();
      if (logger.isDebugEnabled()) {
        logger.debug("Cleared thread-bound request context: " + request);
      }
      attributes.requestCompleted();
    }
  }
View Full Code Here

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

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

    if (logger.isDebugEnabled()) {
      logger.debug("Bound request context to thread: " + request);
    }
   
    try {
      ModelAndView mv = null;
      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.preHandle(processedRequest, response, mappedHandler.getHandler())) {
              triggerAfterCompletion(mappedHandler, interceptorIndex, processedRequest, response, null);
              return;
            }
            interceptorIndex = i;
          }
        }

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

        // Do we need view name translation?
        if (mv != null && !mv.hasView()) {
          mv.setViewName(getDefaultViewName(request));
        }

        // Apply postHandle methods of registered interceptors.
        if (interceptors != null) {
          for (int i = interceptors.length - 1; i >= 0; i--) {
            HandlerInterceptor interceptor = interceptors[i];
            interceptor.postHandle(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(processedRequest, response, handler, ex);
      }

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

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

    catch (Exception ex) {
      // Trigger after-completion for thrown exception.
      triggerAfterCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex);
      throw ex;
    }
    catch (Error err) {
      ServletException ex = new NestedServletException("Handler processing failed", err);
      // Trigger after-completion for thrown exception.
      triggerAfterCompletion(mappedHandler, interceptorIndex, processedRequest, response, ex);
      throw ex;
    }

    finally {
      // Clean up any resources used by a multipart request.
      if (processedRequest != request) {
        cleanupMultipart(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 request context: " + request);
      }
    }
  }
View Full Code Here

          String value = ((String)appList.get(key)).trim();
          String jsp = "StartJNLPApplication.jsp?appName=" + key + "&appStartClass=" + value;
          /*
           * create launch URL
           */
          ServletRequestAttributes requestAttributes;
          try {
            requestAttributes = (ServletRequestAttributes)RequestContextHolder.currentRequestAttributes();
            /*
             * we are running distributed
             */
            HttpServletRequest request = requestAttributes.getRequest();
            value = request.getScheme() + "://" + InetAddress.getLocalHost().getHostName() + ":" + request.getServerPort() + request.getContextPath() + "/" + jsp;

          } catch (IllegalStateException e1) {
            /*
             * we are running locally
View Full Code Here

        String jsp = "StartJNLPApplication.jsp?appName=" + key
            + "&appStartClass=" + value;
        /*
         * create launch URL
         */
        ServletRequestAttributes requestAttributes;
        try {
          requestAttributes = (ServletRequestAttributes) RequestContextHolder
              .currentRequestAttributes();
          /*
           * we are running distributed
           */
          HttpServletRequest request = requestAttributes.getRequest();
          value = request.getScheme() + "://"
              + InetAddress.getLocalHost().getHostName() + ":"
              + request.getServerPort()
              + request.getContextPath() + "/" + jsp;

View Full Code Here

  @Override
  protected NativeWebRequest getWebRequest() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (requestAttributes instanceof ServletRequestAttributes) {
      ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
      return new ServletWebRequest(servletRequestAttributes.getRequest());
    }
    return null;
  }
View Full Code Here

    LocaleContext previousLocaleContext = LocaleContextHolder.getLocaleContext();
    LocaleContext localeContext = buildLocaleContext(request);

    RequestAttributes previousAttributes = RequestContextHolder.getRequestAttributes();
    ServletRequestAttributes requestAttributes = null;
    if (previousAttributes == null || (previousAttributes instanceof ServletRequestAttributes)) {
      requestAttributes = new ServletRequestAttributes(request);
    }

    initContextHolders(request, localeContext, requestAttributes);

    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
    asyncManager.registerCallableInterceptor(FrameworkServlet.class.getName(), getRequestBindingInterceptor(request));

    try {
      doService(request, response);
    }
    catch (ServletException ex) {
      failureCause = ex;
      throw ex;
    }
    catch (IOException ex) {
      failureCause = ex;
      throw ex;
    }
    catch (Throwable ex) {
      failureCause = ex;
      throw new NestedServletException("Request processing failed", ex);
    }

    finally {
      resetContextHolders(request, previousLocaleContext, previousAttributes);
      if (requestAttributes != null) {
        requestAttributes.requestCompleted();
      }

      if (logger.isDebugEnabled()) {
        if (failureCause != null) {
          this.logger.debug("Could not complete request", failureCause);
View Full Code Here

  private CallableProcessingInterceptor getRequestBindingInterceptor(final HttpServletRequest request) {
    return new CallableProcessingInterceptorAdapter() {
      @Override
      public <T> void preProcess(NativeWebRequest webRequest, Callable<T> task) {
        initContextHolders(request, buildLocaleContext(request), new ServletRequestAttributes(request));
      }
      @Override
      public <T> void postProcess(NativeWebRequest webRequest, Callable<T> task, Object concurrentResult) {
        resetContextHolders(request, null, null);
      }
View Full Code Here

TOP

Related Classes of org.springframework.web.context.request.ServletRequestAttributes

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.