use of org.folio.okapi.common.Failure in project okapi by folio-org.
the class InternalModule method updateModule.
private void updateModule(ProxyContext pc, String id, String body, Handler<ExtendedAsyncResult<String>> fut) {
try {
final ModuleDescriptor md = Json.decodeValue(body, ModuleDescriptor.class);
if (!id.equals(md.getId())) {
fut.handle(new Failure<>(USER, "Module.id=" + md.getId() + " id=" + id));
return;
}
String validerr = md.validate(pc);
if (!validerr.isEmpty()) {
fut.handle(new Failure<>(USER, validerr));
return;
}
moduleManager.update(md, res -> {
if (res.failed()) {
fut.handle(new Failure<>(res.getType(), res.cause()));
return;
}
final String s = Json.encodePrettily(md);
fut.handle(new Success<>(s));
});
} catch (DecodeException ex) {
fut.handle(new Failure<>(USER, ex));
}
}
use of org.folio.okapi.common.Failure in project okapi by folio-org.
the class PullManager method getRemoteUrl.
private void getRemoteUrl(Iterator<String> it, Handler<ExtendedAsyncResult<String>> fut) {
if (!it.hasNext()) {
fut.handle(new Failure<>(ErrorType.NOT_FOUND, "pull: none of remote URLs work"));
} else {
final String baseUrl = it.next();
String url = baseUrl;
if (!url.endsWith("/")) {
url += "/";
}
url += "_/version";
final Buffer body = Buffer.buffer();
HttpClientRequest req = httpClient.getAbs(url, res -> {
res.handler(body::appendBuffer);
res.endHandler(x -> {
if (res.statusCode() != 200) {
logger.info("pull for " + baseUrl + " failed with status " + res.statusCode());
fut.handle(new Failure<>(ErrorType.USER, "pull for " + baseUrl + " returned status " + res.statusCode() + "\n" + body.toString()));
} else {
fut.handle(new Success<>(baseUrl));
}
});
res.exceptionHandler(x -> fut.handle(new Failure<>(ErrorType.INTERNAL, x.getMessage())));
});
req.exceptionHandler(res -> {
logger.info("pull for " + baseUrl + " failed with status " + res.getMessage());
getRemoteUrl(it, fut);
});
req.end();
}
}
use of org.folio.okapi.common.Failure in project okapi by folio-org.
the class ProxyService method proxyRequestHttpClient.
private void proxyRequestHttpClient(Iterator<ModuleInstance> it, ProxyContext pc, Buffer bcontent, ModuleInstance mi) {
RoutingContext ctx = pc.getCtx();
String url = makeUrl(mi, ctx);
HttpMethod meth = ctx.request().method();
HttpClientRequest cReq = httpClient.requestAbs(meth, url, res -> {
if (res.statusCode() < 200 || res.statusCode() >= 300) {
proxyResponseImmediate(pc, res, mi);
} else if (it.hasNext()) {
makeTraceHeader(mi, res.statusCode(), pc);
pc.closeTimer();
relayToRequest(res, pc, mi);
proxyR(it, pc, null, bcontent);
} else {
relayToResponse(ctx.response(), res);
makeTraceHeader(mi, res.statusCode(), pc);
res.endHandler(x -> {
pc.closeTimer();
pc.trace("ProxyRequestHttpClient final response buf '" + bcontent + "'");
ctx.response().end(bcontent);
});
res.exceptionHandler(e -> pc.warn("proxyRequestHttpClient: res exception (b)", e));
}
});
cReq.exceptionHandler(e -> {
pc.warn("proxyRequestHttpClient failure: " + url, e);
pc.responseText(500, "proxyRequestHttpClient failure: " + mi.getModuleDescriptor().getId() + " " + mi.getUrl() + ": " + e + " " + e.getMessage());
});
cReq.headers().setAll(ctx.request().headers());
cReq.headers().remove("Content-Length");
pc.trace("ProxyRequestHttpClient request buf '" + bcontent + "'");
cReq.end(bcontent);
log(pc, cReq);
}
Aggregations