Search in sources :

Example 21 with UndertowEmbeddedServletContainerFactory

use of org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory in project ArTEMiS by ls1intum.

the class WebConfigurer method customize.

/**
 * Customize the Servlet engine: Mime types, the document root, the cache.
 */
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
    // IE issue, see https://github.com/jhipster/generator-jhipster/pull/711
    mappings.add("html", MediaType.TEXT_HTML_VALUE + ";charset=utf-8");
    // CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64
    mappings.add("json", MediaType.TEXT_HTML_VALUE + ";charset=utf-8");
    container.setMimeMappings(mappings);
    // When running in an IDE or with ./gradlew bootRun, set location of the static web assets.
    setLocationForStaticAssets(container);
    /*
         * Enable HTTP/2 for Undertow - https://twitter.com/ankinson/status/829256167700492288
         * HTTP/2 requires HTTPS, so HTTP requests will fallback to HTTP/1.1.
         * See the JHipsterProperties class and your application-*.yml configuration files
         * for more information.
         */
    if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) && container instanceof UndertowEmbeddedServletContainerFactory) {
        ((UndertowEmbeddedServletContainerFactory) container).addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true));
    }
}
Also used : UndertowEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory) MimeMappings(org.springframework.boot.context.embedded.MimeMappings)

Example 22 with UndertowEmbeddedServletContainerFactory

use of org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory in project ArTEMiS by ls1intum.

the class WebConfigurerTest method testUndertowHttp2Enabled.

@Test
public void testUndertowHttp2Enabled() {
    props.getHttp().setVersion(JHipsterProperties.Http.Version.V_2_0);
    UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory();
    webConfigurer.customize(container);
    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isTrue();
}
Also used : UndertowEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory) Builder(io.undertow.Undertow.Builder) OptionMap(org.xnio.OptionMap) Test(org.junit.Test)

Aggregations

UndertowEmbeddedServletContainerFactory (org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory)22 Builder (io.undertow.Undertow.Builder)16 Test (org.junit.Test)14 OptionMap (org.xnio.OptionMap)14 Bean (org.springframework.context.annotation.Bean)5 MimeMappings (org.springframework.boot.context.embedded.MimeMappings)3 UndertowBuilderCustomizer (org.springframework.boot.context.embedded.undertow.UndertowBuilderCustomizer)2 Undertow (io.undertow.Undertow)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 CertificateException (java.security.cert.CertificateException)1 AbstractEmbeddedServletContainerFactory (org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory)1 JettyEmbeddedServletContainerFactory (org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory)1 TomcatEmbeddedServletContainerFactory (org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory)1 UndertowDeploymentInfoCustomizer (org.springframework.boot.context.embedded.undertow.UndertowDeploymentInfoCustomizer)1