Search in sources :

Example 31 with DispatcherServlet

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

the class HttpTransportConfiguration method httpServer.

@Bean(initMethod = "start", destroyMethod = "stop")
@Order(0)
public Server httpServer(@Value("${http.enabled:false}") boolean httpEnabled, @Value("${http.hostname:}") String httpHostname, @Value("${http.port:-1}") int httpPort, @Value("${https.enabled:false}") boolean httpsEnabled, @Value("${https.hostname:}") String httpsHostname, @Value("${https.port:-1}") int httpsPort, @Value("${https.selfSigned:false}") boolean selfSigned, @Value("${https.mutualSsl:false}") boolean mutualSsl, @Value("${https.keyStorePath:}") String keyStorePath, @Value("${https.keyStoreData:}") String keyStoreData, @Value("${https.keyStorePassword:}") String keyStorePassword, @Value("${https.keyManagerPassword:}") String keyManagerPassword, @Value("${https.trustStorePath:}") String trustStorePath, @Value("${https.trustStoreData:}") String trustStoreData, @Value("${https.trustStorePassword:}") String trustStorePassword, @Value("${https.excludedCipherSuites:}") String[] excludedCipherSuites, ConfigurableWebApplicationContext webApplicationContext) throws Exception {
    // set up servlets
    ServletContextHandler context = servletContextHandler();
    // create a new child application context
    AnnotationConfigWebApplicationContext childApplicationContext = (AnnotationConfigWebApplicationContext) transportWebMvcContext(webApplicationContext, context).getContext();
    // register swagger
    childApplicationContext.getBean(SwaggerRegistry.class).registerSwagger(context, getObjectMappers(webApplicationContext));
    // configure the spring mvc dispatcher
    DispatcherServlet dispatcher = new DispatcherServlet(childApplicationContext);
    // enable gzip
    context.addFilter(GzipFilter.class, "/*", null);
    // map application servlets
    context.addServlet(new ServletHolder(dispatcher), "/");
    if (healthCheckRegistry != null) {
        context.addServlet(new ServletHolder(new HealthServlet(healthCheckRegistry)), "/healthcheck");
    }
    // create the server
    Server server;
    if (metricRegistry == null || !monitorThreadpool) {
        server = new Server();
        server.setHandler(context);
    } else {
        server = new Server(new InstrumentedQueuedThreadPool(metricRegistry));
        InstrumentedHandler instrumented = new InstrumentedHandler(metricRegistry);
        instrumented.setHandler(context);
        server.setHandler(instrumented);
    }
    // set up connectors
    if (httpEnabled) {
        InetSocketAddress address = StringUtils.isBlank(httpHostname) ? new InetSocketAddress(httpPort) : new InetSocketAddress(httpHostname, httpPort);
        JettyConnectorRegistry.registerHttpConnector(server, address);
    }
    if (httpsEnabled) {
        InetSocketAddress address = StringUtils.isBlank(httpsHostname) ? new InetSocketAddress(httpsPort) : new InetSocketAddress(httpsHostname, httpsPort);
        JettyConnectorRegistry.registerHttpsConnector(server, address, selfSigned, mutualSsl, keyStorePath, keyStoreData, keyStorePassword, keyManagerPassword, trustStorePath, trustStoreData, trustStorePassword, excludedCipherSuites);
    }
    return server;
}
Also used : InstrumentedQueuedThreadPool(com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool) Server(org.eclipse.jetty.server.Server) HealthServlet(com.kixeye.chassis.transport.shared.HealthServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) InetSocketAddress(java.net.InetSocketAddress) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) SwaggerRegistry(com.kixeye.chassis.transport.swagger.SwaggerRegistry) Order(org.springframework.core.annotation.Order) Bean(org.springframework.context.annotation.Bean)

Example 32 with DispatcherServlet

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

the class JPAWebConfigurer 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 33 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 34 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project Protocol-Adapter-OSLP by OSGP.

the class WebDeviceSimulatorInitializer method onStartup.

/**
 */
@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    startUp(servletContext);
    InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
    final ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING);
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) Slf4JLoggerFactory(org.jboss.netty.logging.Slf4JLoggerFactory)

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