Search in sources :

Example 1 with ParameterizableViewController

use of org.springframework.web.servlet.mvc.ParameterizableViewController in project cas by apereo.

the class CasApplicationContextConfiguration method rootController.

@Bean
protected Controller rootController() {
    return new ParameterizableViewController() {

        @Override
        protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) {
            final String queryString = request.getQueryString();
            final String url = request.getContextPath() + "/login" + (queryString != null ? '?' + queryString : StringUtils.EMPTY);
            return new ModelAndView(new RedirectView(response.encodeURL(url)));
        }
    };
}
Also used : ParameterizableViewController(org.springframework.web.servlet.mvc.ParameterizableViewController) HttpServletRequest(javax.servlet.http.HttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) HttpServletResponse(javax.servlet.http.HttpServletResponse) Bean(org.springframework.context.annotation.Bean)

Example 2 with ParameterizableViewController

use of org.springframework.web.servlet.mvc.ParameterizableViewController in project spring-framework by spring-projects.

the class MvcNamespaceTests method testViewControllersDefaultConfig.

@Test
public void testViewControllersDefaultConfig() {
    loadBeanDefinitions("mvc-config-view-controllers-minimal.xml");
    SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class);
    assertThat(hm).isNotNull();
    ParameterizableViewController viewController = (ParameterizableViewController) hm.getUrlMap().get("/path");
    assertThat(viewController).isNotNull();
    assertThat(viewController.getViewName()).isEqualTo("home");
    ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old");
    assertThat(redirectViewController).isNotNull();
    assertThat(redirectViewController.getView()).isInstanceOf(RedirectView.class);
    ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad");
    assertThat(statusViewController).isNotNull();
    assertThat(statusViewController.getStatusCode().value()).isEqualTo(404);
    BeanNameUrlHandlerMapping beanNameMapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class);
    assertThat(beanNameMapping).isNotNull();
    assertThat(beanNameMapping.getOrder()).isEqualTo(2);
}
Also used : ParameterizableViewController(org.springframework.web.servlet.mvc.ParameterizableViewController) BeanNameUrlHandlerMapping(org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping) SimpleUrlHandlerMapping(org.springframework.web.servlet.handler.SimpleUrlHandlerMapping) Test(org.junit.jupiter.api.Test)

Example 3 with ParameterizableViewController

use of org.springframework.web.servlet.mvc.ParameterizableViewController in project spring-framework by spring-projects.

the class ViewControllerRegistryTests method getRedirectView.

private RedirectView getRedirectView(String path) {
    ParameterizableViewController controller = getController(path);
    assertThat(controller.getViewName()).isNull();
    assertThat(controller.getView()).isNotNull();
    assertThat(controller.getView().getClass()).isEqualTo(RedirectView.class);
    return (RedirectView) controller.getView();
}
Also used : ParameterizableViewController(org.springframework.web.servlet.mvc.ParameterizableViewController) RedirectView(org.springframework.web.servlet.view.RedirectView)

Example 4 with ParameterizableViewController

use of org.springframework.web.servlet.mvc.ParameterizableViewController in project spring-framework by spring-projects.

the class ViewControllerRegistryTests method addViewControllerWithDefaultViewName.

@Test
public void addViewControllerWithDefaultViewName() {
    this.registry.addViewController("/path");
    ParameterizableViewController controller = getController("/path");
    assertThat(controller.getViewName()).isNull();
    assertThat(controller.getStatusCode()).isNull();
    assertThat(controller.isStatusOnly()).isFalse();
    assertThat(controller.getApplicationContext()).isNotNull();
}
Also used : ParameterizableViewController(org.springframework.web.servlet.mvc.ParameterizableViewController) Test(org.junit.jupiter.api.Test)

Example 5 with ParameterizableViewController

use of org.springframework.web.servlet.mvc.ParameterizableViewController in project spring-framework by spring-projects.

the class ViewControllerRegistryTests method addStatusController.

@Test
public void addStatusController() {
    this.registry.addStatusController("/path", HttpStatus.NOT_FOUND);
    ParameterizableViewController controller = getController("/path");
    assertThat(controller.getViewName()).isNull();
    assertThat(controller.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
    assertThat(controller.isStatusOnly()).isTrue();
    assertThat(controller.getApplicationContext()).isNotNull();
}
Also used : ParameterizableViewController(org.springframework.web.servlet.mvc.ParameterizableViewController) Test(org.junit.jupiter.api.Test)

Aggregations

ParameterizableViewController (org.springframework.web.servlet.mvc.ParameterizableViewController)9 Test (org.junit.jupiter.api.Test)4 RedirectView (org.springframework.web.servlet.view.RedirectView)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Bean (org.springframework.context.annotation.Bean)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 lombok.val (lombok.val)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 BeanNameUrlHandlerMapping (org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping)1 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)1