use of org.springframework.boot.web.embedded.jetty.JettyWebServer in project spring-boot by spring-projects.
the class JettyWebServerFactoryCustomizerTests method threadPoolWithMaxQueueCapacityEqualToZeroCustomizesThreadPool.
@Test
void threadPoolWithMaxQueueCapacityEqualToZeroCustomizesThreadPool() {
bind("server.jetty.threads.max-queue-capacity=0", "server.jetty.threads.min=100", "server.jetty.threads.max=100", "server.jetty.threads.idle-timeout=6s");
JettyWebServer server = customizeAndGetServer();
QueuedThreadPool threadPool = (QueuedThreadPool) server.getServer().getThreadPool();
assertThat(threadPool.getMinThreads()).isEqualTo(100);
assertThat(threadPool.getMaxThreads()).isEqualTo(100);
assertThat(threadPool.getIdleTimeout()).isEqualTo(Duration.ofSeconds(6).toMillis());
}
use of org.springframework.boot.web.embedded.jetty.JettyWebServer in project spring-boot by spring-projects.
the class JettyWebServerFactoryCustomizerTests method customMaxHttpHeaderSizeIgnoredIfNegative.
@Test
void customMaxHttpHeaderSizeIgnoredIfNegative() {
bind("server.max-http-header-size=-1");
JettyWebServer server = customizeAndGetServer();
List<Integer> requestHeaderSizes = getRequestHeaderSizes(server);
assertThat(requestHeaderSizes).containsOnly(8192);
}
use of org.springframework.boot.web.embedded.jetty.JettyWebServer in project spring-boot by spring-projects.
the class ServerPropertiesTests method jettyMaxHttpFormPostSizeMatchesDefault.
@Test
void jettyMaxHttpFormPostSizeMatchesDefault() {
JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0);
JettyWebServer jetty = (JettyWebServer) jettyFactory.getWebServer((ServletContextInitializer) (servletContext) -> servletContext.addServlet("formPost", new HttpServlet() {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.getParameterMap();
}
}).addMapping("/form"));
jetty.start();
org.eclipse.jetty.server.Connector connector = jetty.getServer().getConnectors()[0];
final AtomicReference<Throwable> failure = new AtomicReference<>();
connector.addBean(new HttpChannel.Listener() {
@Override
public void onDispatchFailure(Request request, Throwable ex) {
failure.set(ex);
}
});
try {
RestTemplate template = new RestTemplate();
template.setErrorHandler(new ResponseErrorHandler() {
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return false;
}
@Override
public void handleError(ClientHttpResponse response) throws IOException {
}
});
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
StringBuilder data = new StringBuilder();
for (int i = 0; i < 250000; i++) {
data.append("a");
}
body.add("data", data.toString());
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(body, headers);
template.postForEntity(URI.create("http://localhost:" + jetty.getPort() + "/form"), entity, Void.class);
assertThat(failure.get()).isNotNull();
String message = failure.get().getCause().getMessage();
int defaultMaxPostSize = Integer.parseInt(message.substring(message.lastIndexOf(' ')).trim());
assertThat(this.properties.getJetty().getMaxHttpFormPostSize().toBytes()).isEqualTo(defaultMaxPostSize);
} finally {
jetty.stop();
}
}
use of org.springframework.boot.web.embedded.jetty.JettyWebServer in project joinfaces by joinfaces.
the class JettyAutoConfigurationIT method customize.
@Test
public void customize() {
JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
this.jettyAutoConfiguration.jsfJettyFactoryCustomizer().customize(factory);
Server server = ((JettyWebServer) factory.getWebServer()).getServer();
Handler[] childHandlersByClass = server.getChildHandlersByClass(WebAppContext.class);
WebAppContext webAppContext = (WebAppContext) childHandlersByClass[0];
assertThat(webAppContext.getBaseResource().getResource("testJetty.txt").exists()).isTrue();
}
use of org.springframework.boot.web.embedded.jetty.JettyWebServer in project spring-boot by spring-projects.
the class JettyWebServerFactoryCustomizerTests method accessLogCanBeCustomized.
@Test
void accessLogCanBeCustomized() throws IOException {
File logFile = File.createTempFile("jetty_log", ".log");
bind("server.jetty.accesslog.enabled=true", "server.jetty.accesslog.format=extended_ncsa", "server.jetty.accesslog.filename=" + logFile.getAbsolutePath().replace("\\", "\\\\"), "server.jetty.accesslog.file-date-format=yyyy-MM-dd", "server.jetty.accesslog.retention-period=42", "server.jetty.accesslog.append=true", "server.jetty.accesslog.ignore-paths=/a/path,/b/path");
JettyWebServer server = customizeAndGetServer();
CustomRequestLog requestLog = getRequestLog(server);
assertThat(requestLog.getFormatString()).isEqualTo(CustomRequestLog.EXTENDED_NCSA_FORMAT);
assertThat(requestLog.getIgnorePaths()).hasSize(2);
assertThat(requestLog.getIgnorePaths()).containsExactly("/a/path", "/b/path");
RequestLogWriter logWriter = getLogWriter(requestLog);
assertThat(logWriter.getFileName()).isEqualTo(logFile.getAbsolutePath());
assertThat(logWriter.getFilenameDateFormat()).isEqualTo("yyyy-MM-dd");
assertThat(logWriter.getRetainDays()).isEqualTo(42);
assertThat(logWriter.isAppend()).isTrue();
}
Aggregations