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;
}
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");
}
Aggregations