Package org.springframework.web.context.request

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


    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        ServletRequest subSessionRequest = request;
        ServletResponse subSessionResponse = response;
        ServletRequestAttributes attributes = null;
        if (request instanceof HttpServletRequest) {
            HttpServletRequest httpRequest = (HttpServletRequest) request;
            attributes = new ServletRequestAttributes(httpRequest);
            setContext(httpRequest, attributes);
            String path = httpRequest.getPathInfo() == null ? httpRequest.getServletPath() : httpRequest.getPathInfo();
            subSessionResponse = compress(path, httpRequest, (HttpServletResponse) response);
        }
        try {
            super.doFilter(subSessionRequest, subSessionResponse, filterChain);
        } finally {
            RequestContextHolder.resetRequestAttributes();
            LocaleContextHolder.resetLocaleContext();
            if (attributes != null) attributes.requestCompleted();
        }
        gzip(subSessionResponse);
    }
View Full Code Here


  }

  public void requestInitialized(ServletRequestEvent servletRequestEvent) {
    if (servletRequestEvent.getServletRequest() instanceof HttpServletRequest) {
      HttpServletRequest request = (HttpServletRequest) servletRequestEvent.getServletRequest();
      ServletRequestAttributes attributes = new ServletRequestAttributes(request);
      request.setAttribute(REQUEST_ATTRIBUTES_ATTRIBUTE, attributes);
      LocaleContextHolder.setLocale(request.getLocale());
      RequestContextHolder.setRequestAttributes(attributes);
    }
  }
View Full Code Here

      RequestContextHolder.setRequestAttributes(attributes);
    }
  }

  public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
    ServletRequestAttributes attributes = (ServletRequestAttributes) servletRequestEvent.getServletRequest()
        .getAttribute(REQUEST_ATTRIBUTES_ATTRIBUTE);
    ServletRequestAttributes threadAttributes =
        (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    if (threadAttributes != null) {
      if (attributes == null) {
        attributes = threadAttributes;
      }
View Full Code Here

    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setScheme("http");
    mockRequest.setServerName("geomajas.org");
    mockRequest.setServerPort(80);
    mockRequest.setContextPath("/test");
    ServletRequestAttributes attributes = new ServletRequestAttributes(mockRequest);
    RequestContextHolder.setRequestAttributes(attributes);

    Assert.assertEquals("http://geomajas.org/test/d/", adus.getDispatcherUrl());

View Full Code Here

    request.setParameter("_conversationID", "ttt");
    context = new Context();
    context.setServletRequest(request);
    context.setHttpSession(request.getSession());
    context.getParams().put("_conversationID", "ttt");
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
  }
View Full Code Here

   * Initializes web tests. Will register a {@link MockHttpServletRequest} for the current thread.
   */
  public static void initWebTest() {

    MockHttpServletRequest request = new MockHttpServletRequest();
    ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(requestAttributes);
  }
View Full Code Here

        return null;
    }

    /** Get the current servlet request, possibly null. */
    protected HttpServletRequest getServletRequest() {
        ServletRequestAttributes requestAttributes = this.getServletRequestAttributes();
        if (requestAttributes != null) {
            return requestAttributes.getRequest();
        }

        return null;
    }
View Full Code Here

  @Override
  public UtilisateurGrpModel checkUserByKerberosSSO() {

    UtilisateurGrpModel userModel = new UtilisateurGrpModel();
    ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    HttpServletRequest request = attr.getRequest();

//    if( request.getUserPrincipal() != null && !"".equalsIgnoreCase(request.getUserPrincipal().getName()) ) {
//      String userLogin = request.getUserPrincipal().getName();
      String userLogin = "long.nguyen@bouygues-construction.com";
      if( userLogin != null ) {
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.isTraceEnabled()) {
      logger.trace("Bound request context to thread: " + request);
    }
   
    try {
      ModelAndView mv = null;
      boolean errorView = false;

      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);
        errorView = (mv != null);
      }

      // Did the handler return a view to render?
      if (mv != null && !mv.wasCleared()) {
        render(mv, processedRequest, response);
        if (errorView) {
          WebUtils.clearErrorRequestAttributes(request);
        }
      }
      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.isTraceEnabled()) {
        logger.trace("Cleared thread-bound request context: " + request);
      }
    }
  }
View Full Code Here

  @Override
  public void setUp() throws Exception {
    super.setUp();
    /* Simulate the Spring environment. */
    LocaleContextHolder.setLocale(request.getLocale());
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));

  }
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.