Search in sources :

Example 1 with ReactiveRequest

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()));
}
Also used : Logger(org.slf4j.Logger) ReactiveReply(com.dexels.navajo.client.stream.ReactiveReply) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Publisher(org.reactivestreams.Publisher) LoggerFactory(org.slf4j.LoggerFactory) UnaryOperator(java.util.function.UnaryOperator) Request(org.eclipse.jetty.client.api.Request) Single(io.reactivex.Single) ByteBuffer(java.nio.ByteBuffer) FlowableTransformer(io.reactivex.FlowableTransformer) HttpClient(org.eclipse.jetty.client.HttpClient) Emitter(io.reactivex.Emitter) AtomicLong(java.util.concurrent.atomic.AtomicLong) ContentChunk(org.eclipse.jetty.reactive.client.ContentChunk) Flowable(io.reactivex.Flowable) Optional(java.util.Optional) ReactiveRequest(org.eclipse.jetty.reactive.client.ReactiveRequest) ContentChunk(org.eclipse.jetty.reactive.client.ContentChunk) ReactiveReply(com.dexels.navajo.client.stream.ReactiveReply) Request(org.eclipse.jetty.client.api.Request) ReactiveRequest(org.eclipse.jetty.reactive.client.ReactiveRequest) ReactiveRequest(org.eclipse.jetty.reactive.client.ReactiveRequest)

Aggregations

ReactiveReply (com.dexels.navajo.client.stream.ReactiveReply)1 Emitter (io.reactivex.Emitter)1 Flowable (io.reactivex.Flowable)1 FlowableTransformer (io.reactivex.FlowableTransformer)1 Single (io.reactivex.Single)1 ByteBuffer (java.nio.ByteBuffer)1 Optional (java.util.Optional)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 UnaryOperator (java.util.function.UnaryOperator)1 HttpClient (org.eclipse.jetty.client.HttpClient)1 Request (org.eclipse.jetty.client.api.Request)1 ContentChunk (org.eclipse.jetty.reactive.client.ContentChunk)1 ReactiveRequest (org.eclipse.jetty.reactive.client.ReactiveRequest)1 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)1 Publisher (org.reactivestreams.Publisher)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1