Examples of DispatcherServlet


Examples of org.springframework.web.servlet.DispatcherServlet

    servlet.service(request, response);
    assertEquals("mySurpriseView", response.getContentAsString());
  }

  public void testControllerClassNamePlusMethodNameDispatchingController() throws Exception {
    @SuppressWarnings("serial")
    DispatcherServlet servlet = new DispatcherServlet() {
      protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
        GenericWebApplicationContext wac = new GenericWebApplicationContext();
        RootBeanDefinition mapping = new RootBeanDefinition(ControllerClassNameHandlerMapping.class);
        mapping.getPropertyValues().addPropertyValue("excludedPackages", null);
        wac.registerBeanDefinition("handlerMapping", mapping);
        wac.registerBeanDefinition("controller", new RootBeanDefinition(MethodNameDispatchingController.class));
        wac.refresh();
        return wac;
      }
    };
    servlet.init(new MockServletConfig());

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/methodnamedispatching/myHandle");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("myView", response.getContentAsString());

    request = new MockHttpServletRequest("GET", "/methodnamedispatching/myOtherHandle.do");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("myOtherView", response.getContentAsString());

    request = new MockHttpServletRequest("POST", "/methodnamedispatching/myLangHandle.x");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("myLangView", response.getContentAsString());

    request = new MockHttpServletRequest("POST", "/methodnamedispatching/mySurpriseHandle.y");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("mySurpriseView", response.getContentAsString());
  }
View Full Code Here

Examples of org.springframework.web.servlet.DispatcherServlet

    servlet.service(request, response);
    assertEquals("mySurpriseView", response.getContentAsString());
  }

  public void testPostMethodNameDispatchingController() throws Exception {
    @SuppressWarnings("serial")
    DispatcherServlet servlet = new DispatcherServlet() {
      protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
        GenericWebApplicationContext wac = new GenericWebApplicationContext();
        wac.registerBeanDefinition("controller", new RootBeanDefinition(MyPostMethodNameDispatchingController.class));
        wac.refresh();
        return wac;
      }
    };
    servlet.init(new MockServletConfig());

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myHandle.do");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals(405, response.getStatus());

    request = new MockHttpServletRequest("POST", "/myUnknownHandle.do");
    request.addParameter("myParam", "myValue");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals(404, response.getStatus());

    request = new MockHttpServletRequest("POST", "/myHandle.do");
    request.addParameter("myParam", "myValue");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("myView", response.getContentAsString());

    request = new MockHttpServletRequest("POST", "/myOtherHandle.do");
    request.addParameter("myParam", "myValue");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("myOtherView", response.getContentAsString());

    request = new MockHttpServletRequest("POST", "/myLangHandle.do");
    request.addParameter("myParam", "myValue");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("myLangView", response.getContentAsString());

    request = new MockHttpServletRequest("POST", "/mySurpriseHandle.do");
    request.addParameter("myParam", "myValue");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("mySurpriseView", response.getContentAsString());
  }
View Full Code Here

Examples of org.springframework.web.servlet.DispatcherServlet

    servlet.service(request, response);
    assertEquals("mySurpriseView", response.getContentAsString());
  }

  public void testRelativePathDispatchingController() throws Exception {
    @SuppressWarnings("serial")
    DispatcherServlet servlet = new DispatcherServlet() {
      protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
        GenericWebApplicationContext wac = new GenericWebApplicationContext();
        wac.registerBeanDefinition("controller", new RootBeanDefinition(MyRelativePathDispatchingController.class));
        wac.refresh();
        return wac;
      }
    };
    servlet.init(new MockServletConfig());

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myApp/myHandle");
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("myView", response.getContentAsString());

    request = new MockHttpServletRequest("GET", "/myApp/myOther");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("myOtherView", response.getContentAsString());

    request = new MockHttpServletRequest("GET", "/myApp/myLang");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("myLangView", response.getContentAsString());

    request = new MockHttpServletRequest("GET", "/myApp/surprise.do");
    response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("mySurpriseView", response.getContentAsString());
  }
View Full Code Here

Examples of org.springframework.web.servlet.DispatcherServlet

    servlet.service(request, response);
    assertEquals("mySurpriseView", response.getContentAsString());
  }

  public void testNullCommandController() throws Exception {
    @SuppressWarnings("serial")
    DispatcherServlet servlet = new DispatcherServlet() {
      protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
        GenericWebApplicationContext wac = new GenericWebApplicationContext();
        wac.registerBeanDefinition("controller", new RootBeanDefinition(MyNullCommandController.class));
        wac.refresh();
        return wac;
      }
    };
    servlet.init(new MockServletConfig());

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath");
    request.setUserPrincipal(new OtherPrincipal());
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("myView", response.getContentAsString());
  }
View Full Code Here

Examples of org.springframework.web.servlet.DispatcherServlet

    servlet.service(request, response);
    assertEquals("myView", response.getContentAsString());
  }

  public void testEquivalentMappingsWithSameMethodName() throws Exception {
    @SuppressWarnings("serial")
    DispatcherServlet servlet = new DispatcherServlet() {
      protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
        GenericWebApplicationContext wac = new GenericWebApplicationContext();
        wac.registerBeanDefinition("controller", new RootBeanDefinition(ChildController.class));
        wac.refresh();
        return wac;
      }
    };
    servlet.init(new MockServletConfig());

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/child/test");
    request.addParameter("childId", "100");
    MockHttpServletResponse response = new MockHttpServletResponse();
    try {
      servlet.service(request, response);
    }
    catch (NestedServletException ex) {
      assertTrue(ex.getCause() instanceof IllegalStateException);
      assertTrue(ex.getCause().getMessage().contains("doGet"));
    }
View Full Code Here

Examples of org.springframework.web.servlet.DispatcherServlet

    wac.setServletContext(servletContext);
    wac.setServletConfig(servletConfig);
      wac.register(WebConfig.class);
      wac.refresh();

      this.dispatcherServlet = new DispatcherServlet(wac);
      this.dispatcherServlet.init(servletConfig);
  }
View Full Code Here

Examples of org.springframework.web.servlet.DispatcherServlet

    public void onStartup(ServletContext servletContext) throws ServletException {

        WebApplicationContext context = getContext();
        servletContext.addListener(new ContextLoaderListener(context));

        ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping(MAPPING_URL);
    }
View Full Code Here

Examples of org.springframework.web.servlet.DispatcherServlet

  private void registerServlets(ServletContext servletContext,
      AnnotationConfigWebApplicationContext root) {

    // MVC -------------
    final ServletRegistration.Dynamic registration = servletContext.addServlet(
        "dispatcher", new DispatcherServlet(root));
    registration.setLoadOnStartup(0);
    registration.addMapping(ConfigProps.WEB_PATH.value(root.getEnvironment()));

    // Jersey --------------
    final ServletRegistration.Dynamic jerseyServlet = servletContext.addServlet(
View Full Code Here

Examples of org.springframework.web.servlet.DispatcherServlet

    @Before
    public void setUp() {
        super.setUp();

        try {
            servlet = new DispatcherServlet();
            servlet.setContextClass(MyContext.class);
            config = new MockServletConfig(new MockServletContext(), "simple");
            servlet.init(config);
        } catch (Exception e) {
            throw new RuntimeException(e);
View Full Code Here

Examples of org.springframework.web.servlet.DispatcherServlet

        addPropertyValue("serviceInterface", CopperMonitoringService.class.getName()).
        addPropertyValue("remoteInvocationExecutor", remoteInvocationExecutor).
        getBeanDefinition());
    genericWebApplicationContext.refresh();
   
    DispatcherServlet dispatcherServlet = new DispatcherServlet(genericWebApplicationContext);
    ServletHolder servletHolder = new ServletHolder(dispatcherServlet);
    servletContextHandler.addServlet(servletHolder, "/*");
   
    FilterHolder filterHolder = new FilterHolder();
    GzipFilter filter = new GzipFilter();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.