use of org.eclipse.jetty.websocket.common.WebSocketFrame 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.WebSocketFrame 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.WebSocketFrame in project jetty.project by eclipse.
the class IncomingFramesCapture method incomingFrame.
@Override
public void incomingFrame(Frame frame) {
WebSocketFrame copy = WebSocketFrame.copy(frame);
// TODO: might need to make this optional (depending on use by client vs server tests)
// Assert.assertThat("frame.masking must be set",frame.isMasked(),is(true));
frames.add(copy);
}
use of org.eclipse.jetty.websocket.common.WebSocketFrame in project jetty.project by eclipse.
the class BlockheadClient method onConnectionStateChange.
@Override
public void onConnectionStateChange(ConnectionState state) {
LOG.debug("CLIENT onConnectionStateChange() - {}", state);
switch(state) {
case CLOSED:
// this.disconnect();
break;
case CLOSING:
CloseInfo close = ioState.getCloseInfo();
WebSocketFrame frame = close.asFrame();
LOG.debug("Issuing: {}", frame);
try {
write(frame);
} catch (IOException e) {
LOG.debug(e);
}
break;
default:
/* do nothing */
break;
}
}
use of org.eclipse.jetty.websocket.common.WebSocketFrame in project jetty.project by eclipse.
the class Fuzzer method expect.
public void expect(List<WebSocketFrame> expect, int duration, TimeUnit unit) throws Exception {
int expectedCount = expect.size();
LOG.debug("expect() {} frame(s)", expect.size());
// Read frames
EventQueue<WebSocketFrame> frames = client.readFrames(expect.size(), duration, unit);
String prefix = "";
for (int i = 0; i < expectedCount; i++) {
WebSocketFrame expected = expect.get(i);
WebSocketFrame actual = frames.poll();
prefix = "Frame[" + i + "]";
LOG.debug("{} {}", prefix, actual);
Assert.assertThat(prefix + ".opcode", OpCode.name(actual.getOpCode()), is(OpCode.name(expected.getOpCode())));
prefix += "/" + actual.getOpCode();
if (expected.getOpCode() == OpCode.CLOSE) {
CloseInfo expectedClose = new CloseInfo(expected);
CloseInfo actualClose = new CloseInfo(actual);
Assert.assertThat(prefix + ".statusCode", actualClose.getStatusCode(), is(expectedClose.getStatusCode()));
} else {
Assert.assertThat(prefix + ".payloadLength", actual.getPayloadLength(), is(expected.getPayloadLength()));
ByteBufferAssert.assertEquals(prefix + ".payload", expected.getPayload(), actual.getPayload());
}
}
}
Aggregations