@Override public ReadStream<T> exceptionHandler(Handler<Throwable> handler) { delegate.exceptionHandler(handler); return null; }
@Override public JsonParser handler(Handler<JsonEvent> handler) { eventHandler = handler; if (stream != null) { if (handler != null) { stream.endHandler(v -> end()); stream.exceptionHandler(err -> { if (exceptionHandler != null) { exceptionHandler.handle(err); } }); stream.handler(this); } else { stream.handler(null); stream.endHandler(null); stream.exceptionHandler(null); } } return this; }
@Override public RecordParser handler(Handler<Buffer> handler) { eventHandler = handler; if (stream != null) { if (handler != null) { stream.endHandler(v -> end()); stream.exceptionHandler(err -> { if (exceptionHandler != null) { exceptionHandler.handle(err); } }); stream.handler(this); } else { stream.handler(null); stream.endHandler(null); stream.exceptionHandler(null); } } return this; }
}); }); rs.exceptionHandler(t -> fail(t.getMessage())); rs.endHandler(v -> { ended.set(true);
private void testInvalidSubProtocol(WebsocketVersion version) throws Exception { String path = "/some/path"; String subProtocol = "myprotocol"; server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setWebsocketSubProtocols("invalid")).websocketHandler(ws -> { }); server.listen(onSuccess(ar -> { client.websocketStream(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path, null, version, subProtocol). exceptionHandler(t -> { // Should fail testComplete(); }). handler(ws -> { }); })); await(); }
@Override public ReadStream<T> exceptionHandler(Handler<Throwable> handler) { delegate.exceptionHandler(handler); return null; }
private void testReject(WebsocketVersion version, Integer rejectionStatus, int expectedRejectionStatus) throws Exception { String path = "/some/path"; server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).websocketHandler(ws -> { assertEquals(path, ws.path()); if (rejectionStatus != null) { ws.reject(rejectionStatus); } else { ws.reject(); } }); server.listen(ar -> { assertTrue(ar.succeeded()); client.websocketStream(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path, null, version). exceptionHandler(t -> { assertTrue(t instanceof WebsocketRejectedException); assertEquals(expectedRejectionStatus, ((WebsocketRejectedException)t).getStatus()); testComplete(); }). handler(ws -> fail("Should not be called")); }); await(); }
}; wsProvider.apply(client). exceptionHandler(errHandler). handler(wsHandler); });
public <T> CompletableFuture<T> saveAs(Function<Buffer, T> converter) { CompletableFuture<T> future = new CompletableFuture<>(); Buffer buffer = Buffer.buffer(); // if readStream.resume() not run on correct eventloop, will: // 1.create a context task to save last chunk data to buffer // 2.activate connection to read new data // but maybe 2 will run before 1, that will cause lost data or get incorrect data context.runOnContext(V -> { readStream.exceptionHandler(future::completeExceptionally); readStream.handler(buffer::appendBuffer); readStream.endHandler(v -> future.complete(converter.apply(buffer))); readStream.resume(); }); return future; }
@Override public RecordParser handler(Handler<Buffer> handler) { eventHandler = handler; if (stream != null) { if (handler != null) { stream.endHandler(v -> end()); stream.exceptionHandler(err -> { if (exceptionHandler != null) { exceptionHandler.handle(err); } }); stream.handler(this); } else { stream.handler(null); stream.endHandler(null); stream.exceptionHandler(null); } } return this; }
@Override public JsonParser handler(Handler<JsonEvent> handler) { eventHandler = handler; if (stream != null) { if (handler != null) { stream.endHandler(v -> end()); stream.exceptionHandler(err -> { if (exceptionHandler != null) { exceptionHandler.handle(err); } }); stream.handler(this); } else { stream.handler(null); stream.endHandler(null); stream.exceptionHandler(null); } } return this; }
readStream.exceptionHandler(readFuture::completeExceptionally);
@Override public ReadStream<Buffer> exceptionHandler(Handler<Throwable> handler) { s.exceptionHandler(handler); return this; } @Override
}); }); rs.exceptionHandler(t -> fail(t.getMessage())); rs.endHandler(v -> { ended.set(true);
private void testInvalidSubProtocol(WebsocketVersion version) throws Exception { String path = "/some/path"; String subProtocol = "myprotocol"; server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setWebsocketSubProtocols("invalid")).websocketHandler(ws -> { }); server.listen(onSuccess(ar -> { client.websocketStream(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path, null, version, subProtocol). exceptionHandler(t -> { // Should fail testComplete(); }). handler(ws -> { }); })); await(); }
private void testReject(WebsocketVersion version, Integer rejectionStatus, int expectedRejectionStatus) throws Exception { String path = "/some/path"; server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).websocketHandler(ws -> { assertEquals(path, ws.path()); if (rejectionStatus != null) { ws.reject(rejectionStatus); } else { ws.reject(); } }); server.listen(ar -> { assertTrue(ar.succeeded()); client.websocketStream(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path, null, version). exceptionHandler(t -> { assertTrue(t instanceof WebsocketRejectedException); assertEquals(expectedRejectionStatus, ((WebsocketRejectedException)t).getStatus()); testComplete(); }). handler(ws -> fail("Should not be called")); }); await(); }
@Override public BufferReadStream exceptionHandler(Handler<Throwable> handler) { stream.exceptionHandler(handler); return this; } @Override
/** * Set an exception handler on the read stream. * @param handler the exception handler * @return a reference to this, so the API can be used fluently */ public io.vertx.reactivex.core.streams.ReadStream<T> exceptionHandler(Handler<Throwable> handler) { delegate.exceptionHandler(handler); return this; }
}; wsProvider.apply(client). exceptionHandler(errHandler). handler(wsHandler); });
@Test public void testSetHandlersAfterCompletionButPending() { Sender sender = sender(); sender.stream.handler(item -> {}); sender.stream.pause(); sender.emit(); sender.complete(); sender.stream.exceptionHandler(err -> {}); sender.stream.exceptionHandler(null); sender.stream.endHandler(v -> {}); sender.stream.endHandler(null); }