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();
}
}));
}
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) {
}
}
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;
}
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;
}
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");
}
}
Aggregations