Example usage for io.vertx.core.json JsonObject JsonObject

List of usage examples for io.vertx.core.json JsonObject JsonObject

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject JsonObject.

Prototype

public JsonObject() 

Source Link

Document

Create a new, empty instance

Usage

From source file:com.glencoesoftware.omero.ms.core.OmeroWebSessionRequestHandler.java

License:Open Source License

/**
 * Handler implementation whose responsibility is to make the OMERO session
 * key into the routing context via the <code>omero.session_key</code>
 * key of the <code>event</code> context dictionary.
 * @see Handler#handle(Object)/*from w  w  w .  j  ava2 s .c o m*/
 */
@Override
public void handle(RoutingContext event) {
    // First try to get the OMERO session key from the
    // `X-OMERO-Session-Key` request header.
    String sessionKey = event.request().headers().get("X-OMERO-Session-Key");
    if (sessionKey != null) {
        log.debug("OMERO session key from header: {}", sessionKey);
        event.put("omero.session_key", sessionKey);
        event.next();
        return;
    }

    // Next see if it was provided via the `bsession` URL parameter
    sessionKey = event.request().getParam("bsession");
    if (sessionKey != null) {
        log.debug("OMERO session key from 'bsession' URL parameter: {}", sessionKey);
        event.put("omero.session_key", sessionKey);
        event.next();
        return;
    }

    // Finally, check if we have a standard OMERO.web cookie available to
    // retrieve the session key from.
    JsonObject omeroWeb = config.getJsonObject("omero.web", new JsonObject());
    String name = omeroWeb.getString("session_cookie_name", "sessionid");
    Cookie cookie = event.getCookie(name);
    if (cookie == null) {
        event.response().setStatusCode(403);
        event.response().end();
        return;
    }
    final String djangoSessionKey = cookie.getValue();
    log.debug("OMERO.web session key: {}", djangoSessionKey);
    sessionStore.getConnectorAsync(djangoSessionKey).whenComplete((connector, throwable) -> {
        if (throwable != null) {
            log.error("Exception retrieving connector", throwable);
        }
        if (connector == null) {
            event.response().setStatusCode(403);
            event.response().end();
            return;
        }
        event.put("omero.session_key", connector.getOmeroSessionKey());
        event.next();
    });
}

From source file:com.glencoesoftware.omero.ms.thumbnail.ThumbnailMicroserviceVerticle.java

License:Open Source License

/**
 * Entry point method which starts the server event loop and initializes
 * our current OMERO.web session store./*from w ww. java2 s .c o  m*/
 */
@Override
public void start(Future<Void> future) {
    log.info("Starting verticle");

    ConfigStoreOptions store = new ConfigStoreOptions().setType("file").setFormat("yaml")
            .setConfig(new JsonObject().put("path", "conf/config.yaml")).setOptional(true);
    ConfigRetriever retriever = ConfigRetriever.create(vertx,
            new ConfigRetrieverOptions().setIncludeDefaultStores(true).addStore(store));
    retriever.getConfig(ar -> {
        try {
            deploy(ar.result(), future);
        } catch (Exception e) {
            future.fail(e);
        }
    });
}

From source file:com.glt.cronjob.JobServiceVertxEBProxy.java

License:Apache License

public JobService schedule(JsonObject jobDescriptor, Handler<AsyncResult<Boolean>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/*  w w w .j a  va 2 s  .  c o m*/
    JsonObject _json = new JsonObject();
    _json.put("jobDescriptor", jobDescriptor);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "schedule");
    _vertx.eventBus().<Boolean>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            resultHandler.handle(Future.failedFuture(res.cause()));
        } else {
            resultHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
    return this;
}

From source file:com.glt.cronjob.JobServiceVertxEBProxy.java

License:Apache License

public JobService unschedule(JsonObject jobDescriptor, Handler<AsyncResult<Boolean>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }//from   ww  w. j a  va  2  s  .  c om
    JsonObject _json = new JsonObject();
    _json.put("jobDescriptor", jobDescriptor);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "unschedule");
    _vertx.eventBus().<Boolean>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            resultHandler.handle(Future.failedFuture(res.cause()));
        } else {
            resultHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
    return this;
}

From source file:com.glt.rest.client.RestServiceVertxEBProxy.java

License:Apache License

public void get(JsonObject command, Handler<AsyncResult<String>> asyncHandler) {
    if (closed) {
        asyncHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;/* w ww  . j  a  va2s  . c o m*/
    }
    JsonObject _json = new JsonObject();
    _json.put("command", command);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "get");
    _vertx.eventBus().<String>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            asyncHandler.handle(Future.failedFuture(res.cause()));
        } else {
            asyncHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:com.glt.rest.client.RestServiceVertxEBProxy.java

License:Apache License

public void post(JsonObject command, Handler<AsyncResult<String>> asyncHandler) {
    if (closed) {
        asyncHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;//from   ww  w.  j ava2s .c om
    }
    JsonObject _json = new JsonObject();
    _json.put("command", command);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "post");
    _vertx.eventBus().<String>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            asyncHandler.handle(Future.failedFuture(res.cause()));
        } else {
            asyncHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:com.glt.rest.client.RestServiceVertxEBProxy.java

License:Apache License

public void put(JsonObject command, Handler<AsyncResult<String>> asyncHandler) {
    if (closed) {
        asyncHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;/*  w  ww. java 2s .  c  om*/
    }
    JsonObject _json = new JsonObject();
    _json.put("command", command);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "put");
    _vertx.eventBus().<String>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            asyncHandler.handle(Future.failedFuture(res.cause()));
        } else {
            asyncHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:com.glt.rest.client.RestServiceVertxEBProxy.java

License:Apache License

public void delete(JsonObject command, Handler<AsyncResult<String>> asyncHandler) {
    if (closed) {
        asyncHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;/*from   www.j av  a 2  s . c  o m*/
    }
    JsonObject _json = new JsonObject();
    _json.put("command", command);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "delete");
    _vertx.eventBus().<String>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            asyncHandler.handle(Future.failedFuture(res.cause()));
        } else {
            asyncHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:com.glt.rest.client.RestServiceVertxEBProxy.java

License:Apache License

public void getJson(JsonObject command, Handler<AsyncResult<JsonObject>> asyncHandler) {
    if (closed) {
        asyncHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;/*from  www .j a va 2 s  . com*/
    }
    JsonObject _json = new JsonObject();
    _json.put("command", command);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "getJson");
    _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            asyncHandler.handle(Future.failedFuture(res.cause()));
        } else {
            asyncHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:com.glt.rest.client.RestServiceVertxEBProxy.java

License:Apache License

public void postJson(JsonObject command, Handler<AsyncResult<JsonObject>> asyncHandler) {
    if (closed) {
        asyncHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;/*www . j a  v  a 2s.  c  om*/
    }
    JsonObject _json = new JsonObject();
    _json.put("command", command);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "postJson");
    _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            asyncHandler.handle(Future.failedFuture(res.cause()));
        } else {
            asyncHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}