use of io.vertx.core.Handler in project vert.x by eclipse.
the class HttpTest method testServerConnectionClose.
@Test
public void testServerConnectionClose() throws Exception {
// Test server connection close + client close handler
server.requestHandler(req -> {
req.connection().close();
});
CountDownLatch listenLatch = new CountDownLatch(1);
server.listen(onSuccess(s -> listenLatch.countDown()));
awaitLatch(listenLatch);
HttpClientRequest req = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
fail();
});
req.connectionHandler(conn -> {
conn.closeHandler(v -> {
testComplete();
});
});
req.sendHead();
await();
}
use of io.vertx.core.Handler in project vert.x by eclipse.
the class HttpTest method testParamDecoding.
private void testParamDecoding(String value) throws UnsupportedEncodingException {
server.requestHandler(req -> {
req.setExpectMultipart(true);
req.endHandler(v -> {
MultiMap formAttributes = req.formAttributes();
assertEquals(value, formAttributes.get("param"));
});
req.response().end();
});
String postData = "param=" + URLEncoder.encode(value, "UTF-8");
server.listen(onSuccess(server -> {
client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/").putHeader(HttpHeaders.CONTENT_TYPE, HttpHeaders.APPLICATION_X_WWW_FORM_URLENCODED).putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(postData.length())).handler(resp -> {
testComplete();
}).write(postData).end();
}));
await();
}
use of io.vertx.core.Handler in project vert.x by eclipse.
the class HttpTest method testFoo.
private void testFoo(String location, String expected) throws Exception {
int status = 301;
Map<String, String> headers = Collections.singletonMap("Location", location);
HttpMethod method = HttpMethod.GET;
String baseURI = "https://localhost:8080";
class MockReq implements HttpClientRequest {
public HttpClientRequest exceptionHandler(Handler<Throwable> handler) {
throw new UnsupportedOperationException();
}
public HttpClientRequest write(Buffer data) {
throw new UnsupportedOperationException();
}
public HttpClientRequest setWriteQueueMaxSize(int maxSize) {
throw new UnsupportedOperationException();
}
public HttpClientRequest drainHandler(Handler<Void> handler) {
throw new UnsupportedOperationException();
}
public HttpClientRequest handler(Handler<HttpClientResponse> handler) {
throw new UnsupportedOperationException();
}
public HttpClientRequest pause() {
throw new UnsupportedOperationException();
}
public HttpClientRequest resume() {
throw new UnsupportedOperationException();
}
public HttpClientRequest endHandler(Handler<Void> endHandler) {
throw new UnsupportedOperationException();
}
public HttpClientRequest setFollowRedirects(boolean followRedirects) {
throw new UnsupportedOperationException();
}
public HttpClientRequest setChunked(boolean chunked) {
throw new UnsupportedOperationException();
}
public boolean isChunked() {
return false;
}
public HttpMethod method() {
return method;
}
public String getRawMethod() {
throw new UnsupportedOperationException();
}
public HttpClientRequest setRawMethod(String method) {
throw new UnsupportedOperationException();
}
public String absoluteURI() {
return baseURI;
}
public String uri() {
throw new UnsupportedOperationException();
}
public String path() {
throw new UnsupportedOperationException();
}
public String query() {
throw new UnsupportedOperationException();
}
public HttpClientRequest setHost(String host) {
throw new UnsupportedOperationException();
}
public String getHost() {
throw new UnsupportedOperationException();
}
public MultiMap headers() {
throw new UnsupportedOperationException();
}
public HttpClientRequest putHeader(String name, String value) {
throw new UnsupportedOperationException();
}
public HttpClientRequest putHeader(CharSequence name, CharSequence value) {
throw new UnsupportedOperationException();
}
public HttpClientRequest putHeader(String name, Iterable<String> values) {
throw new UnsupportedOperationException();
}
public HttpClientRequest putHeader(CharSequence name, Iterable<CharSequence> values) {
throw new UnsupportedOperationException();
}
public HttpClientRequest write(String chunk) {
throw new UnsupportedOperationException();
}
public HttpClientRequest write(String chunk, String enc) {
throw new UnsupportedOperationException();
}
public HttpClientRequest continueHandler(@Nullable Handler<Void> handler) {
throw new UnsupportedOperationException();
}
public HttpClientRequest sendHead() {
throw new UnsupportedOperationException();
}
public HttpClientRequest sendHead(Handler<HttpVersion> completionHandler) {
throw new UnsupportedOperationException();
}
public void end(String chunk) {
throw new UnsupportedOperationException();
}
public void end(String chunk, String enc) {
throw new UnsupportedOperationException();
}
public void end(Buffer chunk) {
throw new UnsupportedOperationException();
}
public void end() {
throw new UnsupportedOperationException();
}
public HttpClientRequest setTimeout(long timeoutMs) {
throw new UnsupportedOperationException();
}
public HttpClientRequest pushHandler(Handler<HttpClientRequest> handler) {
throw new UnsupportedOperationException();
}
public boolean reset(long code) {
return false;
}
public HttpConnection connection() {
throw new UnsupportedOperationException();
}
public HttpClientRequest connectionHandler(@Nullable Handler<HttpConnection> handler) {
throw new UnsupportedOperationException();
}
public HttpClientRequest writeCustomFrame(int type, int flags, Buffer payload) {
throw new UnsupportedOperationException();
}
public boolean writeQueueFull() {
throw new UnsupportedOperationException();
}
}
HttpClientRequest req = new MockReq();
class MockResp implements HttpClientResponse {
public HttpClientResponse resume() {
throw new UnsupportedOperationException();
}
public HttpClientResponse exceptionHandler(Handler<Throwable> handler) {
throw new UnsupportedOperationException();
}
public HttpClientResponse handler(Handler<Buffer> handler) {
throw new UnsupportedOperationException();
}
public HttpClientResponse pause() {
throw new UnsupportedOperationException();
}
public HttpClientResponse endHandler(Handler<Void> endHandler) {
throw new UnsupportedOperationException();
}
public HttpVersion version() {
throw new UnsupportedOperationException();
}
public int statusCode() {
return status;
}
public String statusMessage() {
throw new UnsupportedOperationException();
}
public MultiMap headers() {
throw new UnsupportedOperationException();
}
public String getHeader(String headerName) {
return headers.get(headerName);
}
public String getHeader(CharSequence headerName) {
return getHeader(headerName.toString());
}
public String getTrailer(String trailerName) {
throw new UnsupportedOperationException();
}
public MultiMap trailers() {
throw new UnsupportedOperationException();
}
public List<String> cookies() {
throw new UnsupportedOperationException();
}
public HttpClientResponse bodyHandler(Handler<Buffer> bodyHandler) {
throw new UnsupportedOperationException();
}
public HttpClientResponse customFrameHandler(Handler<HttpFrame> handler) {
throw new UnsupportedOperationException();
}
public NetSocket netSocket() {
throw new UnsupportedOperationException();
}
public HttpClientRequest request() {
return req;
}
}
MockResp resp = new MockResp();
Function<HttpClientResponse, Future<HttpClientRequest>> handler = client.redirectHandler();
Future<HttpClientRequest> redirection = handler.apply(resp);
if (expected != null) {
assertEquals(location, redirection.result().absoluteURI());
} else {
assertTrue(redirection == null || redirection.failed());
}
}
use of io.vertx.core.Handler in project vert.x by eclipse.
the class HttpTest method testRequestTimesoutWhenIndicatedPeriodExpiresWithoutAResponseFromRemoteServer.
@Test
public void testRequestTimesoutWhenIndicatedPeriodExpiresWithoutAResponseFromRemoteServer() {
// No response handler so timeout triggers
server.requestHandler(noOpHandler());
AtomicBoolean failed = new AtomicBoolean();
server.listen(onSuccess(s -> {
HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
fail("End should not be called because the request should timeout");
});
req.exceptionHandler(t -> {
if (failed.compareAndSet(false, true)) {
assertTrue("Expected to end with timeout exception but ended with other exception: " + t, t instanceof TimeoutException);
testComplete();
}
});
req.setTimeout(1000);
req.end();
}));
await();
}
use of io.vertx.core.Handler in project vert.x by eclipse.
the class WebsocketTest method testEndHandlerCalled.
@Test
public void testEndHandlerCalled() {
String path = "/some/path";
server = vertx.createHttpServer(new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT)).websocketHandler(WebSocketBase::close);
AtomicInteger doneCount = new AtomicInteger();
server.listen(ar -> {
assertTrue(ar.succeeded());
client.websocketStream(HttpTestBase.DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path, null).endHandler(done -> doneCount.incrementAndGet()).handler(ws -> {
assertEquals(0, doneCount.get());
ws.closeHandler(v -> {
assertEquals(1, doneCount.get());
testComplete();
});
});
});
await();
}
Aggregations