io.vertx.ext.web.client.HttpRequest.sendStream()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中io.vertx.ext.web.client.HttpRequest.sendStream()方法的一些代码示例,展示了HttpRequest.sendStream()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.sendStream()方法的具体详情如下:
包路径:io.vertx.ext.web.client.HttpRequest
类名称:HttpRequest
方法名:sendStream

HttpRequest.sendStream介绍

暂无

代码示例

代码示例来源:origin: vert-x3/vertx-examples

@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();
     }
    });
   });
  });
 }
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * 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()));
   }
  }
 });
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * 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()));
   }
  }
 });
}

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * 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()));
   }
  }
 });
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * 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()));
   }
  }
 });
}

代码示例来源:origin: io.vertx/vertx-web-client

AtomicReference<Handler<Void>> endHandler = new AtomicReference<>();
AtomicBoolean paused = new AtomicBoolean();
post.sendStream(new ReadStream<Buffer>() {
   @Override
   public ReadStream<Buffer> exceptionHandler(Handler<Throwable> handler) {

代码示例来源:origin: io.vertx/vertx-web-client

Throwable cause = new Throwable();
startServer();
post.sendStream(new ReadStream<Buffer>() {
 Handler<Throwable> exceptionHandler;
 @Override

代码示例来源:origin: io.vertx/vertx-web-client

Throwable cause = new Throwable();
startServer();
post.sendStream(new ReadStream<Buffer>() {
   @Override
   public ReadStream<Buffer> exceptionHandler(Handler<Throwable> handler) {

代码示例来源:origin: io.vertx/vertx-web-client

builder = builder.putHeader("Content-Length", "" + expected.length());
builder.sendStream(asyncFile, onSuccess(resp -> {
   assertEquals(200, resp.statusCode());
   complete();

代码示例来源:origin: io.vertx/vertx-web-client

@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();
 }
}

代码示例来源:origin: io.vertx/vertx-web-client

f.deleteOnExit();
AsyncFile asyncFile = vertx.fileSystem().openBlocking(f.getAbsolutePath(), new OpenOptions());
req.sendStream(asyncFile, handler);

相关文章