use of org.folio.okapi.common.Failure in project okapi by folio-org.
the class ProxyService method proxyHeaders.
private void proxyHeaders(Iterator<ModuleInstance> it, ProxyContext pc, ReadStream<Buffer> stream, Buffer bcontent, ModuleInstance mi) {
RoutingContext ctx = pc.getCtx();
HttpClientRequest cReq = httpClient.requestAbs(ctx.request().method(), makeUrl(mi, ctx), res -> {
if (res.statusCode() < 200 || res.statusCode() >= 300) {
proxyResponseImmediate(pc, res, mi);
if (bcontent == null) {
stream.resume();
}
} else if (it.hasNext()) {
relayToRequest(res, pc, mi);
makeTraceHeader(mi, res.statusCode(), pc);
res.endHandler(x -> proxyR(it, pc, stream, bcontent));
} else {
relayToResponse(ctx.response(), res);
makeTraceHeader(mi, res.statusCode(), pc);
if (bcontent == null) {
stream.handler(data -> {
ctx.response().write(data);
pc.trace("ProxyHeaders request chunk '" + data.toString() + "'");
});
stream.endHandler(v -> {
ctx.response().end();
pc.trace("ProxyHeaders request end");
});
stream.exceptionHandler(e -> pc.warn("proxyHeaders: content exception ", e));
stream.resume();
} else {
pc.trace("ProxyHeaders request buf '" + bcontent + "'");
ctx.response().end(bcontent);
}
}
});
cReq.exceptionHandler(e -> {
pc.warn("proxyHeaders failure: " + mi.getUrl() + ": ", e);
pc.responseText(500, "proxyHeaders failure: " + mi.getModuleDescriptor().getId() + " " + mi.getUrl() + ": " + e + " " + e.getMessage());
});
cReq.headers().setAll(ctx.request().headers());
cReq.headers().remove("Content-Length");
cReq.end();
log(pc, cReq);
}
use of org.folio.okapi.common.Failure in project okapi by folio-org.
the class PullManager method getList.
private void getList(String urlBase, Handler<ExtendedAsyncResult<ModuleDescriptor[]>> fut) {
String url = urlBase;
if (!url.endsWith("/")) {
url += "/";
}
url += "_/proxy/modules";
final Buffer body = Buffer.buffer();
HttpClientRequest req = httpClient.getAbs(url, res -> {
res.handler(body::appendBuffer);
res.endHandler(x -> {
if (res.statusCode() != 200) {
fut.handle(new Failure<>(ErrorType.USER, body.toString()));
} else {
ModuleDescriptor[] ml = Json.decodeValue(body.toString(), ModuleDescriptor[].class);
fut.handle(new Success<>(ml));
}
});
res.exceptionHandler(x -> fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage())));
});
req.exceptionHandler(x -> fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage())));
req.end();
}
use of org.folio.okapi.common.Failure in project okapi by folio-org.
the class MongoUtil method delete.
public void delete(String id, Handler<ExtendedAsyncResult<Void>> fut) {
JsonObject jq = new JsonObject().put("_id", id);
cli.removeDocument(collection, jq, rres -> {
if (rres.failed()) {
fut.handle(new Failure<>(INTERNAL, rres.cause()));
} else if (rres.result().getRemovedCount() == 0) {
fut.handle(new Failure<>(NOT_FOUND, id));
} else {
fut.handle(new Success<>());
}
});
}
use of org.folio.okapi.common.Failure in project okapi by folio-org.
the class InternalModule method pullModules.
private void pullModules(String body, Handler<ExtendedAsyncResult<String>> fut) {
try {
final PullDescriptor pmd = Json.decodeValue(body, PullDescriptor.class);
pullManager.pull(pmd, res -> {
if (res.failed()) {
fut.handle(new Failure<>(res.getType(), res.cause()));
return;
}
fut.handle(new Success<>(Json.encodePrettily(res.result())));
});
} catch (DecodeException ex) {
fut.handle(new Failure<>(USER, ex));
}
}
use of org.folio.okapi.common.Failure in project okapi by folio-org.
the class InternalModule method updateTenant.
private void updateTenant(String id, String body, Handler<ExtendedAsyncResult<String>> fut) {
try {
final TenantDescriptor td = Json.decodeValue(body, TenantDescriptor.class);
if (!id.equals(td.getId())) {
fut.handle(new Failure<>(USER, "Tenant.id=" + td.getId() + " id=" + id));
return;
}
Tenant t = new Tenant(td);
tenantManager.updateDescriptor(td, res -> {
if (res.failed()) {
fut.handle(new Failure<>(res.getType(), res.cause()));
return;
}
final String s = Json.encodePrettily(t.getDescriptor());
fut.handle(new Success<>(s));
});
} catch (DecodeException ex) {
fut.handle(new Failure<>(USER, ex));
}
}
Aggregations