Search in sources :

Example 1 with ServletWebServerFactory

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

the class EndpointWebMvcAutoConfigurationTests method onDifferentPortWithSpecificServer.

@Test
public void onDifferentPortWithSpecificServer() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management);
    this.applicationContext.register(SpecificWebServerConfig.class, RootConfig.class, DifferentPortConfig.class, EndpointConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    assertContent("/endpoint", ports.get().server, null);
    assertContent("/controller", ports.get().management, null);
    assertContent("/endpoint", ports.get().management, "endpointoutput");
    assertContent("/error", ports.get().management, startsWith("{"));
    ApplicationContext managementContext = this.applicationContext.getBean(ManagementContextResolver.class).getApplicationContext();
    List<?> interceptors = (List<?>) ReflectionTestUtils.getField(managementContext.getBean(EndpointHandlerMapping.class), "interceptors");
    assertThat(interceptors).hasSize(1);
    ServletWebServerFactory parentFactory = this.applicationContext.getBean(ServletWebServerFactory.class);
    ServletWebServerFactory managementFactory = managementContext.getBean(ServletWebServerFactory.class);
    assertThat(parentFactory).isInstanceOf(SpecificServletWebServerFactory.class);
    assertThat(managementFactory).isInstanceOf(SpecificServletWebServerFactory.class);
    assertThat(managementFactory).isNotSameAs(parentFactory);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) ServletWebServerFactory(org.springframework.boot.web.servlet.server.ServletWebServerFactory) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) List(java.util.List) Test(org.junit.Test)

Example 2 with ServletWebServerFactory

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

the class EndpointWebMvcAutoConfigurationTests method undertowManagementAccessLogUsesCustomPrefix.

@Test
public void undertowManagementAccessLogUsesCustomPrefix() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management, "server.undertow.accesslog.enabled: true");
    this.applicationContext.register(UndertowWebServerConfig.class, RootConfig.class, EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    ApplicationContext managementContext = this.applicationContext.getBean(ManagementContextResolver.class).getApplicationContext();
    ServletWebServerFactory factory = managementContext.getBean(ServletWebServerFactory.class);
    assertThat(factory).isInstanceOf(UndertowServletWebServerFactory.class);
    assertThat(((UndertowServletWebServerFactory) factory).getAccessLogPrefix()).isEqualTo("management_access_log.");
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) ServletWebServerFactory(org.springframework.boot.web.servlet.server.ServletWebServerFactory) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) Test(org.junit.Test)

Example 3 with ServletWebServerFactory

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

the class ServletWebServerApplicationContext method createWebServer.

private void createWebServer() {
    WebServer webServer = this.webServer;
    ServletContext servletContext = getServletContext();
    if (webServer == null && servletContext == null) {
        ServletWebServerFactory factory = getWebServerFactory();
        this.webServer = factory.getWebServer(getSelfInitializer());
    } else if (servletContext != null) {
        try {
            getSelfInitializer().onStartup(servletContext);
        } catch (ServletException ex) {
            throw new ApplicationContextException("Cannot initialize servlet context", ex);
        }
    }
    initPropertySources();
}
Also used : ServletException(javax.servlet.ServletException) ServletWebServerFactory(org.springframework.boot.web.servlet.server.ServletWebServerFactory) WebServer(org.springframework.boot.web.server.WebServer) ServletContext(javax.servlet.ServletContext) ApplicationContextException(org.springframework.context.ApplicationContextException)

Example 4 with ServletWebServerFactory

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

the class EndpointWebMvcAutoConfigurationTests method tomcatManagementAccessLogUsesCustomPrefix.

@Test
public void tomcatManagementAccessLogUsesCustomPrefix() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management);
    this.applicationContext.register(TomcatWebServerConfig.class, RootConfig.class, EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "server.tomcat.accesslog.enabled: true");
    this.applicationContext.refresh();
    ApplicationContext managementContext = this.applicationContext.getBean(ManagementContextResolver.class).getApplicationContext();
    ServletWebServerFactory factory = managementContext.getBean(ServletWebServerFactory.class);
    assertThat(factory).isInstanceOf(TomcatServletWebServerFactory.class);
    AccessLogValve accessLogValve = findAccessLogValve(((TomcatServletWebServerFactory) factory));
    assertThat(accessLogValve).isNotNull();
    assertThat(accessLogValve.getPrefix()).isEqualTo("management_access_log");
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) ServletWebServerFactory(org.springframework.boot.web.servlet.server.ServletWebServerFactory) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) AccessLogValve(org.apache.catalina.valves.AccessLogValve) Test(org.junit.Test)

Aggregations

ServletWebServerFactory (org.springframework.boot.web.servlet.server.ServletWebServerFactory)4 Test (org.junit.Test)3 TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)3 UndertowServletWebServerFactory (org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory)3 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)3 ApplicationContext (org.springframework.context.ApplicationContext)3 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)3 List (java.util.List)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1 AccessLogValve (org.apache.catalina.valves.AccessLogValve)1 WebServer (org.springframework.boot.web.server.WebServer)1 ApplicationContextException (org.springframework.context.ApplicationContextException)1