Search in sources :

Example 86 with StacklessLogging

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));
    }
}
Also used : DeferredContentProvider(org.eclipse.jetty.client.util.DeferredContentProvider) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 87 with StacklessLogging

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);
        }
    }
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) HashMap(java.util.HashMap) HttpServlet(javax.servlet.http.HttpServlet) OutputStream(java.io.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.http2.parser.Parser) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) PrefaceFrame(org.eclipse.jetty.http2.frames.PrefaceFrame) SettingsFrame(org.eclipse.jetty.http2.frames.SettingsFrame) MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Socket(java.net.Socket) Test(org.junit.Test)

Example 88 with StacklessLogging

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;
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Logger(org.eclipse.jetty.util.log.Logger) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 89 with StacklessLogging

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));
}
Also used : InputStreamReader(java.io.InputStreamReader) OutputStream(java.io.OutputStream) BufferedReader(java.io.BufferedReader) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Socket(java.net.Socket) EndPoint(org.eclipse.jetty.io.EndPoint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 90 with StacklessLogging

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");
    }
}
Also used : StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Logger(org.eclipse.jetty.util.log.Logger) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Aggregations

StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)143 Test (org.junit.Test)134 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)55 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)51 ArrayList (java.util.ArrayList)46 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)45 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)35 ByteBuffer (java.nio.ByteBuffer)29 IOException (java.io.IOException)26 HttpServletRequest (javax.servlet.http.HttpServletRequest)24 HttpServletResponse (javax.servlet.http.HttpServletResponse)22 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)21 ServletException (javax.servlet.ServletException)20 CountDownLatch (java.util.concurrent.CountDownLatch)17 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)17 Matchers.containsString (org.hamcrest.Matchers.containsString)17 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)14 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)13 OutputStream (java.io.OutputStream)12 Socket (java.net.Socket)12