Search in sources :

Example 16 with ServletRegistrationBean

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

the class H2ConsoleAutoConfiguration method h2Console.

@Bean
public ServletRegistrationBean<WebServlet> h2Console() {
    String path = this.properties.getPath();
    String urlMapping = (path.endsWith("/") ? path + "*" : path + "/*");
    ServletRegistrationBean<WebServlet> registration = new ServletRegistrationBean<>(new WebServlet(), urlMapping);
    H2ConsoleProperties.Settings settings = this.properties.getSettings();
    if (settings.isTrace()) {
        registration.addInitParameter("trace", "");
    }
    if (settings.isWebAllowOthers()) {
        registration.addInitParameter("webAllowOthers", "");
    }
    return registration;
}
Also used : WebServlet(org.h2.server.web.WebServlet) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 17 with ServletRegistrationBean

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

the class SampleAtmosphereApplication method atmosphereServlet.

@Bean
public ServletRegistrationBean<AtmosphereServlet> atmosphereServlet() {
    // Dispatcher servlet is mapped to '/home' to allow the AtmosphereServlet
    // to be mapped to '/chat'
    ServletRegistrationBean<AtmosphereServlet> registration = new ServletRegistrationBean<>(new AtmosphereServlet(), "/chat/*");
    registration.addInitParameter("org.atmosphere.cpr.packages", "sample");
    registration.addInitParameter("org.atmosphere.interceptor.HeartbeatInterceptor" + ".clientHeartbeatFrequencyInSeconds", "10");
    registration.setLoadOnStartup(0);
    // Need to occur before the EmbeddedAtmosphereInitializer
    registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
    return registration;
}
Also used : AtmosphereServlet(org.atmosphere.cpr.AtmosphereServlet) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 18 with ServletRegistrationBean

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

the class AbstractServletWebServerFactoryTests method testRestrictedSSLProtocolsAndCipherSuites.

protected void testRestrictedSSLProtocolsAndCipherSuites(String[] protocols, String[] ciphers) throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks", null, protocols, ciphers));
    this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello"));
    this.webServer.start();
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
    HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    assertThat(getResponse(getLocalUrl("https", "/hello"), requestFactory)).contains("scheme=https");
}
Also used : ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) HttpClient(org.apache.http.client.HttpClient) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) TrustSelfSignedStrategy(org.apache.http.conn.ssl.TrustSelfSignedStrategy)

Example 19 with ServletRegistrationBean

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

the class AbstractServletWebServerFactoryTests method sslKeyAlias.

@Test
public void sslKeyAlias() throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    factory.setSsl(getSsl(null, "password", "test-alias", "src/test/resources/test.jks"));
    this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello"));
    this.webServer.start();
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new SerialNumberValidatingTrustSelfSignedStrategy("77e7c302")).build());
    HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    assertThat(getResponse(getLocalUrl("https", "/hello"), requestFactory)).contains("scheme=https");
}
Also used : ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) HttpClient(org.apache.http.client.HttpClient) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) Test(org.junit.Test)

Example 20 with ServletRegistrationBean

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

the class AbstractServletWebServerFactoryTests method sslGetScheme.

@Test
public void sslGetScheme() throws Exception {
    // gh-2232
    AbstractServletWebServerFactory factory = getFactory();
    factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks"));
    this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello"));
    this.webServer.start();
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
    HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    assertThat(getResponse(getLocalUrl("https", "/hello"), requestFactory)).contains("scheme=https");
}
Also used : ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) HttpClient(org.apache.http.client.HttpClient) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) TrustSelfSignedStrategy(org.apache.http.conn.ssl.TrustSelfSignedStrategy) Test(org.junit.Test)

Aggregations

ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)25 Bean (org.springframework.context.annotation.Bean)14 Test (org.junit.Test)8 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)7 HttpClient (org.apache.http.client.HttpClient)6 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)6 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)6 TrustSelfSignedStrategy (org.apache.http.conn.ssl.TrustSelfSignedStrategy)5 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)4 CamelHttpTransportServlet (org.apache.camel.component.servlet.CamelHttpTransportServlet)3 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)3 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)3 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 HttpServlet (javax.servlet.http.HttpServlet)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Compression (org.springframework.boot.web.server.Compression)2 AbstractServletWebServerFactory (org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory)2 ExampleServlet (org.springframework.boot.web.servlet.server.ExampleServlet)2