Search in sources :

Example 1 with ReactiveReply

use of com.dexels.navajo.client.stream.ReactiveReply in project navajo by Dexels.

the class TestHttpResource method testStoreAdapterBasics.

@Test
@Ignore
public void testStoreAdapterBasics() throws IOException, MappableException, UserException, InterruptedException {
    BinaryStoreAdapter bsa = new BinaryStoreAdapter();
    bsa.load(access);
    Binary b = createBinary();
    String bb = bsa.storeBinary(b, "binstore", "junit", false);
    System.err.println("Result of put: " + bb);
    boolean existsNow = bsa.headBinary(b.getHexDigest(), "binstore", "junit");
    Assert.assertTrue(existsNow);
    System.err.println("exists after insert: " + existsNow);
    ReactiveReply result = bsa.deleteBinary(b.getHexDigest(), "binstore", "junit", false);
    System.err.println("Delete: " + result.status());
    boolean exists = bsa.headBinary(b.getHexDigest(), "binstore", "junit");
    Assert.assertFalse(exists);
    System.err.println("exists after delete: " + exists);
}
Also used : ReactiveReply(com.dexels.navajo.client.stream.ReactiveReply) Binary(com.dexels.navajo.document.types.Binary) BinaryStoreAdapter(com.dexels.navajo.resource.http.adapter.BinaryStoreAdapter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with ReactiveReply

use of com.dexels.navajo.client.stream.ReactiveReply in project navajo by Dexels.

the class BinaryStoreAdapter method storeBinary.

public String storeBinary(Binary b, String resource, String bucket, boolean force) throws IOException {
    String hexDigest = b.getHexDigest();
    String tenant = access.getTenant();
    ReactiveReply result = HttpResourceFactory.getInstance().getHttpResource(resource).put(tenant, bucket, hexDigest, b).filter(reply -> {
        boolean doInsert = (reply.status() != 404) || force;
        logger.debug("Result of insert: " + reply.status());
        return doInsert;
    }).toSingle().blockingGet();
    logger.info("Stored binary with status: {}", result.status());
    if (result.status() >= 400) {
        throw new IOException("Error inserting binary into resource: " + resource + " bucket: " + bucket + " status: " + result.status() + " headers: " + result.responseHeaders());
    }
    return hexDigest;
}
Also used : ReactiveReply(com.dexels.navajo.client.stream.ReactiveReply) IOException(java.io.IOException)

Example 3 with ReactiveReply

use of com.dexels.navajo.client.stream.ReactiveReply in project navajo by Dexels.

the class BinaryStoreAdapter method headBinary.

public boolean headBinary(String hexDigest, String resource, String bucket) throws IOException {
    String tenant = access.getTenant();
    ReactiveReply result = HttpResourceFactory.getInstance().getHttpResource(resource).head(tenant, bucket, hexDigest).blockingGet();
    logger.info("HEAD binary with status: {} headers: {}", result.status(), "\n -> headers: " + result.responseHeaders());
    if (result.status() >= 400) {
        return false;
    }
    return true;
}
Also used : ReactiveReply(com.dexels.navajo.client.stream.ReactiveReply)

Example 4 with ReactiveReply

use of com.dexels.navajo.client.stream.ReactiveReply 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)

Example 5 with ReactiveReply

use of com.dexels.navajo.client.stream.ReactiveReply in project navajo by Dexels.

the class BinaryStoreAdapter method setDeleteBinary.

public void setDeleteBinary(boolean ignore) throws IOException {
    String hash = binaryHash != null ? binaryHash : binary.getHexDigest();
    ReactiveReply reply = deleteBinary(hash, this.resource, this.bucket, false);
    this.deleteResult = reply.status();
}
Also used : ReactiveReply(com.dexels.navajo.client.stream.ReactiveReply)

Aggregations

ReactiveReply (com.dexels.navajo.client.stream.ReactiveReply)7 Binary (com.dexels.navajo.document.types.Binary)2 BinaryStoreAdapter (com.dexels.navajo.resource.http.adapter.BinaryStoreAdapter)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 Emitter (io.reactivex.Emitter)1 Flowable (io.reactivex.Flowable)1 FlowableTransformer (io.reactivex.FlowableTransformer)1 Single (io.reactivex.Single)1 IOException (java.io.IOException)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