Search in sources :

Example 71 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class ManyConnectionsCleanupTest method fastFail.

private void fastFail() throws Exception {
    try (IBlockheadClient client = new BlockheadClient(server.getServerUri())) {
        client.setProtocols("fastfail");
        client.setTimeout(1, TimeUnit.SECONDS);
        try (StacklessLogging scope = new StacklessLogging(WebSocketSession.class)) {
            client.connect();
            client.sendStandardRequest();
            client.expectUpgradeResponse();
            // client.readFrames(1,2,TimeUnit.SECONDS);
            CloseInfo close = new CloseInfo(StatusCode.NORMAL, "Normal");
            // respond with close
            client.write(close.asFrame());
            // ensure server socket got close event
            assertThat("Fast Fail Latch", closeSocket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
            assertThat("Fast Fail.statusCode", closeSocket.closeStatusCode, is(StatusCode.SERVER_ERROR));
            assertThat("Fast Fail.errors", closeSocket.errors.size(), is(1));
        }
    }
}
Also used : IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) IBlockheadClient(org.eclipse.jetty.websocket.common.test.IBlockheadClient) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Example 72 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class TestABCase2 method testCase2_5.

/**
     * Ping with 126 byte binary payload
     * @throws Exception on test failure
     */
@Test
public void testCase2_5() throws Exception {
    try (StacklessLogging scope = new StacklessLogging(Parser.class)) {
        // intentionally too big
        byte[] payload = new byte[126];
        Arrays.fill(payload, (byte) '5');
        ByteBuffer buf = ByteBuffer.wrap(payload);
        List<WebSocketFrame> send = new ArrayList<>();
        // trick websocket frame into making extra large payload for ping
        send.add(new BadFrame(OpCode.PING).setPayload(buf));
        send.add(new CloseInfo(StatusCode.NORMAL, "Test 2.5").asFrame());
        List<WebSocketFrame> expect = new ArrayList<>();
        expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
        try (Fuzzer fuzzer = new Fuzzer(this)) {
            fuzzer.connect();
            fuzzer.setSendMode(Fuzzer.SendMode.BULK);
            fuzzer.send(send);
            fuzzer.expect(expect);
        }
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) ByteBuffer(java.nio.ByteBuffer) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 73 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class HttpClientTest method testEarlyEOF.

@Test
public void testEarlyEOF() throws Exception {
    start(new AbstractHandler() {

        @Override
        public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            // Promise some content, then flush the headers, then fail to send the content.
            response.setContentLength(16);
            response.flushBuffer();
            throw new NullPointerException("Explicitly thrown by test");
        }
    });
    try (StacklessLogging stackless = new StacklessLogging(org.eclipse.jetty.server.HttpChannel.class)) {
        client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).timeout(60, TimeUnit.SECONDS).send();
        Assert.fail();
    } catch (ExecutionException x) {
    // Expected.
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 74 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class AsyncServletTest method testAsyncNotSupportedAsync.

@Test
public void testAsyncNotSupportedAsync() throws Exception {
    try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) {
        _expectedCode = "500 ";
        String response = process("noasync", "start=200", null);
        Assert.assertThat(response, Matchers.startsWith("HTTP/1.1 500 "));
        assertThat(__history, contains("REQUEST /ctx/noasync/info", "initial", "ERROR /ctx/error/custom", "!initial"));
        assertContains("500", response);
        assertContains("!asyncSupported", response);
        assertContains("AsyncServletTest$AsyncServlet", response);
    }
}
Also used : StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Test(org.junit.Test)

Example 75 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class PostServletTest method testBadSplitPost.

@Test
public void testBadSplitPost() throws Exception {
    StringBuilder req = new StringBuilder();
    req.append("POST /post HTTP/1.1\r\n");
    req.append("Host: localhost\r\n");
    req.append("Connection: close\r\n");
    req.append("Transfer-Encoding: chunked\r\n");
    req.append("\r\n");
    req.append("6\r\n");
    req.append("Hello ");
    req.append("\r\n");
    try (StacklessLogging scope = new StacklessLogging(ServletHandler.class)) {
        LocalConnector.LocalEndPoint endp = connector.executeRequest(req.toString());
        req.setLength(0);
        while (!posted.get()) Thread.sleep(100);
        Thread.sleep(100);
        req.append("x\r\n");
        req.append("World\n");
        req.append("\r\n");
        req.append("0\r\n");
        req.append("\r\n");
        endp.addInput(req.toString());
        endp.waitUntilClosedOrIdleFor(1, TimeUnit.SECONDS);
        String resp = endp.takeOutputString();
        assertThat("resp", resp, containsString("HTTP/1.1 200 "));
        // aborted
        assertThat("resp", resp, not(containsString("\r\n0\r\n")));
    }
    assertTrue(complete.await(5, TimeUnit.SECONDS));
    assertThat(ex0.get(), not(nullValue()));
    assertThat(ex1.get(), not(nullValue()));
}
Also used : LocalConnector(org.eclipse.jetty.server.LocalConnector) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) 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