Search in sources :

Example 41 with TomcatServletWebServerFactory

use of org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory in project spring-thymeleaf-simplefinance by heitkergm.

the class Application method servletWebServer.

/**
 * This sets up the embedded tomcat server.
 *
 * @return the customized embedded tomcat server
 */
@Bean
public TomcatServletWebServerFactory servletWebServer() {
    TomcatServletWebServerFactory tomcat;
    tomcat = new TomcatServletWebServerFactoryImpl();
    tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) (final Connector connector) -> {
        connector.setRedirectPort(8443);
    });
    tomcat.addAdditionalTomcatConnectors(createSSLConnector());
    return tomcat;
}
Also used : Connector(org.apache.catalina.connector.Connector) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) Bean(org.springframework.context.annotation.Bean)

Example 42 with TomcatServletWebServerFactory

use of org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory in project joinfaces by joinfaces.

the class TomcatAutoConfigurationTest method customize.

@Test
public void customize() {
    TomcatServletWebServerFactory tomcatFactory = new TomcatServletWebServerFactory();
    this.tomcatAutoConfiguration.jsfTomcatFactoryCustomizer().customize(tomcatFactory);
    assertThat(tomcatFactory.getTomcatContextCustomizers()).isNotEmpty();
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) Test(org.junit.Test)

Example 43 with TomcatServletWebServerFactory

use of org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory in project cas by apereo.

the class X509TomcatServletWebServiceFactoryCustomizer method customize.

@Override
public void customize(final ConfigurableServletWebServerFactory factory) {
    val webflow = casProperties.getAuthn().getX509().getWebflow();
    if (factory instanceof TomcatServletWebServerFactory && webflow.getPort() > 0) {
        val tomcat = (TomcatServletWebServerFactory) factory;
        LOGGER.debug("Creating X509 configuration for the tomcat container...");
        val connector = new Connector("HTTP/1.1");
        connector.setPort(webflow.getPort());
        connector.setScheme("https");
        connector.setSecure(true);
        connector.setAllowTrace(true);
        val protocol = (AbstractHttp11JsseProtocol) connector.getProtocolHandler();
        protocol.setSSLEnabled(true);
        protocol.setSslProtocol("TLS");
        protocol.setClientAuth(webflow.getClientAuth());
        protocol.setKeystoreFile(serverProperties.getSsl().getKeyStore());
        protocol.setKeystorePass(serverProperties.getSsl().getKeyStorePassword());
        protocol.setTruststoreFile(serverProperties.getSsl().getTrustStore());
        protocol.setTruststorePass(serverProperties.getSsl().getTrustStorePassword());
        tomcat.addAdditionalTomcatConnectors(connector);
    }
}
Also used : lombok.val(lombok.val) Connector(org.apache.catalina.connector.Connector) AbstractHttp11JsseProtocol(org.apache.coyote.http11.AbstractHttp11JsseProtocol) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)

Example 44 with TomcatServletWebServerFactory

use of org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory in project spring-boot by spring-projects.

the class TomcatWebServerFactoryCustomizerTests method accessLogMaxDaysDefault.

@Test
void accessLogMaxDaysDefault() {
    bind("server.tomcat.accesslog.enabled=true");
    TomcatServletWebServerFactory factory = customizeAndGetFactory();
    assertThat(((AccessLogValve) factory.getEngineValves().iterator().next()).getMaxDays()).isEqualTo(this.serverProperties.getTomcat().getAccesslog().getMaxDays());
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) AccessLogValve(org.apache.catalina.valves.AccessLogValve) Test(org.junit.jupiter.api.Test)

Example 45 with TomcatServletWebServerFactory

use of org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory in project spring-boot by spring-projects.

the class TomcatWebServerFactoryCustomizerTests method accessLogConditionCanBeSpecified.

@Test
void accessLogConditionCanBeSpecified() {
    bind("server.tomcat.accesslog.enabled=true", "server.tomcat.accesslog.conditionIf=foo", "server.tomcat.accesslog.conditionUnless=bar");
    TomcatServletWebServerFactory factory = customizeAndGetFactory();
    assertThat(((AccessLogValve) factory.getEngineValves().iterator().next()).getConditionIf()).isEqualTo("foo");
    assertThat(((AccessLogValve) factory.getEngineValves().iterator().next()).getConditionUnless()).isEqualTo("bar");
    assertThat(((AccessLogValve) factory.getEngineValves().iterator().next()).getCondition()).describedAs("value of condition should equal conditionUnless - provided for backwards compatibility").isEqualTo("bar");
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) AccessLogValve(org.apache.catalina.valves.AccessLogValve) Test(org.junit.jupiter.api.Test)

Aggregations

TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)67 Test (org.junit.jupiter.api.Test)28 AccessLogValve (org.apache.catalina.valves.AccessLogValve)24 Test (org.junit.Test)18 HashMap (java.util.HashMap)13 Bean (org.springframework.context.annotation.Bean)10 Connector (org.apache.catalina.connector.Connector)6 WebApplicationContextRunner (org.springframework.boot.test.context.runner.WebApplicationContextRunner)6 TomcatWebServer (org.springframework.boot.web.embedded.tomcat.TomcatWebServer)6 Valve (org.apache.catalina.Valve)4 RemoteIpValve (org.apache.catalina.valves.RemoteIpValve)4 Context (org.apache.catalina.Context)3 TomcatContextCustomizer (org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer)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 ServletContext (jakarta.servlet.ServletContext)2 lombok.val (lombok.val)2 ErrorReportValve (org.apache.catalina.valves.ErrorReportValve)2 AbstractProtocol (org.apache.coyote.AbstractProtocol)2