use of org.springframework.boot.testsupport.web.servlet.ExampleServlet in project spring-boot by spring-projects.
the class UndertowServletWebServerFactoryTests method errorPage404.
@Test
void errorPage404() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/hello"));
this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(), "/hello"));
this.webServer.start();
assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
assertThat(getResponse(getLocalUrl("/not-found"))).isEqualTo("Hello World");
}
use of org.springframework.boot.testsupport.web.servlet.ExampleServlet 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/restricted.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 = this.httpClientBuilder.get().setSSLSocketFactory(socketFactory).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
assertThat(getResponse(getLocalUrl("https", "/hello"), requestFactory)).contains("scheme=https");
}
use of org.springframework.boot.testsupport.web.servlet.ExampleServlet in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method sslGetScheme.
@Test
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");
}
use of org.springframework.boot.testsupport.web.servlet.ExampleServlet in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method sessionServletRegistration.
protected final ServletContextInitializer sessionServletRegistration() {
ServletRegistrationBean<ExampleServlet> bean = new ServletRegistrationBean<>(new ExampleServlet() {
@Override
public void service(ServletRequest request, ServletResponse response) throws IOException {
HttpSession session = ((HttpServletRequest) request).getSession(true);
long value = System.currentTimeMillis();
Object existing = session.getAttribute("boot");
session.setAttribute("boot", value);
PrintWriter writer = response.getWriter();
writer.append(String.valueOf(existing)).append(":").append(String.valueOf(value));
}
}, "/session");
bean.setName("session");
return bean;
}
use of org.springframework.boot.testsupport.web.servlet.ExampleServlet in project spring-boot by spring-projects.
the class AbstractServletWebServerFactoryTests method sslWithInvalidAliasFailsDuringStartup.
@Test
void sslWithInvalidAliasFailsDuringStartup() {
AbstractServletWebServerFactory factory = getFactory();
Ssl ssl = getSsl(null, "password", "test-alias-404", "src/test/resources/test.jks");
factory.setSsl(ssl);
ServletRegistrationBean<ExampleServlet> registration = new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello");
ThrowingCallable call = () -> factory.getWebServer(registration).start();
assertThatSslWithInvalidAliasCallFails(call);
}
Aggregations