use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class WebSocketImplBase method writeTextMessageInternal.
private void writeTextMessageInternal(String text) {
checkClosed();
Buffer data = Buffer.buffer(text);
writePartialMessage(FrameType.TEXT, data, 0);
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class Http2Test method testClientStreamPausedWhenConnectionIsPaused.
@Test
public void testClientStreamPausedWhenConnectionIsPaused() throws Exception {
waitFor(2);
Buffer buffer = TestUtils.randomBuffer(512);
CompletableFuture<Void> resumeLatch = new CompletableFuture<>();
server.requestHandler(req -> {
switch(req.path()) {
case "/0":
{
req.pause();
resumeLatch.thenAccept(v -> {
req.resume();
});
req.endHandler(v -> {
req.response().end();
});
break;
}
case "/1":
{
req.bodyHandler(v -> {
assertEquals(v, buffer);
req.response().end();
});
break;
}
}
});
startServer();
HttpClientRequest req1 = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/0", resp -> {
complete();
}).setChunked(true);
while (!req1.writeQueueFull()) {
req1.write(Buffer.buffer(TestUtils.randomAlphaString(512)));
Thread.sleep(1);
}
HttpClientRequest req2 = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/1", resp -> {
complete();
}).setChunked(true);
assertFalse(req2.writeQueueFull());
req2.sendHead(v -> {
assertTrue(req2.writeQueueFull());
resumeLatch.complete(null);
});
resumeLatch.get(20, TimeUnit.SECONDS);
waitUntil(() -> !req2.writeQueueFull());
req1.end();
req2.end(buffer);
await();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class HttpTest method testFormUploadAttributes2.
@Test
public void testFormUploadAttributes2() throws Exception {
AtomicInteger attributeCount = new AtomicInteger();
server.requestHandler(req -> {
if (req.method() == HttpMethod.POST) {
assertEquals(req.path(), "/form");
req.setExpectMultipart(true);
req.uploadHandler(event -> event.handler(buffer -> {
fail("Should not get here");
}));
req.endHandler(v -> {
MultiMap attrs = req.formAttributes();
attributeCount.set(attrs.size());
assertEquals("junit-testUserAlias", attrs.get("origin"));
assertEquals("admin@foo.bar", attrs.get("login"));
assertEquals("admin", attrs.get("pass word"));
req.response().end();
});
}
});
server.listen(onSuccess(s -> {
HttpClientRequest req = client.request(HttpMethod.POST, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/form", resp -> {
assertEquals(200, resp.statusCode());
resp.bodyHandler(body -> {
assertEquals(0, body.length());
});
assertEquals(3, attributeCount.get());
testComplete();
});
Buffer buffer = Buffer.buffer();
buffer.appendString("origin=junit-testUserAlias&login=admin%40foo.bar&pass+word=admin");
req.headers().set("content-length", String.valueOf(buffer.length()));
req.headers().set("content-type", "application/x-www-form-urlencoded");
req.write(buffer).end();
}));
await();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class HttpTest method testResponseBodyWriteFixedString.
@Test
public void testResponseBodyWriteFixedString() {
String body = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
Buffer bodyBuff = Buffer.buffer(body);
server.requestHandler(req -> {
req.response().setChunked(true);
req.response().write(body);
req.response().end();
});
server.listen(onSuccess(s -> {
client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
resp.bodyHandler(buff -> {
assertEquals(bodyBuff, buff);
testComplete();
});
}).end();
}));
await();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class HttpTest method testClientRequestArguments.
@Test
public void testClientRequestArguments() throws Exception {
HttpClientRequest req = client.request(HttpMethod.PUT, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler());
assertNullPointerException(() -> req.putHeader((String) null, "someValue"));
assertNullPointerException(() -> req.putHeader((CharSequence) null, "someValue"));
assertNullPointerException(() -> req.putHeader("someKey", (Iterable<String>) null));
assertNullPointerException(() -> req.write((Buffer) null));
assertNullPointerException(() -> req.write((String) null));
assertNullPointerException(() -> req.write(null, "UTF-8"));
assertNullPointerException(() -> req.write("someString", null));
assertNullPointerException(() -> req.end((Buffer) null));
assertNullPointerException(() -> req.end((String) null));
assertNullPointerException(() -> req.end(null, "UTF-8"));
assertNullPointerException(() -> req.end("someString", null));
assertIllegalArgumentException(() -> req.setTimeout(0));
}
Aggregations