Search in sources :

Example 1 with AbstractServletWebServerFactory

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

the class JettyServletWebServerFactoryTests method setUpFactoryForCompression.

@Override
@SuppressWarnings("serial")
protected // Workaround for Jetty issue - https://bugs.eclipse.org/bugs/show_bug.cgi?id=470646
String setUpFactoryForCompression(final int contentSize, String[] mimeTypes, String[] excludedUserAgents) throws Exception {
    char[] chars = new char[contentSize];
    Arrays.fill(chars, 'F');
    final String testContent = new String(chars);
    AbstractServletWebServerFactory factory = getFactory();
    Compression compression = new Compression();
    compression.setEnabled(true);
    if (mimeTypes != null) {
        compression.setMimeTypes(mimeTypes);
    }
    if (excludedUserAgents != null) {
        compression.setExcludedUserAgents(excludedUserAgents);
    }
    factory.setCompression(compression);
    this.webServer = factory.getWebServer(new ServletRegistrationBean<HttpServlet>(new HttpServlet() {

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.setContentLength(contentSize);
            resp.setHeader(HttpHeaders.CONTENT_TYPE, "text/plain");
            resp.getWriter().print(testContent);
        }
    }, "/test.txt"));
    this.webServer.start();
    return testContent;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Compression(org.springframework.boot.web.server.Compression) AbstractServletWebServerFactory(org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException)

Example 2 with AbstractServletWebServerFactory

use of org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory 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)

Aggregations

ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)2 AbstractServletWebServerFactory (org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Test (org.junit.Test)1 Compression (org.springframework.boot.web.server.Compression)1 ErrorPage (org.springframework.boot.web.server.ErrorPage)1 ExampleServlet (org.springframework.boot.web.servlet.server.ExampleServlet)1