use of org.eclipse.jetty.websocket.api.extensions.Frame in project jetty.project by eclipse.
the class RFC6455ExamplesParserTest method testSingleUnmasked64KByteBinaryMessage.
@Test
public void testSingleUnmasked64KByteBinaryMessage() {
int dataSize = 1024 * 64;
ByteBuffer buf = ByteBuffer.allocate((dataSize + 10));
// Raw bytes as found in RFC 6455, Section 5.7 - Examples
// 64 Kbytes binary message in a single unmasked frame
buf.put(new byte[] { (byte) 0x82, 0x7F });
// 64bit size
buf.putLong(dataSize);
for (int i = 0; i < dataSize; i++) {
buf.put((byte) 0x77);
}
buf.flip();
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
Parser parser = new UnitParser(policy);
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(buf);
capture.assertNoErrors();
capture.assertHasFrame(OpCode.BINARY, 1);
Frame bin = capture.getFrames().poll();
Assert.assertThat("BinaryFrame.payloadLength", bin.getPayloadLength(), is(dataSize));
ByteBuffer data = bin.getPayload();
Assert.assertThat("BinaryFrame.payload.length", data.remaining(), is(dataSize));
for (int i = 0; i < dataSize; i++) {
Assert.assertThat("BinaryFrame.payload[" + i + "]", data.get(i), is((byte) 0x77));
}
}
use of org.eclipse.jetty.websocket.api.extensions.Frame in project jetty.project by eclipse.
the class WebSocketServletRFCTest method testInternalError.
/**
* Test the requirement of responding with server terminated close code 1011 when there is an unhandled (internal server error) being produced by the
* WebSocket POJO.
* @throws Exception on test failure
*/
@Test
public void testInternalError() throws Exception {
try (BlockheadClient client = new BlockheadClient(server.getServerUri());
StacklessLogging stackless = new StacklessLogging(EventDriver.class)) {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
try (StacklessLogging context = new StacklessLogging(EventDriver.class)) {
// Generate text frame
client.write(new TextFrame().setPayload("CRASH"));
// Read frame (hopefully close frame)
EventQueue<WebSocketFrame> frames = client.readFrames(1, 30, TimeUnit.SECONDS);
Frame cf = frames.poll();
CloseInfo close = new CloseInfo(cf);
Assert.assertThat("Close Frame.status code", close.getStatusCode(), is(StatusCode.SERVER_ERROR));
}
}
}
use of org.eclipse.jetty.websocket.api.extensions.Frame in project jetty.project by eclipse.
the class IncomingFramesCapture method dump.
public void dump() {
System.err.printf("Captured %d incoming frames%n", frames.size());
int i = 0;
for (Frame frame : frames) {
System.err.printf("[%3d] %s%n", i++, frame);
System.err.printf(" payload: %s%n", BufferUtil.toDetailString(frame.getPayload()));
}
}
use of org.eclipse.jetty.websocket.api.extensions.Frame in project jetty.project by eclipse.
the class OutgoingFramesCapture method dump.
public void dump() {
System.out.printf("Captured %d outgoing writes%n", frames.size());
for (int i = 0; i < frames.size(); i++) {
Frame frame = frames.get(i);
System.out.printf("[%3d] %s%n", i, frame);
System.out.printf(" %s%n", BufferUtil.toDetailString(frame.getPayload()));
}
}
use of org.eclipse.jetty.websocket.api.extensions.Frame in project jetty.project by eclipse.
the class Fuzzer method send.
public void send(List<WebSocketFrame> send) throws IOException {
Assert.assertThat("Client connected", client.isConnected(), is(true));
LOG.debug("[{}] Sending {} frames (mode {})", testname, send.size(), sendMode);
if ((sendMode == SendMode.BULK) || (sendMode == SendMode.SLOW)) {
int buflen = 0;
for (Frame f : send) {
buflen += f.getPayloadLength() + Generator.MAX_HEADER_LENGTH;
}
ByteBuffer buf = ByteBuffer.allocate(buflen);
// Generate frames
for (WebSocketFrame f : send) {
setClientMask(f);
buf.put(generator.generateHeaderBytes(f));
if (f.hasPayload()) {
buf.put(f.getPayload());
}
}
BufferUtil.flipToFlush(buf, 0);
// Write Data Frame
switch(sendMode) {
case BULK:
client.writeRaw(buf);
break;
case SLOW:
client.writeRawSlowly(buf, slowSendSegmentSize);
break;
default:
throw new RuntimeException("Whoops, unsupported sendMode: " + sendMode);
}
} else if (sendMode == SendMode.PER_FRAME) {
for (WebSocketFrame f : send) {
// make sure we have mask set
f.setMask(MASK);
// Using lax generator, generate and send
ByteBuffer fullframe = ByteBuffer.allocate(f.getPayloadLength() + Generator.MAX_HEADER_LENGTH);
BufferUtil.clearToFill(fullframe);
generator.generateWholeFrame(f, fullframe);
BufferUtil.flipToFlush(fullframe, 0);
client.writeRaw(fullframe);
client.flush();
}
}
}
Aggregations