Search in sources :

Example 1 with DecodeException

use of io.vertx.core.json.DecodeException in project vert.x by eclipse.

the class Starter method runVerticle.

private void runVerticle(String main, Args args) {
    boolean ha = args.map.get("-ha") != null;
    boolean clustered = args.map.get("-cluster") != null || ha;
    Vertx vertx = startVertx(clustered, ha, args);
    if (vertx == null) {
        // Throwable should have been logged at this point
        return;
    }
    String sinstances = args.map.get("-instances");
    int instances;
    if (sinstances != null) {
        try {
            instances = Integer.parseInt(sinstances);
            if (instances != -1 && instances < 1) {
                log.error("Invalid number of instances");
                displaySyntax();
                return;
            }
        } catch (NumberFormatException e) {
            displaySyntax();
            return;
        }
    } else {
        instances = 1;
    }
    String confArg = args.map.get("-conf");
    JsonObject conf;
    if (confArg != null) {
        try (Scanner scanner = new Scanner(new File(confArg)).useDelimiter("\\A")) {
            String sconf = scanner.next();
            try {
                conf = new JsonObject(sconf);
            } catch (DecodeException e) {
                log.error("Configuration file " + sconf + " does not contain a valid JSON object");
                return;
            }
        } catch (FileNotFoundException e) {
            try {
                conf = new JsonObject(confArg);
            } catch (DecodeException e2) {
                log.error("-conf option does not point to a file and is not valid JSON: " + confArg);
                return;
            }
        }
    } else {
        conf = null;
    }
    boolean worker = args.map.get("-worker") != null;
    String message = (worker) ? "deploying worker verticle" : "deploying verticle";
    deploymentOptions = new DeploymentOptions();
    configureFromSystemProperties(deploymentOptions, DEPLOYMENT_OPTIONS_PROP_PREFIX);
    deploymentOptions.setConfig(conf).setWorker(worker).setHa(ha).setInstances(instances);
    beforeDeployingVerticle(deploymentOptions);
    vertx.deployVerticle(main, deploymentOptions, createLoggingHandler(message, res -> {
        if (res.failed()) {
            handleDeployFailed();
        }
    }));
}
Also used : Manifest(java.util.jar.Manifest) java.util(java.util) DecodeException(io.vertx.core.json.DecodeException) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) IOException(java.io.IOException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Attributes(java.util.jar.Attributes) LoggerFactory(io.vertx.core.logging.LoggerFactory) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Args(io.vertx.core.impl.Args) java.net(java.net) MetricsOptions(io.vertx.core.metrics.MetricsOptions) JsonObject(io.vertx.core.json.JsonObject) Logger(io.vertx.core.logging.Logger) Method(java.lang.reflect.Method) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) JsonObject(io.vertx.core.json.JsonObject) File(java.io.File) DecodeException(io.vertx.core.json.DecodeException)

Example 2 with DecodeException

use of io.vertx.core.json.DecodeException in project vert.x by eclipse.

the class BufferTest method testToJsonArray.

@Test
public void testToJsonArray() throws Exception {
    JsonArray arr = new JsonArray();
    arr.add("wibble");
    arr.add(5);
    arr.add(true);
    Buffer buff = Buffer.buffer(arr.encode());
    assertEquals(arr, buff.toJsonArray());
    buff = Buffer.buffer(TestUtils.randomAlphaString(10));
    try {
        buff.toJsonObject();
        fail();
    } catch (DecodeException ignore) {
    }
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Buffer(io.vertx.core.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) DecodeException(io.vertx.core.json.DecodeException) Test(org.junit.Test)

Example 3 with DecodeException

use of io.vertx.core.json.DecodeException in project hono by eclipse.

the class FileBasedRegistrationService method addAll.

private Future<Void> addAll(final Buffer deviceIdentities) {
    Future<Void> result = Future.future();
    try {
        int deviceCount = 0;
        JsonArray allObjects = deviceIdentities.toJsonArray();
        for (Object obj : allObjects) {
            if (JsonObject.class.isInstance(obj)) {
                deviceCount += addDevicesForTenant((JsonObject) obj);
            }
        }
        log.info("successfully loaded {} device identities from file [{}]", deviceCount, getConfig().getFilename());
        result.complete();
    } catch (DecodeException e) {
        log.warn("cannot read malformed JSON from device identity file [{}]", getConfig().getFilename());
        result.fail(e);
    }
    return result;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) DecodeException(io.vertx.core.json.DecodeException)

Example 4 with DecodeException

use of io.vertx.core.json.DecodeException in project hono by eclipse.

the class FileBasedTenantService method addAll.

private Future<Void> addAll(final Buffer tenantsBuffer) {
    final Future<Void> result = Future.future();
    try {
        if (tenantsBuffer.length() > 0) {
            int tenantCount = 0;
            final JsonArray allObjects = tenantsBuffer.toJsonArray();
            for (final Object obj : allObjects) {
                if (JsonObject.class.isInstance(obj)) {
                    tenantCount++;
                    addTenant((JsonObject) obj);
                }
            }
            log.info("successfully loaded {} tenants from file [{}]", tenantCount, getConfig().getFilename());
        }
        result.complete();
    } catch (final DecodeException e) {
        log.warn("cannot read malformed JSON from tenants file [{}]", getConfig().getFilename());
        result.fail(e);
    }
    return result;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) TenantObject(org.eclipse.hono.util.TenantObject) JsonObject(io.vertx.core.json.JsonObject) DecodeException(io.vertx.core.json.DecodeException)

Example 5 with DecodeException

use of io.vertx.core.json.DecodeException in project hono by eclipse.

the class RegistrationHttpEndpoint method doUpdateRegistrationJson.

private void doUpdateRegistrationJson(final RoutingContext ctx) {
    try {
        JsonObject payload = null;
        if (ctx.getBody().length() > 0) {
            payload = ctx.getBodyAsJson();
        }
        updateRegistration(getDeviceIdParam(ctx), payload, ctx);
    } catch (final DecodeException e) {
        HttpUtils.badRequest(ctx, "body does not contain a valid JSON object");
    }
}
Also used : JsonObject(io.vertx.core.json.JsonObject) DecodeException(io.vertx.core.json.DecodeException)

Aggregations

DecodeException (io.vertx.core.json.DecodeException)42 JsonObject (io.vertx.core.json.JsonObject)17 Failure (org.folio.okapi.common.Failure)13 Test (org.junit.Test)8 File (java.io.File)6 DeploymentDescriptor (org.folio.okapi.bean.DeploymentDescriptor)6 TenantModuleDescriptor (org.folio.okapi.bean.TenantModuleDescriptor)6 JsonArray (io.vertx.core.json.JsonArray)4 ArrayList (java.util.ArrayList)4 ModuleDescriptor (org.folio.okapi.bean.ModuleDescriptor)4 Buffer (io.vertx.rxjava.core.buffer.Buffer)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Tuple2 (io.vavr.Tuple2)2 Vertx (io.vertx.core.Vertx)2 Buffer (io.vertx.core.buffer.Buffer)2 FileNotFoundException (java.io.FileNotFoundException)2 ByteBuffer (java.nio.ByteBuffer)2 Scanner (java.util.Scanner)2 AmqpClient (io.enmasse.iot.transport.AmqpClient)1