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