Search in sources :

Example 6 with ConfigurableServletWebServerFactory

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

the class ServletWebServerFactoryCustomizerTests method whenShutdownPropertyIsSetThenShutdownIsCustomized.

@Test
void whenShutdownPropertyIsSetThenShutdownIsCustomized() {
    Map<String, String> map = new HashMap<>();
    map.put("server.shutdown", "graceful");
    bindProperties(map);
    ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
    this.customizer.customize(factory);
    ArgumentCaptor<Shutdown> shutdownCaptor = ArgumentCaptor.forClass(Shutdown.class);
    then(factory).should().setShutdown(shutdownCaptor.capture());
    assertThat(shutdownCaptor.getValue()).isEqualTo(Shutdown.GRACEFUL);
}
Also used : ConfigurableServletWebServerFactory(org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory) Shutdown(org.springframework.boot.web.server.Shutdown) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 7 with ConfigurableServletWebServerFactory

use of org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory in project jhipster-registry by jhipster.

the class WebConfigurer method setLocationForStaticAssets.

private void setLocationForStaticAssets(WebServerFactory server) {
    if (server instanceof ConfigurableServletWebServerFactory) {
        ConfigurableServletWebServerFactory servletWebServer = (ConfigurableServletWebServerFactory) server;
        File root;
        String prefixPath = resolvePathPrefix();
        root = new File(prefixPath + "target/classes/static/");
        if (root.exists() && root.isDirectory()) {
            servletWebServer.setDocumentRoot(root);
        }
    }
}
Also used : ConfigurableServletWebServerFactory(org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory) File(java.io.File)

Example 8 with ConfigurableServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizerTests method testDefaultDisplayName.

@Test
public void testDefaultDisplayName() throws Exception {
    ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
    this.customizer.customize(factory);
    verify(factory).setDisplayName("application");
}
Also used : ConfigurableServletWebServerFactory(org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory) Test(org.junit.Test)

Example 9 with ConfigurableServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizerTests method testCustomizeTomcatPort.

@Test
public void testCustomizeTomcatPort() throws Exception {
    ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
    this.properties.setPort(8080);
    this.customizer.customize(factory);
    verify(factory).setPort(8080);
}
Also used : ConfigurableServletWebServerFactory(org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory) Test(org.junit.Test)

Example 10 with ConfigurableServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizerTests method customizeSessionProperties.

@Test
public void customizeSessionProperties() throws Exception {
    Map<String, String> map = new HashMap<>();
    map.put("server.session.timeout", "123");
    map.put("server.session.tracking-modes", "cookie,url");
    map.put("server.session.cookie.name", "testname");
    map.put("server.session.cookie.domain", "testdomain");
    map.put("server.session.cookie.path", "/testpath");
    map.put("server.session.cookie.comment", "testcomment");
    map.put("server.session.cookie.http-only", "true");
    map.put("server.session.cookie.secure", "true");
    map.put("server.session.cookie.max-age", "60");
    bindProperties(map);
    ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
    ServletContext servletContext = mock(ServletContext.class);
    SessionCookieConfig sessionCookieConfig = mock(SessionCookieConfig.class);
    given(servletContext.getSessionCookieConfig()).willReturn(sessionCookieConfig);
    this.customizer.customize(factory);
    triggerInitializers(factory, servletContext);
    verify(factory).setSessionTimeout(123);
    verify(servletContext).setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE, SessionTrackingMode.URL));
    verify(sessionCookieConfig).setName("testname");
    verify(sessionCookieConfig).setDomain("testdomain");
    verify(sessionCookieConfig).setPath("/testpath");
    verify(sessionCookieConfig).setComment("testcomment");
    verify(sessionCookieConfig).setHttpOnly(true);
    verify(sessionCookieConfig).setSecure(true);
    verify(sessionCookieConfig).setMaxAge(60);
}
Also used : ConfigurableServletWebServerFactory(org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory) HashMap(java.util.HashMap) ServletContext(javax.servlet.ServletContext) SessionCookieConfig(javax.servlet.SessionCookieConfig) Test(org.junit.Test)

Aggregations

ConfigurableServletWebServerFactory (org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory)32 Test (org.junit.jupiter.api.Test)10 File (java.io.File)9 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 Session (org.springframework.boot.web.servlet.server.Session)2 ServletContext (javax.servlet.ServletContext)1 SessionCookieConfig (javax.servlet.SessionCookieConfig)1 KeycloakAuthenticatorValve (org.keycloak.adapters.tomcat.KeycloakAuthenticatorValve)1 JettyServletWebServerFactory (org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory)1 TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)1 UndertowServletWebServerFactory (org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory)1 MimeMappings (org.springframework.boot.web.server.MimeMappings)1 Shutdown (org.springframework.boot.web.server.Shutdown)1 Ssl (org.springframework.boot.web.server.Ssl)1 WebServerFactoryCustomizer (org.springframework.boot.web.server.WebServerFactoryCustomizer)1 Jsp (org.springframework.boot.web.servlet.server.Jsp)1 Cookie (org.springframework.boot.web.servlet.server.Session.Cookie)1 Bean (org.springframework.context.annotation.Bean)1