Package org.springframework.web.servlet

Examples of org.springframework.web.servlet.HandlerExecutionChain


   * @return the final handler object
   */
  protected Object buildPathExposingHandler(Object rawHandler, String bestMatchingPattern,
      String pathWithinMapping, Map<String, String> uriTemplateVariables) {

    HandlerExecutionChain chain = new HandlerExecutionChain(rawHandler);
    chain.addInterceptor(new PathExposingHandlerInterceptor(bestMatchingPattern, pathWithinMapping));
    if (!CollectionUtils.isEmpty(uriTemplateVariables)) {
      chain.addInterceptor(new UriTemplateVariablesHandlerInterceptor(uriTemplateVariables));
    }
    return chain;
  }
View Full Code Here


   * @param request current HTTP request
   * @return the HandlerExecutionChain (never {@code null})
   * @see #getAdaptedInterceptors()
   */
  protected HandlerExecutionChain getHandlerExecutionChain(Object handler, HttpServletRequest request) {
    HandlerExecutionChain chain = (handler instanceof HandlerExecutionChain ?
        (HandlerExecutionChain) handler : new HandlerExecutionChain(handler));
    chain.addInterceptors(getAdaptedInterceptors());

    String lookupPath = this.urlPathHelper.getLookupPathForRequest(request);
    for (MappedInterceptor mappedInterceptor : this.mappedInterceptors) {
      if (mappedInterceptor.matches(lookupPath, this.pathMatcher)) {
        chain.addInterceptor(mappedInterceptor.getInterceptor());
      }
    }

    return chain;
  }
View Full Code Here

    request.setMethod("GET");
    request.setRequestURI("/myapp/app/bar");
    request.setContextPath("/myapp");
    request.setServletPath("/app/");
    request.setAttribute("com.ibm.websphere.servlet.uri_non_decoded", "/myapp/app/bar");
    HandlerExecutionChain chain = mapping2.getHandler(request);
    assertEquals(4, chain.getInterceptors().length);
    assertTrue(chain.getInterceptors()[1] instanceof ConversionServiceExposingInterceptor);
    assertTrue(chain.getInterceptors()[2] instanceof LocaleChangeInterceptor);
    assertTrue(chain.getInterceptors()[3] instanceof ThemeChangeInterceptor);
    ModelAndView mv2 = adapter.handle(request, new MockHttpServletResponse(), chain.getHandler());
    assertEquals("baz", mv2.getViewName());

    request.setRequestURI("/myapp/app/");
    request.setContextPath("/myapp");
    request.setServletPath("/app/");
    chain = mapping2.getHandler(request);
    assertEquals(4, chain.getInterceptors().length);
    assertTrue(chain.getInterceptors()[1] instanceof ConversionServiceExposingInterceptor);
    assertTrue(chain.getInterceptors()[2] instanceof LocaleChangeInterceptor);
    assertTrue(chain.getInterceptors()[3] instanceof ThemeChangeInterceptor);
    ModelAndView mv3 = adapter.handle(request, new MockHttpServletResponse(), chain.getHandler());
    assertEquals("root", mv3.getViewName());

    request.setRequestURI("/myapp/");
    request.setContextPath("/myapp");
    request.setServletPath("/");
    chain = mapping2.getHandler(request);
    assertEquals(4, chain.getInterceptors().length);
    assertTrue(chain.getInterceptors()[1] instanceof ConversionServiceExposingInterceptor);
    assertTrue(chain.getInterceptors()[2] instanceof LocaleChangeInterceptor);
    assertTrue(chain.getInterceptors()[3] instanceof ThemeChangeInterceptor);
    mv3 = adapter.handle(request, new MockHttpServletResponse(), chain.getHandler());
    assertEquals("root", mv3.getViewName());
  }
View Full Code Here

  private void doTestRequestsWithSubPaths(HandlerMapping hm) throws Exception {
    Object bean = wac.getBean("godCtrl");

    MockHttpServletRequest req = new MockHttpServletRequest("GET", "/mypath/welcome.html");
    HandlerExecutionChain hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/myapp/mypath/welcome.html");
    req.setContextPath("/myapp");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/myapp/mypath/welcome.html");
    req.setContextPath("/myapp");
    req.setServletPath("/mypath/welcome.html");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/myapp/myservlet/mypath/welcome.html");
    req.setContextPath("/myapp");
    req.setServletPath("/myservlet");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/myapp/myapp/mypath/welcome.html");
    req.setContextPath("/myapp");
    req.setServletPath("/myapp");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/mypath/show.html");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/mypath/bookseats.html");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
  }
View Full Code Here

    this.hm = (HandlerMapping) this.wac.getBean("mapping");
  }

  public void testIndexUri() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/index");
    HandlerExecutionChain chain = this.hm.getHandler(request);
    assertEquals(this.wac.getBean("index"), chain.getHandler());
  }
View Full Code Here

    assertEquals(this.wac.getBean("index"), chain.getHandler());
  }

  public void testMapSimpleUri() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/welcome");
    HandlerExecutionChain chain = this.hm.getHandler(request);
    assertEquals(this.wac.getBean("welcome"), chain.getHandler());
  }
View Full Code Here

  }

  public void testWithContextPath() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myapp/welcome");
    request.setContextPath("/myapp");
    HandlerExecutionChain chain = this.hm.getHandler(request);
    assertEquals(this.wac.getBean("welcome"), chain.getHandler());
  }
View Full Code Here

    hm.setAlwaysUseFullPath(true);
    hm.setApplicationContext(wac);
    Object bean = wac.getBean("godCtrl");

    MockHttpServletRequest req = new MockHttpServletRequest("GET", "/mypath/welcome.html");
    HandlerExecutionChain hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/myapp/mypath/welcome.html");
    req.setContextPath("/myapp");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/mypath/welcome.html");
    req.setContextPath("");
    req.setServletPath("/mypath");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/Myapp/mypath/welcome.html");
    req.setContextPath("/myapp");
    req.setServletPath("/mypath");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
  }
View Full Code Here

    assertEquals(this.wac.getBean("welcome"), chain.getHandler());
  }

  public void testWithMultiActionControllerMapping() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/admin");
    HandlerExecutionChain chain = this.hm.getHandler(request);
    assertEquals(this.wac.getBean("admin"), chain.getHandler());
  }
View Full Code Here

    assertEquals(this.wac.getBean("admin"), chain.getHandler());
  }

  public void testWithoutControllerSuffix() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/buy");
    HandlerExecutionChain chain = this.hm.getHandler(request);
    assertEquals(this.wac.getBean("buy"), chain.getHandler());
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.servlet.HandlerExecutionChain

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.