Search in sources :

Example 16 with OkapiClient

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);
    });
}
Also used : OkapiClient(org.folio.okapi.common.OkapiClient) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 17 with OkapiClient

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();
    });
}
Also used : OkapiClient(org.folio.okapi.common.OkapiClient) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 18 with OkapiClient

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));
                }
            });
        }
    });
}
Also used : OkapiClient(org.folio.okapi.common.OkapiClient) HashMap(java.util.HashMap) DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor)

Example 19 with OkapiClient

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<>());
                    }
                });
            }
        });
    }
}
Also used : OkapiClient(org.folio.okapi.common.OkapiClient) HashMap(java.util.HashMap)

Aggregations

OkapiClient (org.folio.okapi.common.OkapiClient)19 HashMap (java.util.HashMap)17 Async (io.vertx.ext.unit.Async)12 Test (org.junit.Test)12 JsonObject (io.vertx.core.json.JsonObject)3 HttpMethod (io.vertx.core.http.HttpMethod)2 DeploymentDescriptor (org.folio.okapi.bean.DeploymentDescriptor)2 RoutingEntry (org.folio.okapi.bean.RoutingEntry)2 AbstractVerticle (io.vertx.core.AbstractVerticle)1 Future (io.vertx.core.Future)1 MultiMap (io.vertx.core.MultiMap)1 HttpServerOptions (io.vertx.core.http.HttpServerOptions)1 Logger (io.vertx.core.logging.Logger)1 Router (io.vertx.ext.web.Router)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 ManagementFactory (java.lang.management.ManagementFactory)1 Map (java.util.Map)1 ModuleInstance (org.folio.okapi.bean.ModuleInstance)1