Search in sources :

Example 11 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project pinpoint by naver.

the class SpringWebMvcIT method testRequest.

@Test
public void testRequest() throws Exception {
    MockServletConfig config = new MockServletConfig();
    MockHttpServletRequest req = new MockHttpServletRequest();
    MockHttpServletResponse res = new MockHttpServletResponse();
    config.addInitParameter("contextConfigLocation", "classpath:spring-web-test.xml");
    req.setMethod("GET");
    req.setRequestURI("/");
    req.setRemoteAddr("1.2.3.4");
    DispatcherServlet servlet = new DispatcherServlet();
    servlet.init(config);
    servlet.service(req, res);
    Method method = FrameworkServlet.class.getDeclaredMethod("doGet", HttpServletRequest.class, HttpServletResponse.class);
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    verifier.verifyTrace(Expectations.event(SPRING_MVC, method));
    verifier.verifyTraceCount(0);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) MockServletConfig(org.springframework.mock.web.MockServletConfig) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 12 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project spring-boot by spring-projects.

the class EmbeddedJarStarter method main.

public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);
    AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
    webApplicationContext.register(SpringConfiguration.class);
    DispatcherServlet dispatcherServlet = new DispatcherServlet(webApplicationContext);
    context.addServlet(new ServletHolder(dispatcherServlet), "/*");
    server.start();
    server.join();
}
Also used : Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext)

Example 13 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project chassis by Kixeye.

the class TestSpringWebApp method httpServer.

@Bean(initMethod = "start", destroyMethod = "stop", name = "httpServer")
@Order(0)
public Server httpServer(ConfigurableWebApplicationContext webApplicationContext) {
    // set up servlets
    ServletHandler servlets = new ServletHandler();
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
    context.setErrorHandler(null);
    context.setWelcomeFiles(new String[] { "/" });
    // set up spring with the servlet context
    setServletContext(context.getServletContext());
    // configure the spring mvc dispatcher
    DispatcherServlet dispatcher = new DispatcherServlet(webApplicationContext);
    // map application servlets
    context.addServlet(new ServletHolder(dispatcher), "/");
    servlets.setHandler(context);
    // create the server
    InetSocketAddress address = new InetSocketAddress(SocketUtils.findAvailableTcpPort());
    Server server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setHost(address.getHostName());
    connector.setPort(address.getPort());
    server.setConnectors(new Connector[] { connector });
    server.setHandler(servlets);
    server.setStopAtShutdown(true);
    return server;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) InetSocketAddress(java.net.InetSocketAddress) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Order(org.springframework.core.annotation.Order) Bean(org.springframework.context.annotation.Bean)

Example 14 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project Activiti by Activiti.

the class WebConfigurer method initSpring.

/**
   * Initializes Spring and Spring MVC.
   */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    log.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);
    log.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);
    return dispatcherServlet;
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext)

Example 15 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project Activiti by Activiti.

the class WebConfigurer method initSpring.

/**
   * Initializes Spring and Spring MVC.
   */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    log.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);
    log.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);
    return dispatcherServlet;
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext)

Aggregations

DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)34 Test (org.junit.Test)16 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)14 MockServletConfig (org.springframework.mock.web.test.MockServletConfig)7 WebApplicationContext (org.springframework.web.context.WebApplicationContext)6 ServletRegistration (javax.servlet.ServletRegistration)5 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)5 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)5 Server (org.eclipse.jetty.server.Server)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)4 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)4 Bean (org.springframework.context.annotation.Bean)4 MockServletContext (org.springframework.mock.web.MockServletContext)4 InetSocketAddress (java.net.InetSocketAddress)3 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)3 Order (org.springframework.core.annotation.Order)3 MockServletContext (org.springframework.mock.web.test.MockServletContext)3 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)3 Filter (javax.servlet.Filter)2 ServerConnector (org.eclipse.jetty.server.ServerConnector)2