use of org.folio.okapi.common.OkapiClient in project okapi by folio-org.
the class AuthModuleTest method testOkLogin.
@Test
public void testOkLogin(TestContext context) {
Async async = context.async();
HashMap<String, String> headers = new HashMap<>();
headers.put(XOkapiHeaders.URL, URL);
headers.put(XOkapiHeaders.TENANT, "my-lib");
OkapiClient cli = new OkapiClient(URL, vertx, headers);
JsonObject j = new JsonObject();
j.put("tenant", "my-lib");
j.put("username", "foo");
j.put("password", "foo-password");
String body = j.encodePrettily();
cli.post("/authn/login", body, res -> {
context.assertTrue(res.succeeded());
cli.setOkapiToken(cli.getRespHeaders().get(XOkapiHeaders.TOKEN));
testNormal(context, cli, async);
});
}
use of org.folio.okapi.common.OkapiClient in project okapi by folio-org.
the class AuthModuleTest method testNoTokenNoTenant.
@Test
public void testNoTokenNoTenant(TestContext context) {
Async async = context.async();
HashMap<String, String> headers = new HashMap<>();
headers.put(XOkapiHeaders.URL, URL);
OkapiClient cli = new OkapiClient(URL, vertx, headers);
cli.get("/notokentenant", res -> {
cli.close();
context.assertTrue(res.failed());
context.assertEquals(ErrorType.INTERNAL, res.getType());
async.complete();
});
}
use of org.folio.okapi.common.OkapiClient in project okapi by folio-org.
the class DiscoveryManager method callDeploy.
/**
* Helper to actually launch (deploy) a module on a node.
*/
private void callDeploy(String nodeId, ProxyContext pc, DeploymentDescriptor dd, Handler<ExtendedAsyncResult<DeploymentDescriptor>> fut) {
logger.debug("callDeploy starting for " + Json.encode(dd));
getNode(nodeId, noderes -> {
if (noderes.failed()) {
fut.handle(new Failure<>(noderes.getType(), noderes.cause()));
} else {
Map<String, String> headers = new HashMap<>();
if (pc != null) {
for (String s : pc.getCtx().request().headers().names()) {
if (s.startsWith("X-") || s.startsWith("x-")) {
final String v = pc.getCtx().request().headers().get(s);
headers.put(s, v);
}
}
}
OkapiClient ok = new OkapiClient(noderes.result().getUrl(), vertx, headers);
String reqdata = Json.encode(dd);
ok.post("/_/deployment/modules", reqdata, okres -> {
ok.close();
if (okres.failed()) {
fut.handle(new Failure<>(okres.getType(), okres.cause().getMessage()));
} else {
DeploymentDescriptor pmd = Json.decodeValue(okres.result(), DeploymentDescriptor.class);
fut.handle(new Success<>(pmd));
}
});
}
});
}
use of org.folio.okapi.common.OkapiClient in project okapi by folio-org.
the class DiscoveryManager method callUndeploy.
private void callUndeploy(DeploymentDescriptor md, ProxyContext pc, Handler<ExtendedAsyncResult<Void>> fut) {
logger.info("callUndeploy srvcId=" + md.getSrvcId() + " instId=" + md.getInstId() + " node=" + md.getNodeId());
final String nodeId = md.getNodeId();
if (nodeId == null) {
logger.info("callUndeploy remove");
remove(md.getSrvcId(), md.getInstId(), fut);
} else {
logger.info("callUndeploy calling..");
getNode(nodeId, res1 -> {
if (res1.failed()) {
fut.handle(new Failure<>(res1.getType(), res1.cause()));
} else {
Map<String, String> headers = new HashMap<>();
if (pc != null) {
for (String s : pc.getCtx().request().headers().names()) {
if (s.startsWith("X-") || s.startsWith("x-")) {
final String v = pc.getCtx().request().headers().get(s);
headers.put(s, v);
}
}
}
OkapiClient ok = new OkapiClient(res1.result().getUrl(), vertx, headers);
ok.delete("/_/deployment/modules/" + md.getInstId(), okres -> {
ok.close();
if (okres.failed()) {
logger.warn("Dm: Failure: " + okres.getType() + " " + okres.cause().getMessage());
fut.handle(new Failure<>(okres.getType(), okres.cause().getMessage()));
} else {
fut.handle(new Success<>());
}
});
}
});
}
}
Aggregations