use of org.springframework.boot.web.servlet.ServletRegistrationBean in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method serverHeaderIsDisabledByDefaultWhenUsingSsl.
@Test
public void serverHeaderIsDisabledByDefaultWhenUsingSsl() throws Exception {
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();
ClientHttpResponse response = getClientResponse(getLocalUrl("https", "/hello"), HttpMethod.GET, new HttpComponentsClientHttpRequestFactory(httpClient));
assertThat(response.getHeaders().get("Server")).isNullOrEmpty();
}
use of org.springframework.boot.web.servlet.ServletRegistrationBean in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method compressionWithoutContentSizeHeader.
@Test
public void compressionWithoutContentSizeHeader() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
Compression compression = new Compression();
compression.setEnabled(true);
factory.setCompression(compression);
this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(false, true), "/hello"));
this.webServer.start();
TestGzipInputStreamFactory inputStreamFactory = new TestGzipInputStreamFactory();
Map<String, InputStreamFactory> contentDecoderMap = Collections.singletonMap("gzip", (InputStreamFactory) inputStreamFactory);
getResponse(getLocalUrl("/hello"), new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create().setContentDecoderRegistry(contentDecoderMap).build()));
assertThat(inputStreamFactory.wasCompressionUsed()).isTrue();
}
use of org.springframework.boot.web.servlet.ServletRegistrationBean in project spring-boot by spring-projects.
the class JerseyAutoConfiguration method jerseyServletRegistration.
@Bean
@ConditionalOnMissingBean(name = "jerseyServletRegistration")
@ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "servlet", matchIfMissing = true)
public ServletRegistrationBean<ServletContainer> jerseyServletRegistration() {
ServletRegistrationBean<ServletContainer> registration = new ServletRegistrationBean<>(new ServletContainer(this.config), this.path);
addInitParameters(registration);
registration.setName(getServletRegistrationName());
registration.setLoadOnStartup(this.jersey.getServlet().getLoadOnStartup());
return registration;
}
use of org.springframework.boot.web.servlet.ServletRegistrationBean in project spring-boot by spring-projects.
the class WebServicesAutoConfiguration method messageDispatcherServlet.
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
String path = this.properties.getPath();
String urlMapping = (path.endsWith("/") ? path + "*" : path + "/*");
ServletRegistrationBean<MessageDispatcherServlet> registration = new ServletRegistrationBean<>(servlet, urlMapping);
WebServicesProperties.Servlet servletProperties = this.properties.getServlet();
registration.setLoadOnStartup(servletProperties.getLoadOnStartup());
for (Map.Entry<String, String> entry : servletProperties.getInit().entrySet()) {
registration.addInitParameter(entry.getKey(), entry.getValue());
}
return registration;
}
use of org.springframework.boot.web.servlet.ServletRegistrationBean in project java-chassis by ServiceComb.
the class CseEmbeddedServlet method restServletRegistration.
@Bean
public ServletRegistrationBean restServletRegistration() {
String name = env.getProperty("cse.servlet.name");
name = name == null ? DEFAULT_SERVLET_NAME : name;
String url = env.getProperty("cse.servlet.url");
url = url == null ? DEFAULT_URL : url;
ServletRegistrationBean registrationBean = new ServletRegistrationBean(new RestServlet(), url);
registrationBean.setName(name);
return registrationBean;
}
Aggregations