@Override public void start() throws Exception { String filename = "upload.txt"; FileSystem fs = vertx.fileSystem(); WebClient client = WebClient.create(vertx); fs.props(filename, ares -> { FileProps props = ares.result(); System.out.println("props is " + props); long size = props.size(); HttpRequest<Buffer> req = client.put(8080, "localhost", "/"); req.putHeader("content-length", "" + size); fs.open(filename, new OpenOptions(), ares2 -> { req.sendStream(ares2.result(), ar -> { if (ar.succeeded()) { HttpResponse<Buffer> response = ar.result(); System.out.println("Got HTTP response with status " + response.statusCode()); } else { ar.cause().printStackTrace(); } }); }); }); } }
/** * Like {@link io.vertx.rxjava.ext.web.client.HttpRequest#send} but with an HTTP request <code>body</code> stream. * @param body the body * @param handler */ public void sendStream(io.vertx.rxjava.core.streams.ReadStream<io.vertx.rxjava.core.buffer.Buffer> body, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.HttpResponse<T>>> handler) { delegate.sendStream(body.getDelegate(), new Handler<AsyncResult<io.vertx.ext.web.client.HttpResponse<T>>>() { public void handle(AsyncResult<io.vertx.ext.web.client.HttpResponse<T>> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.HttpResponse.newInstance(ar.result(), __typeArg_0))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
/** * Like {@link io.vertx.rxjava.ext.web.client.HttpRequest#send} but with an HTTP request <code>body</code> stream. * @param body the body * @param handler */ public void sendStream(io.vertx.rxjava.core.streams.ReadStream<io.vertx.rxjava.core.buffer.Buffer> body, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.HttpResponse<T>>> handler) { delegate.sendStream(body.getDelegate(), new Handler<AsyncResult<io.vertx.ext.web.client.HttpResponse<T>>>() { public void handle(AsyncResult<io.vertx.ext.web.client.HttpResponse<T>> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.HttpResponse.newInstance(ar.result(), __typeArg_0))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
/** * Like {@link io.vertx.rxjava.ext.web.client.HttpRequest#send} but with an HTTP request <code>body</code> stream. * @param body the body * @param handler */ public void sendStream(Observable<io.vertx.rxjava.core.buffer.Buffer> body, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.HttpResponse<T>>> handler) { delegate.sendStream(io.vertx.rx.java.ReadStreamSubscriber.asReadStream(body,obj -> (io.vertx.core.buffer.Buffer)obj.getDelegate()).resume(), new Handler<AsyncResult<io.vertx.ext.web.client.HttpResponse<T>>>() { public void handle(AsyncResult<io.vertx.ext.web.client.HttpResponse<T>> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.HttpResponse.newInstance(ar.result(), __typeArg_0))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
/** * Like {@link io.vertx.rxjava.ext.web.client.HttpRequest#send} but with an HTTP request <code>body</code> stream. * @param body the body * @param handler */ public void sendStream(Observable<io.vertx.rxjava.core.buffer.Buffer> body, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.HttpResponse<T>>> handler) { delegate.sendStream(io.vertx.rx.java.ReadStreamSubscriber.asReadStream(body,obj -> (io.vertx.core.buffer.Buffer)obj.getDelegate()).resume(), new Handler<AsyncResult<io.vertx.ext.web.client.HttpResponse<T>>>() { public void handle(AsyncResult<io.vertx.ext.web.client.HttpResponse<T>> ar) { if (ar.succeeded()) { handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.HttpResponse.newInstance(ar.result(), __typeArg_0))); } else { handler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); }
AtomicReference<Handler<Void>> endHandler = new AtomicReference<>(); AtomicBoolean paused = new AtomicBoolean(); post.sendStream(new ReadStream<Buffer>() { @Override public ReadStream<Buffer> exceptionHandler(Handler<Throwable> handler) {
Throwable cause = new Throwable(); startServer(); post.sendStream(new ReadStream<Buffer>() { Handler<Throwable> exceptionHandler; @Override
Throwable cause = new Throwable(); startServer(); post.sendStream(new ReadStream<Buffer>() { @Override public ReadStream<Buffer> exceptionHandler(Handler<Throwable> handler) {
builder = builder.putHeader("Content-Length", "" + expected.length()); builder.sendStream(asyncFile, onSuccess(resp -> { assertEquals(200, resp.statusCode()); complete();
@Test public void testStreamHttpServerRequest() throws Exception { Buffer expected = TestUtils.randomBuffer(10000); HttpServer server2 = vertx.createHttpServer(new HttpServerOptions().setPort(8081)).requestHandler(req -> req.bodyHandler(body -> { assertEquals(body, expected); req.response().end(); })); startServer(server2); WebClient webClient = WebClient.create(vertx); try { server.requestHandler(req -> webClient.postAbs("http://localhost:8081/") .sendStream(req, onSuccess(resp -> req.response().end("ok")))); startServer(); webClient.post(8080, "localhost", "/").sendBuffer(expected, onSuccess(resp -> { assertEquals("ok", resp.bodyAsString()); complete(); })); await(); } finally { server2.close(); } }
f.deleteOnExit(); AsyncFile asyncFile = vertx.fileSystem().openBlocking(f.getAbsolutePath(), new OpenOptions()); req.sendStream(asyncFile, handler);