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

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

Introduction

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

Prototype

public JsonObject put(String key, Object value) 

Source Link

Document

Put an Object into the JSON object with the specified key.

Usage

From source file:com.test.db.DbServiceVertxEBProxy.java

License:Apache License

public void read(String query, JsonObject databaseConfig, Handler<AsyncResult<JsonObject>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;/*from w  w w.ja va2 s  .c  o  m*/
    }
    JsonObject _json = new JsonObject();
    _json.put("query", query);
    _json.put("databaseConfig", databaseConfig);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "read");
    _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            resultHandler.handle(Future.failedFuture(res.cause()));
        } else {
            resultHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:com.test.db.DbServiceVertxEBProxy.java

License:Apache License

public void nonSharedRead(String query, JsonObject databaseConfig,
        Handler<AsyncResult<JsonObject>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;// w w  w. ja  v a  2  s  .c om
    }
    JsonObject _json = new JsonObject();
    _json.put("query", query);
    _json.put("databaseConfig", databaseConfig);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "nonSharedRead");
    _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            resultHandler.handle(Future.failedFuture(res.cause()));
        } else {
            resultHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:com.test.mailer.MailerServiceVertxEBProxy.java

License:Apache License

public void sendAttachment(String To, MailAttachment attachment, String Title,
        Handler<AsyncResult<JsonObject>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;/*  w ww .  j  av  a  2 s.c o  m*/
    }
    JsonObject _json = new JsonObject();
    _json.put("To", To);
    _json.put("attachment", attachment == null ? null : attachment.toJson());
    _json.put("Title", Title);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "sendAttachment");
    _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            resultHandler.handle(Future.failedFuture(res.cause()));
        } else {
            resultHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:com.waves_rsp.ikb4stream.communication.web.WebCommunication.java

License:Open Source License

/**
 * Starts the server, implemented by vertx.
 *
 * @param databaseReader {@link IDatabaseReader} is the connection to database to get Event
 * @throws NullPointerException if databaseReader is null
 * @see WebCommunication#PROPERTIES_MANAGER
 * @see WebCommunication#server/*  w ww. j a v  a2  s  .com*/
 */
@Override
public void start(IDatabaseReader databaseReader) {
    Objects.requireNonNull(databaseReader);
    configureDatabaseReader(databaseReader);
    LOGGER.info("Starting WebCommunication module");
    server = Vertx.vertx();
    DeploymentOptions deploymentOptions = new DeploymentOptions();
    int port = 8081;
    try {
        PROPERTIES_MANAGER.getProperty("communications.web.port");
        port = Integer.parseInt(PROPERTIES_MANAGER.getProperty("communications.web.port"));
        LOGGER.info("WebCommunication Server set on port {}", port);
    } catch (NumberFormatException e) {
        LOGGER.error("Invalid 'communications.web.port' value");
        return;
    } catch (IllegalArgumentException e) {
        LOGGER.info("Property 'communications.web.port' not set. Use default value for score.target");
    }
    JsonObject jsonObject = new JsonObject();
    jsonObject.put("http.port", port);
    deploymentOptions.setConfig(jsonObject);
    server.deployVerticle(VertxServer.class.getName(), deploymentOptions);
}

From source file:com.weeaar.vertxwebconfig.codec.request.HttpRequestConverter.java

License:Apache License

public static void toJson(HttpRequest obj, JsonObject json) {
    if (obj.getBodyString() != null) {
        json.put("bodyString", obj.getBodyString());
    }/*ww w  .jav a 2s. co  m*/
    if (obj.getCookies() != null) {
        json.put("cookies", obj.getCookies());
    }
    json.put("ended", obj.isEnded());
    json.put("ssl", obj.isSSL());
}

From source file:com.weeaar.vertxwebconfig.codec.response.HttpResponseConverter.java

License:Apache License

public static void toJson(HttpResponse obj, JsonObject json) {
    if (obj.getBody() != null) {
        json.put("body", obj.getBody());
    }//ww  w.  ja  v  a  2  s.  co  m
    if (obj.getStatusCode() != null) {
        json.put("statusCode", obj.getStatusCode());
    }
    if (obj.getStatusMessage() != null) {
        json.put("statusMessage", obj.getStatusMessage());
    }
}

From source file:de.braintags.netrelay.controller.api.DataTablesController.java

License:Open Source License

private JsonObject createJsonObject(IMapper mapper, List<IStoreObject<?, ?>> selection,
        DataTableLinkDescriptor descr, long completeCount, long tableCount) {
    LOGGER.info("tableCount: " + tableCount + ", completeCount: " + completeCount);
    JsonObject json = new JsonObject();
    json.put("recordsTotal", tableCount);
    json.put("recordsFiltered", completeCount);
    JsonArray resArray = new JsonArray();
    json.put("data", resArray);
    for (IStoreObject<?, ?> ob : selection) {
        resArray.add(handleObject(mapper, ob, descr));
    }//from w w w.j  a  v  a  2  s . c o m
    return json;
}

From source file:de.braintags.netrelay.controller.authentication.AbstractAuthProviderController.java

License:Open Source License

private AuthProvider initDatastoreAuthProvider(String mapper) {
    Class mapperClass = getNetRelay().getSettings().getMappingDefinitions().getMapperClass(mapper);
    if (mapperClass == null) {
        throw new InitException("Could not find defined mapper class for mapper '" + mapper + "'");
    }/*from  ww  w  . j a  v a 2  s.c  o  m*/
    JsonObject config = new JsonObject();
    config.put(IDatastoreAuth.PROPERTY_MAPPER_CLASS_NAME, mapperClass.getName());
    return IDatastoreAuth.create(getNetRelay().getDatastore(), config);
}

From source file:de.braintags.netrelay.controller.authentication.AbstractAuthProviderController.java

License:Open Source License

/**
 * Init the Authentication Service// w  w w.  j  a  v a  2 s.  co  m
 */
private AuthProvider initMongoAuthProvider(String mapper) {
    IDataStore store = getNetRelay().getDatastore();
    if (!(store instanceof MongoDataStore)) {
        throw new IllegalArgumentException("MongoAuthProvider expects a MongoDataStore");
    }
    JsonObject config = new JsonObject();
    String saltStyle = readProperty(MongoAuth.PROPERTY_SALT_STYLE, HashSaltStyle.NO_SALT.toString(), false);
    config.put(MongoAuth.PROPERTY_SALT_STYLE, HashSaltStyle.valueOf(saltStyle));
    MongoAuth auth = MongoAuth.create((MongoClient) ((MongoDataStore) store).getClient(), config);

    String passwordFieldName = readProperty(MongoAuth.PROPERTY_PASSWORD_FIELD, null, true);
    Class mapperClass = getNetRelay().getSettings().getMappingDefinitions().getMapperClass(mapper);
    if (mapperClass == null) {
        throw new InitException("Could not find mapper with name " + mapper);
    }
    IMapper mapperDef = getNetRelay().getDatastore().getMapperFactory().getMapper(mapperClass);
    IField pwField = mapperDef.getField(passwordFieldName);
    if (pwField.getEncoder() != null) {
        throw new InitException(
                "MongoAuth does not support the annotation Encoder, please use DatastoreAuth instead");
    }
    auth.setPasswordField(passwordFieldName);
    auth.setUsernameField(readProperty(MongoAuth.PROPERTY_USERNAME_FIELD, null, true));
    auth.setCollectionName(mapper);

    String roleField = readProperty(MongoAuth.PROPERTY_ROLE_FIELD, null, false);
    if (roleField != null) {
        auth.setRoleField(roleField);
    }
    String saltField = readProperty(MongoAuth.PROPERTY_SALT_FIELD, null, false);
    if (saltField != null) {
        auth.setSaltField(saltField);
    }

    return auth;
}

From source file:de.braintags.netrelay.controller.authentication.RegisterController.java

License:Open Source License

private JsonObject getAuthObject(IAuthenticatable user, AuthProviderProxy proxy) {
    AuthProvider prov = proxy.getProvider();
    if (prov instanceof MongoAuthImpl) {
        JsonObject authInfo = new JsonObject();
        authInfo.put(((MongoAuthImpl) prov).getUsernameCredentialField(), user.getEmail())
                .put(((MongoAuthImpl) prov).getPasswordCredentialField(), user.getPassword());
        return authInfo;
    } else if (prov instanceof IDatastoreAuth) {
        JsonObject authInfo = new JsonObject();
        authInfo.put(IDatastoreAuth.CREDENTIAL_USERNAME_FIELD, user.getEmail())
                .put(IDatastoreAuth.CREDENTIAL_PASSWORD_FIELD, user.getPassword());
        return authInfo;
    }//ww w .  jav  a 2  s. c om
    throw new UnsupportedOperationException("Unsupported authprovider class: " + prov.getClass());
}