use of org.eclipse.jetty.reactive.client.ReactiveRequest in project navajo by Dexels.
the class JettyClient method call.
public Flowable<ReactiveReply> call(String uri, UnaryOperator<Request> buildRequest, Optional<Flowable<byte[]>> requestBody, Optional<String> requestContentType) {
// Reque
Request req = httpClient.newRequest(uri);
Request reqProcessed = buildRequest.apply(req);
if (requestContentType.isPresent()) {
reqProcessed = reqProcessed.header("Content-Type", requestContentType.get());
}
ReactiveRequest.Builder requestBuilder = ReactiveRequest.newBuilder(reqProcessed);
if (requestBody.isPresent()) {
Publisher<ContentChunk> bb = requestBody.get().doOnNext(b -> this.sent.addAndGet(b.length)).map(e -> new ContentChunk(ByteBuffer.wrap(e)));
requestBuilder = requestBuilder.content(ReactiveRequest.Content.fromPublisher(bb, requestContentType.orElse("application/octet-stream")));
}
ReactiveRequest request = requestBuilder.build();
return Flowable.fromPublisher(request.response((response, content) -> Flowable.just(new ReactiveReply(response, content, b -> this.sent.addAndGet(b.length))))).doOnComplete(() -> logger.info("HTTP Client to {}: sent: {} received: {}", uri, sent.get(), received.get()));
}
Aggregations