use of io.vertx.core.http.HttpClientRequest in project georocket by georocket.
the class S3Store method getOne.
@Override
public void getOne(String path, Handler<AsyncResult<ChunkReadStream>> handler) {
String key = PathUtils.removeLeadingSlash(PathUtils.normalize(path));
vertx.<URL>executeBlocking(f -> {
f.complete(generatePresignedUrl(key, HttpMethod.GET));
}, ar -> {
if (ar.failed()) {
handler.handle(Future.failedFuture(ar.cause()));
return;
}
URL u = ar.result();
log.debug("GET " + u);
HttpClientRequest request = client.get(ar.result().getFile());
request.putHeader("Host", u.getHost());
request.exceptionHandler(t -> {
handler.handle(Future.failedFuture(t));
});
request.handler(response -> {
if (response.statusCode() == 200) {
String contentLength = response.getHeader("Content-Length");
long chunkSize = Long.parseLong(contentLength);
handler.handle(Future.succeededFuture(new DelegateChunkReadStream(chunkSize, response)));
} else {
Buffer errorBody = Buffer.buffer();
response.handler(buf -> {
errorBody.appendBuffer(buf);
});
response.endHandler(v -> {
log.error(errorBody);
handler.handle(Future.failedFuture(response.statusMessage()));
});
}
});
request.end();
});
}
use of io.vertx.core.http.HttpClientRequest in project georocket by georocket.
the class StoreEndpointTest method doScrolledStorepointRequest.
/**
* Performs request against the server and checks for the scroll headers.
* Fails when the headers are not present or an error occured during the request.
*
* @param context Test context
* @param url url
* @param checkHeaders should the test check the headers
* @param checkScrollIdHeaderPresent should the test check the scroll id
* @param handler response handler
*/
private void doScrolledStorepointRequest(TestContext context, String url, Boolean checkHeaders, Boolean checkScrollIdHeaderPresent, Handler<HttpClientResponse> handler) {
HttpClient client = createHttpClient();
HttpClientRequest request = client.get(url, response -> {
if (checkHeaders) {
checkScrollingResponsePresent(response, context, checkScrollIdHeaderPresent);
}
handler.handle(response);
});
request.exceptionHandler(x -> {
context.fail("Exception during query.");
});
request.end();
}
use of io.vertx.core.http.HttpClientRequest in project mod-inventory-storage by folio-org.
the class LoanTypeTest method send.
private void send(URL url, HttpMethod method, String content, Handler<HttpClientResponse> handler) {
HttpClient client = StorageTestSuite.getVertx().createHttpClient();
HttpClientRequest request;
if (content == null) {
content = "";
}
Buffer buffer = Buffer.buffer(content);
switch(method) {
case POST:
request = client.postAbs(url.toString());
break;
case DELETE:
request = client.deleteAbs(url.toString());
break;
case GET:
request = client.getAbs(url.toString());
break;
default:
request = client.putAbs(url.toString());
}
request.exceptionHandler(error -> {
Assert.fail(error.getLocalizedMessage());
}).handler(handler);
request.putHeader("Authorization", "test_tenant");
request.putHeader("x-okapi-tenant", "test_tenant");
request.putHeader("Accept", "application/json,text/plain");
request.putHeader("Content-type", SUPPORTED_CONTENT_TYPE_JSON_DEF);
request.end(buffer);
}
use of io.vertx.core.http.HttpClientRequest in project mod-inventory-storage by folio-org.
the class LocationsTest method send.
// /////////////////////////// helpers
private static void send(URL url, HttpMethod method, String content, String contentType, Handler<HttpClientResponse> handler) {
HttpClient client = StorageTestSuite.getVertx().createHttpClient();
HttpClientRequest request;
if (content == null) {
content = "";
}
Buffer buffer = Buffer.buffer(content);
if (method == HttpMethod.POST) {
request = client.postAbs(url.toString());
} else if (method == HttpMethod.DELETE) {
request = client.deleteAbs(url.toString());
} else if (method == HttpMethod.GET) {
request = client.getAbs(url.toString());
} else {
request = client.putAbs(url.toString());
}
request.exceptionHandler(error -> {
Assert.fail(error.getLocalizedMessage());
}).handler(handler);
request.putHeader("Authorization", "test_tenant");
request.putHeader("x-okapi-tenant", "test_tenant");
request.putHeader("Accept", "application/json,text/plain");
request.putHeader("Content-type", contentType);
request.end(buffer);
}
use of io.vertx.core.http.HttpClientRequest in project mod-inventory-storage by folio-org.
the class LocationUnitTest method send.
// //////////////// General helpers
/*
private JsonObject createItemRequest(String temporaryLocationId) {
JsonObject item = new JsonObject();
item.put("holdingsRecordId", UUID.randomUUID().toString());
item.put("barcode", "12345");
item.put("permanentLoanTypeId", canCirculateLoanTypeID);
item.put("materialTypeId", journalMaterialTypeID);
item.put("temporaryLocationId", temporaryLocationId);
return item;
}
*/
private static void send(URL url, HttpMethod method, String content, String contentType, Handler<HttpClientResponse> handler) {
HttpClient client = StorageTestSuite.getVertx().createHttpClient();
HttpClientRequest request;
if (content == null) {
content = "";
}
Buffer buffer = Buffer.buffer(content);
if (method == HttpMethod.POST) {
request = client.postAbs(url.toString());
} else if (method == HttpMethod.DELETE) {
request = client.deleteAbs(url.toString());
} else if (method == HttpMethod.GET) {
request = client.getAbs(url.toString());
} else {
request = client.putAbs(url.toString());
}
request.exceptionHandler(error -> {
Assert.fail(error.getLocalizedMessage());
}).handler(handler);
request.putHeader("Authorization", "test_tenant");
request.putHeader("x-okapi-tenant", "test_tenant");
request.putHeader("Accept", "application/json,text/plain");
request.putHeader("Content-type", contentType);
request.end(buffer);
}
Aggregations