use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.
the class ServerTimeoutsTest method testBlockingTimeoutLargerThanIdleTimeoutBlockingReadIdleTimeoutFires.
@Test
public void testBlockingTimeoutLargerThanIdleTimeoutBlockingReadIdleTimeoutFires() throws Exception {
long idleTimeout = 2500;
long blockingTimeout = 3 * idleTimeout;
httpConfig.setBlockingTimeout(blockingTimeout);
CountDownLatch handlerLatch = new CountDownLatch(1);
start(new BlockingReadHandler(handlerLatch));
setServerIdleTimeout(idleTimeout);
try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) {
DeferredContentProvider contentProvider = new DeferredContentProvider(ByteBuffer.allocate(1));
CountDownLatch resultLatch = new CountDownLatch(1);
client.POST(newURI()).content(contentProvider).send(result -> {
if (result.getResponse().getStatus() == HttpStatus.INTERNAL_SERVER_ERROR_500)
resultLatch.countDown();
});
// Blocking read should timeout.
Assert.assertTrue(handlerLatch.await(2 * idleTimeout, TimeUnit.MILLISECONDS));
// Complete the request.
contentProvider.close();
Assert.assertTrue(resultLatch.await(5, TimeUnit.SECONDS));
}
}
use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.
the class HTTP2ServerTest method testNonISOHeader.
@Test
public void testNonISOHeader() throws Exception {
try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) {
startServer(new HttpServlet() {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Invalid header name, the connection must be closed.
response.setHeader("Euro_(€)", "42");
}
});
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
generator.control(lease, new PrefaceFrame());
generator.control(lease, new SettingsFrame(new HashMap<>(), false));
MetaData.Request metaData = newRequest("GET", new HttpFields());
generator.control(lease, new HeadersFrame(1, metaData, null, true));
try (Socket client = new Socket("localhost", connector.getLocalPort())) {
OutputStream output = client.getOutputStream();
for (ByteBuffer buffer : lease.getByteBuffers()) output.write(BufferUtil.toArray(buffer));
output.flush();
Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter(), 4096, 8192);
boolean closed = parseResponse(client, parser);
Assert.assertTrue(closed);
}
}
}
use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.
the class HttpConnectionTest method testOversizedResponse.
@Test
public void testOversizedResponse() throws Exception {
String str = "thisisastringthatshouldreachover1kbytes-";
for (int i = 0; i < 500; i++) str += "xxxxxxxxxxxx";
final String longstr = str;
final CountDownLatch checkError = new CountDownLatch(1);
String response = null;
server.stop();
server.setHandler(new AbstractHandler.ErrorDispatchHandler() {
@Override
protected void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
response.setHeader(HttpHeader.CONTENT_TYPE.toString(), MimeTypes.Type.TEXT_HTML.toString());
response.setHeader("LongStr", longstr);
PrintWriter writer = response.getWriter();
writer.write("<html><h1>FOO</h1></html>");
writer.flush();
if (writer.checkError())
checkError.countDown();
response.flushBuffer();
}
});
server.start();
Logger logger = Log.getLogger(HttpChannel.class);
try (StacklessLogging stackless = new StacklessLogging(logger)) {
logger.info("Expect IOException: Response header too large...");
response = connector.getResponse("GET / HTTP/1.1\r\n" + "Host: localhost\r\n" + "\r\n");
checkContains(response, 0, "HTTP/1.1 500");
assertTrue(checkError.await(1, TimeUnit.SECONDS));
} catch (Exception e) {
if (response != null)
System.err.println(response);
throw e;
}
}
use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.
the class ConnectorTimeoutTest method testBlockingTimeoutWrite.
@Test(timeout = 60000)
// TODO make more stable
@Ignore
public void testBlockingTimeoutWrite() throws Exception {
_httpConfiguration.setBlockingTimeout(750L);
configureServer(new HugeResponseHandler());
Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
client.setSoTimeout(10000);
Assert.assertFalse(client.isClosed());
OutputStream os = client.getOutputStream();
BufferedReader is = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.ISO_8859_1), 2048);
os.write(("GET / HTTP/1.0\r\n" + "host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" + "connection: keep-alive\r\n" + "Connection: close\r\n" + "\r\n").getBytes("utf-8"));
os.flush();
// read the header
String line = is.readLine();
Assert.assertThat(line, Matchers.startsWith("HTTP/1.1 200 OK"));
while (line.length() != 0) line = is.readLine();
long start = System.currentTimeMillis();
try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class, AbstractConnection.class)) {
for (int i = 0; i < (128 * 1024); i++) {
if (i % 1028 == 0) {
Thread.sleep(20);
// System.err.println("read "+System.currentTimeMillis());
}
line = is.readLine();
if (line == null)
break;
}
} catch (Throwable e) {
}
long end = System.currentTimeMillis();
long duration = end - start;
Assert.assertThat(duration, Matchers.lessThan(20L * 128L));
}
use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.
the class HttpConnectionTest method testUnconsumedException.
@Test
public void testUnconsumedException() throws Exception {
int offset = 0;
String requests = "GET /R1?read=1&ISE=true HTTP/1.1\r\n" + "Host: localhost\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "\r\n" + "5;\r\n" + "12345\r\n" + "5;\r\n" + "67890\r\n" + "0;\r\n" + "\r\n" + "GET /R2 HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "Content-Length: 10\r\n" + "\r\n" + "abcdefghij\r\n";
Logger logger = Log.getLogger(HttpChannel.class);
try (StacklessLogging stackless = new StacklessLogging(logger)) {
logger.info("EXPECTING: java.lang.IllegalStateException...");
String response = connector.getResponse(requests);
offset = checkContains(response, offset, "HTTP/1.1 500");
offset = checkContains(response, offset, "Connection: close");
checkNotContained(response, offset, "HTTP/1.1 200");
}
}
Aggregations