use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class TestABCase3 method data.
@Parameters
public static Collection<WebSocketFrame[]> data() {
List<WebSocketFrame[]> data = new ArrayList<>();
// @formatter:off
data.add(new WebSocketFrame[] { new PingFrame().setFin(false) });
data.add(new WebSocketFrame[] { new PingFrame().setRsv1(true) });
data.add(new WebSocketFrame[] { new PingFrame().setRsv2(true) });
data.add(new WebSocketFrame[] { new PingFrame().setRsv3(true) });
data.add(new WebSocketFrame[] { new PongFrame().setFin(false) });
data.add(new WebSocketFrame[] { new PingFrame().setRsv1(true) });
data.add(new WebSocketFrame[] { new PongFrame().setRsv2(true) });
data.add(new WebSocketFrame[] { new PongFrame().setRsv3(true) });
data.add(new WebSocketFrame[] { new CloseInfo().asFrame().setFin(false) });
data.add(new WebSocketFrame[] { new CloseInfo().asFrame().setRsv1(true) });
data.add(new WebSocketFrame[] { new CloseInfo().asFrame().setRsv2(true) });
data.add(new WebSocketFrame[] { new CloseInfo().asFrame().setRsv3(true) });
// @formatter:on
return data;
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class TestABCase7_3 method testCase7_3_1GenerateEmptyClose.
@Test
public void testCase7_3_1GenerateEmptyClose() {
CloseInfo close = new CloseInfo();
ByteBuffer actual = UnitGenerator.generate(close.asFrame());
ByteBuffer expected = ByteBuffer.allocate(5);
expected.put(new byte[] { (byte) 0x88, (byte) 0x00 });
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class MisbehavingClassTest method testAnnotatedRuntimeOnConnect.
@Test
public void testAnnotatedRuntimeOnConnect() throws Exception {
try (IBlockheadClient client = new BlockheadClient(server.getServerUri());
StacklessLogging scope = new StacklessLogging(AnnotatedRuntimeOnConnectSocket.class, WebSocketSession.class)) {
client.setProtocols("annotated-runtime-connect");
client.setTimeout(1, TimeUnit.SECONDS);
AnnotatedRuntimeOnConnectSocket socket = badSocketsServlet.annotatedRuntimeConnect;
socket.reset();
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
WebSocketFrame frame = frames.poll();
assertThat("frames[0].opcode", frame.getOpCode(), is(OpCode.CLOSE));
CloseInfo close = new CloseInfo(frame);
assertThat("Close Status Code", close.getStatusCode(), is(StatusCode.SERVER_ERROR));
// respond with close
client.write(close.asFrame());
// ensure server socket got close event
assertThat("Close Latch", socket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
assertThat("closeStatusCode", socket.closeStatusCode, is(StatusCode.SERVER_ERROR));
// Validate errors
assertThat("socket.onErrors", socket.errors.size(), is(1));
Throwable cause = socket.errors.pop();
assertThat("Error type", cause, instanceOf(RuntimeException.class));
}
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class WebSocketServletRFCTest method testTextNotUTF8.
@Test
public void testTextNotUTF8() throws Exception {
try (StacklessLogging stackless = new StacklessLogging(Parser.class);
BlockheadClient client = new BlockheadClient(server.getServerUri())) {
client.setProtocols("other");
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
byte[] buf = new byte[] { (byte) 0xC2, (byte) 0xC3 };
WebSocketFrame txt = new TextFrame().setPayload(ByteBuffer.wrap(buf));
txt.setMask(Hex.asByteArray("11223344"));
ByteBuffer bbHeader = generator.generateHeaderBytes(txt);
client.writeRaw(bbHeader);
client.writeRaw(txt.getPayload());
EventQueue<WebSocketFrame> frames = client.readFrames(1, 30, TimeUnit.SECONDS);
WebSocketFrame frame = frames.poll();
Assert.assertThat("frames[0].opcode", frame.getOpCode(), is(OpCode.CLOSE));
CloseInfo close = new CloseInfo(frame);
Assert.assertThat("Close Status Code", close.getStatusCode(), is(StatusCode.BAD_PAYLOAD));
}
}
use of org.eclipse.jetty.websocket.common.CloseInfo in project jetty.project by eclipse.
the class TestABCase9 method testCase9_1_5.
/**
* Echo 8MB text message (1 frame)
* @throws Exception on test failure
*/
@Test
@Stress("High I/O use")
public void testCase9_1_5() throws Exception {
byte[] utf = new byte[8 * MBYTE];
Arrays.fill(utf, (byte) 'y');
ByteBuffer buf = ByteBuffer.wrap(utf);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(buf));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new TextFrame().setPayload(clone(buf)));
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect, 16, TimeUnit.SECONDS);
}
}
Aggregations