Search in sources :

Example 1 with ExampleServlet

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

the class UndertowServletWebServerFactoryTests method errorPage404.

@Test
public 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");
}
Also used : ErrorPage(org.springframework.boot.web.server.ErrorPage) AbstractServletWebServerFactory(org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) ExampleServlet(org.springframework.boot.web.servlet.server.ExampleServlet) Test(org.junit.Test)

Example 2 with ExampleServlet

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

the class SkipSslVerificationHttpRequestFactoryTests method getHttpsUrl.

private String getHttpsUrl() {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0);
    factory.setSsl(getSsl("password", "classpath:test.jks"));
    WebServer webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(), "/hello"));
    webServer.start();
    return "https://localhost:" + webServer.getPort() + "/hello";
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) WebServer(org.springframework.boot.web.server.WebServer) ExampleServlet(org.springframework.boot.web.servlet.server.ExampleServlet)

Example 3 with ExampleServlet

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

the class UndertowServletWebServerFactoryTests method testAccessLog.

private void testAccessLog(String prefix, String suffix, String expectedFile) throws IOException, URISyntaxException, InterruptedException {
    UndertowServletWebServerFactory factory = getFactory();
    factory.setAccessLogEnabled(true);
    factory.setAccessLogPrefix(prefix);
    factory.setAccessLogSuffix(suffix);
    File accessLogDirectory = this.temporaryFolder.getRoot();
    factory.setAccessLogDirectory(accessLogDirectory);
    assertThat(accessLogDirectory.listFiles()).isEmpty();
    this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(), "/hello"));
    this.webServer.start();
    assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
    File accessLog = new File(accessLogDirectory, expectedFile);
    awaitFile(accessLog);
    assertThat(accessLogDirectory.listFiles()).contains(accessLog);
}
Also used : ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) File(java.io.File) ExampleServlet(org.springframework.boot.web.servlet.server.ExampleServlet)

Aggregations

ExampleServlet (org.springframework.boot.web.servlet.server.ExampleServlet)3 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)2 File (java.io.File)1 Test (org.junit.Test)1 TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)1 ErrorPage (org.springframework.boot.web.server.ErrorPage)1 WebServer (org.springframework.boot.web.server.WebServer)1 AbstractServletWebServerFactory (org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory)1