io.vertx.core.streams.Pipe Java Examples

The following examples show how to use io.vertx.core.streams.Pipe. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VertxHttpClientTest.java    From gravitee-gateway with Apache License 2.0 4 votes vote down vote up
@Override
public Pipe<HttpClientResponse> pipe() {
    return null;
}
 
Example #2
Source File: HttpContext.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
private void handleReceiveResponse() {
  HttpClientResponse resp = clientResponse;
  Context context = Vertx.currentContext();
  Promise<HttpResponse<T>> promise = Promise.promise();
  promise.future().onComplete(r -> {
    // We are running on a context (the HTTP client mandates it)
    context.runOnContext(v -> {
      if (r.succeeded()) {
        dispatchResponse(r.result());
      } else {
        fail(r.cause());
      }
    });
  });
  resp.exceptionHandler(err -> {
    if (!promise.future().isComplete()) {
      promise.fail(err);
    }
  });
  Pipe<Buffer> pipe = resp.pipe();
  request.codec.create(ar1 -> {
    if (ar1.succeeded()) {
      BodyStream<T> stream = ar1.result();
      pipe.to(stream, ar2 -> {
        if (ar2.succeeded()) {
          stream.result().onComplete(ar3 -> {
            if (ar3.succeeded()) {
              promise.complete(new HttpResponseImpl<>(
                resp.version(),
                resp.statusCode(),
                resp.statusMessage(),
                resp.headers(),
                resp.trailers(),
                resp.cookies(),
                stream.result().result(),
                redirectedLocations
              ));
            } else {
              promise.fail(ar3.cause());
            }
          });
        } else {
          promise.fail(ar2.cause());
        }
      });
    } else {
      pipe.close();
      fail(ar1.cause());
    }
  });
}