Search in sources :

Example 31 with StacklessLogging

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

the class ClientCloseTest method testProtocolException.

@Test
public void testProtocolException() throws Exception {
    // Set client timeout
    final int timeout = 1000;
    client.setMaxIdleTimeout(timeout);
    // Client connects
    CloseTrackingSocket clientSocket = new CloseTrackingSocket();
    Future<Session> clientConnectFuture = client.connect(clientSocket, server.getWsUri());
    // Server accepts connect
    IBlockheadServerConnection serverConn = server.accept();
    serverConn.upgrade();
    // client confirms connection via echo
    confirmConnection(clientSocket, clientConnectFuture, serverConn);
    // client should not have received close message (yet)
    clientSocket.assertNoCloseEvent();
    // server sends bad close frame (too big of a reason message)
    byte[] msg = new byte[400];
    Arrays.fill(msg, (byte) 'x');
    ByteBuffer bad = ByteBuffer.allocate(500);
    RawFrameBuilder.putOpFin(bad, OpCode.CLOSE, true);
    RawFrameBuilder.putLength(bad, msg.length + 2, false);
    bad.putShort((short) StatusCode.NORMAL);
    bad.put(msg);
    BufferUtil.flipToFlush(bad, 0);
    try (StacklessLogging quiet = new StacklessLogging(Parser.class)) {
        serverConn.write(bad);
        // client should have noticed the error
        assertThat("OnError Latch", clientSocket.errorLatch.await(2, TimeUnit.SECONDS), is(true));
        assertThat("OnError", clientSocket.error.get(), instanceOf(ProtocolException.class));
        assertThat("OnError", clientSocket.error.get().getMessage(), containsString("Invalid control frame"));
        // client parse invalid frame, notifies server of close (protocol error)
        confirmServerReceivedCloseFrame(serverConn, StatusCode.PROTOCOL, allOf(containsString("Invalid control frame"), containsString("length")));
    }
    // server disconnects
    serverConn.disconnect();
    // client triggers close event on client ws-endpoint
    clientSocket.assertReceivedCloseEvent(timeout, is(StatusCode.PROTOCOL), allOf(containsString("Invalid control frame"), containsString("length")));
}
Also used : ProtocolException(org.eclipse.jetty.websocket.api.ProtocolException) IBlockheadServerConnection(org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) ByteBuffer(java.nio.ByteBuffer) EndPoint(org.eclipse.jetty.io.EndPoint) SocketChannelEndPoint(org.eclipse.jetty.io.SocketChannelEndPoint) Session(org.eclipse.jetty.websocket.api.Session) WebSocketSession(org.eclipse.jetty.websocket.common.WebSocketSession) Test(org.junit.Test)

Example 32 with StacklessLogging

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

the class IdleTimeoutTest method testAnnotated.

@Test
public void testAnnotated() throws Exception {
    try (StacklessLogging stackless = new StacklessLogging(JsrEvents.class)) {
        URI uri = server.getServerBaseURI();
        assertConnectionTimeout(uri.resolve("idle-onopen-socket"));
    }
}
Also used : StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) URI(java.net.URI) Test(org.junit.Test)

Example 33 with StacklessLogging

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

the class TestABCase5 method testCase5_13.

/**
     * Send continuation+!fin, then text+fin (framewise)
     * @throws Exception on test failure
     */
@Test
public void testCase5_13() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new ContinuationFrame().setPayload("sorry").setFin(false));
    send.add(new TextFrame().setPayload("hello, world"));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this);
        StacklessLogging supress = new StacklessLogging(Parser.class)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME);
        fuzzer.sendAndIgnoreBrokenPipe(send);
        fuzzer.expect(expect);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 34 with StacklessLogging

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

the class TestABCase5 method testCase5_14.

/**
     * Send continuation+!fin, then text+fin (slowly)
     * @throws Exception on test failure
     */
@Test
public void testCase5_14() throws Exception {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new ContinuationFrame().setPayload("sorry").setFin(false));
    send.add(new TextFrame().setPayload("hello, world"));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect = new ArrayList<>();
    expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this);
        StacklessLogging supress = new StacklessLogging(Parser.class)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.SLOW);
        fuzzer.setSlowSendSegmentSize(1);
        fuzzer.sendAndIgnoreBrokenPipe(send);
        fuzzer.expect(expect);
    }
}
Also used : Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) Test(org.junit.Test)

Example 35 with StacklessLogging

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

the class TestABCase5 method testCase5_20.

/**
     * send text message fragmented in 5 frames, with 2 pings and wait between. (framewise)
     * @throws Exception on test failure
     */
@Test
public void testCase5_20() throws Exception {
    List<WebSocketFrame> send1 = new ArrayList<>();
    send1.add(new TextFrame().setPayload("f1").setFin(false));
    send1.add(new ContinuationFrame().setPayload(",f2").setFin(false));
    send1.add(new PingFrame().setPayload("pong-1"));
    List<WebSocketFrame> send2 = new ArrayList<>();
    send2.add(new ContinuationFrame().setPayload(",f3").setFin(false));
    send2.add(new ContinuationFrame().setPayload(",f4").setFin(false));
    send2.add(new PingFrame().setPayload("pong-2"));
    send2.add(new ContinuationFrame().setPayload(",f5").setFin(true));
    send2.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    List<WebSocketFrame> expect1 = new ArrayList<>();
    expect1.add(new PongFrame().setPayload("pong-1"));
    List<WebSocketFrame> expect2 = new ArrayList<>();
    expect2.add(new PongFrame().setPayload("pong-2"));
    expect2.add(new TextFrame().setPayload("f1,f2,f3,f4,f5"));
    expect2.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    try (Fuzzer fuzzer = new Fuzzer(this);
        StacklessLogging supress = new StacklessLogging(Parser.class)) {
        fuzzer.connect();
        fuzzer.setSendMode(Fuzzer.SendMode.PER_FRAME);
        fuzzer.send(send1);
        fuzzer.expect(expect1);
        TimeUnit.SECONDS.sleep(1);
        fuzzer.send(send2);
        fuzzer.expect(expect2);
    }
}
Also used : PongFrame(org.eclipse.jetty.websocket.common.frames.PongFrame) Fuzzer(org.eclipse.jetty.websocket.common.test.Fuzzer) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo) 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