use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class FragmentExtensionTest method testFragmentExtension.
@Test
public void testFragmentExtension() throws Exception {
int fragSize = 4;
BlockheadClient client = new BlockheadClient(server.getServerUri());
client.clearExtensions();
client.addExtensions("fragment;maxLength=" + fragSize);
client.setProtocols("onConnect");
try {
// Make sure the read times out if there are problems with the implementation
client.setTimeout(1, TimeUnit.SECONDS);
client.connect();
client.sendStandardRequest();
HttpResponse resp = client.expectUpgradeResponse();
Assert.assertThat("Response", resp.getExtensionsHeader(), containsString("fragment"));
String msg = "Sent as a long message that should be split";
client.write(new TextFrame().setPayload(msg));
String[] parts = split(msg, fragSize);
EventQueue<WebSocketFrame> frames = client.readFrames(parts.length, 1000, TimeUnit.MILLISECONDS);
for (int i = 0; i < parts.length; i++) {
WebSocketFrame frame = frames.poll();
Assert.assertThat("text[" + i + "].payload", frame.getPayloadAsUTF8(), is(parts[i]));
}
} finally {
client.close();
}
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class IdentityExtensionTest method testIdentityExtension.
@Test
public void testIdentityExtension() throws Exception {
BlockheadClient client = new BlockheadClient(server.getServerUri());
client.clearExtensions();
client.addExtensions("identity;param=0");
client.addExtensions("identity;param=1, identity ; param = '2' ; other = ' some = value '");
client.setProtocols("onConnect");
try {
// Make sure the read times out if there are problems with the implementation
client.setTimeout(1, TimeUnit.SECONDS);
client.connect();
client.sendStandardRequest();
HttpResponse resp = client.expectUpgradeResponse();
Assert.assertThat("Response", resp.getExtensionsHeader(), containsString("identity"));
client.write(new TextFrame().setPayload("Hello"));
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1000, TimeUnit.MILLISECONDS);
WebSocketFrame frame = frames.poll();
Assert.assertThat("TEXT.payload", frame.getPayloadAsUTF8(), is("Hello"));
} finally {
client.close();
}
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class TestABCase1 method testCase1_1_6.
/**
* Echo 65535 byte TEXT message (uses medium 2 byte payload length)
* @throws Exception on test failure
*/
@Test
public void testCase1_1_6() throws Exception {
byte[] payload = new byte[65535];
Arrays.fill(payload, (byte) '*');
ByteBuffer buf = ByteBuffer.wrap(payload);
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(SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class TestABCase1 method testCase1_1_3.
/**
* Echo 126 byte TEXT message (uses medium 2 byte payload length)
* @throws Exception on test failure
*/
@Test
public void testCase1_1_3() throws Exception {
byte[] payload = new byte[126];
Arrays.fill(payload, (byte) '*');
ByteBuffer buf = ByteBuffer.wrap(payload);
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(SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class TestABCase1 method testCase1_1_2.
/**
* Echo 125 byte TEXT message (uses small 7-bit payload length)
* @throws Exception on test failure
*/
@Test
public void testCase1_1_2() throws Exception {
byte[] payload = new byte[125];
Arrays.fill(payload, (byte) '*');
ByteBuffer buf = ByteBuffer.wrap(payload);
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(SendMode.BULK);
fuzzer.send(send);
fuzzer.expect(expect);
}
}
Aggregations