use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class RequestHeadersTest method testAccessRequestCookies.
@Test
public void testAccessRequestCookies() throws Exception {
BlockheadClient client = new BlockheadClient(server.getServerUri());
client.setTimeout(1, TimeUnit.SECONDS);
try {
client.connect();
client.addHeader("Cookie: fruit=Pear; type=Anjou\r\n");
client.sendStandardRequest();
client.expectUpgradeResponse();
UpgradeRequest req = echoCreator.getLastRequest();
Assert.assertThat("Last Request", req, notNullValue());
List<HttpCookie> cookies = req.getCookies();
Assert.assertThat("Request cookies", cookies, notNullValue());
Assert.assertThat("Request cookies.size", cookies.size(), is(2));
for (HttpCookie cookie : cookies) {
Assert.assertThat("Cookie name", cookie.getName(), anyOf(is("fruit"), is("type")));
Assert.assertThat("Cookie value", cookie.getValue(), anyOf(is("Pear"), is("Anjou")));
}
} finally {
client.close();
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class SubProtocolTest method testSubProtocol.
private void testSubProtocol(String requestProtocols, String acceptedSubProtocols) throws Exception {
try (BlockheadClient client = new BlockheadClient(server.getServerUri())) {
client.setTimeout(1, TimeUnit.SECONDS);
client.connect();
client.addHeader("Sec-WebSocket-Protocol: " + requestProtocols + "\r\n");
client.sendStandardRequest();
client.expectUpgradeResponse();
client.write(new TextFrame().setPayload("showme"));
EventQueue<WebSocketFrame> frames = client.readFrames(1, 30, TimeUnit.SECONDS);
WebSocketFrame tf = frames.poll();
assertThat(ProtocolEchoSocket.class.getSimpleName() + ".onMessage()", tf.getPayloadAsUTF8(), is("acceptedSubprotocol=" + acceptedSubProtocols));
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class SuspendResumeTest method testSuspendResume.
@Test
public void testSuspendResume() throws Exception {
try (BlockheadClient client = new BlockheadClient(server.getServerUri())) {
client.setTimeout(1, TimeUnit.SECONDS);
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.write(new TextFrame().setPayload("echo1"));
client.write(new TextFrame().setPayload("echo2"));
EventQueue<WebSocketFrame> frames = client.readFrames(2, 30, TimeUnit.SECONDS);
WebSocketFrame tf = frames.poll();
assertThat(EchoSocket.class.getSimpleName() + ".onMessage()", tf.getPayloadAsUTF8(), is("echo1"));
tf = frames.poll();
assertThat(EchoSocket.class.getSimpleName() + ".onMessage()", tf.getPayloadAsUTF8(), is("echo2"));
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class TooFastClientTest method testUpgradeWithLargeFrame.
/**
* Test where were a client sends a HTTP Upgrade to websocket AND enough websocket frame(s)
* to completely overfill the {@link org.eclipse.jetty.io.AbstractConnection#getInputBufferSize()}
* to test a situation where the WebSocket connection opens with prefill that exceeds
* the normal input buffer sizes.
* @throws Exception on test failure
*/
@Test
@Ignore("RELEASE")
public void testUpgradeWithLargeFrame() throws Exception {
BlockheadClient client = new BlockheadClient(server.getServerUri());
try {
client.connect();
// Create ByteBuffer representing the initial opening network packet from the client
ByteBuffer initialPacket = ByteBuffer.allocate(100 * 1024);
BufferUtil.clearToFill(initialPacket);
// Add upgrade request to packet
StringBuilder upgradeRequest = client.generateUpgradeRequest();
ByteBuffer upgradeBuffer = BufferUtil.toBuffer(upgradeRequest.toString(), StandardCharsets.UTF_8);
initialPacket.put(upgradeBuffer);
// Add text frames
Generator generator = new Generator(WebSocketPolicy.newClientPolicy(), new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()));
byte[] bigMsgBytes = new byte[64 * 1024];
Arrays.fill(bigMsgBytes, (byte) 'x');
String bigMsg = new String(bigMsgBytes, StandardCharsets.UTF_8);
// Need to set frame mask (as these are client frames)
byte[] mask = new byte[] { 0x11, 0x22, 0x33, 0x44 };
TextFrame frame = new TextFrame().setPayload(bigMsg);
frame.setMask(mask);
generator.generateWholeFrame(frame, initialPacket);
// Write packet to network
BufferUtil.flipToFlush(initialPacket, 0);
client.writeRaw(initialPacket);
// Expect upgrade
client.expectUpgradeResponse();
// Read frames (hopefully text frames)
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
WebSocketFrame tf = frames.poll();
Assert.assertThat("Text Frame/msg1", tf.getPayloadAsUTF8(), is(bigMsg));
} finally {
client.close();
}
}
use of org.eclipse.jetty.websocket.common.test.BlockheadClient in project jetty.project by eclipse.
the class DecoratorsTest method testAccessRequestCookies.
@Test
public void testAccessRequestCookies() throws Exception {
BlockheadClient client = new BlockheadClient(server.getServerUri());
client.setTimeout(1, TimeUnit.SECONDS);
try {
client.connect();
client.sendStandardRequest();
client.expectUpgradeResponse();
client.write(new TextFrame().setPayload("info"));
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
WebSocketFrame resp = frames.poll();
String textMsg = resp.getPayloadAsUTF8();
assertThat("DecoratedObjectFactory", textMsg, containsString("Object is a DecoratedObjectFactory"));
assertThat("decorators.size", textMsg, containsString("Decorators.size = [1]"));
assertThat("decorator type", textMsg, containsString("decorator[] = " + DummyUtilDecorator.class.getName()));
} finally {
client.close();
}
}
Aggregations