use of io.vertx.core.json.DecodeException in project hono by eclipse.
the class RegistrationHttpEndpoint method doRegisterDeviceJson.
private void doRegisterDeviceJson(final RoutingContext ctx) {
try {
JsonObject payload = null;
if (ctx.getBody().length() > 0) {
payload = ctx.getBodyAsJson();
}
registerDevice(ctx, payload);
} catch (final DecodeException e) {
HttpUtils.badRequest(ctx, "body does not contain a valid JSON object");
}
}
use of io.vertx.core.json.DecodeException in project rulesservice by genny-project.
the class RulesLoader method processFileRealms.
private static List<Tuple3<String, String, String>> processFileRealms(final String realm, String inputFileStr) {
File file = new File(inputFileStr);
String fileName = inputFileStr.replaceFirst(".*/(\\w+).*", "$1");
String fileNameExt = inputFileStr.replaceFirst(".*/\\w+\\.(.*)", "$1");
List<Tuple3<String, String, String>> rules = new ArrayList<Tuple3<String, String, String>>();
if (!file.isFile()) {
// DIRECTORY
if (!fileName.startsWith("XX")) {
String localRealm = realm;
if (fileName.startsWith("prj_") || fileName.startsWith("PRJ_")) {
// extract realm name
localRealm = fileName.substring("prj_".length()).toLowerCase();
}
final List<String> filesList = Vertx.currentContext().owner().fileSystem().readDirBlocking(inputFileStr);
for (final String dirFileStr : filesList) {
// use
List<Tuple3<String, String, String>> childRules = processFileRealms(localRealm, dirFileStr);
// directory
// name
// as
// rulegroup
rules.addAll(childRules);
}
}
return rules;
} else {
Buffer buf = Vertx.currentContext().owner().fileSystem().readFileBlocking(inputFileStr);
try {
if ((!fileName.startsWith("XX")) && (fileNameExt.equalsIgnoreCase("drl"))) {
// ignore files that start
// with XX
final String ruleText = buf.toString();
Tuple3<String, String, String> rule = (Tuple.of(realm, fileName + "." + fileNameExt, ruleText));
System.out.println(realm + " Loading in Rule:" + rule._1 + " of " + inputFileStr);
rules.add(rule);
} else if ((!fileName.startsWith("XX")) && (fileNameExt.equalsIgnoreCase("bpmn"))) {
// ignore files
// that start
// with XX
final String bpmnText = buf.toString();
Tuple3<String, String, String> bpmn = (Tuple.of(realm, fileName + "." + fileNameExt, bpmnText));
System.out.println(realm + " Loading in BPMN:" + bpmn._1 + " of " + inputFileStr);
rules.add(bpmn);
} else if ((!fileName.startsWith("XX")) && (fileNameExt.equalsIgnoreCase("xls"))) {
// ignore files that
// start with XX
final String xlsText = buf.toString();
Tuple3<String, String, String> xls = (Tuple.of(realm, fileName + "." + fileNameExt, xlsText));
System.out.println(realm + " Loading in XLS:" + xls._1 + " of " + inputFileStr);
rules.add(xls);
}
return rules;
} catch (final DecodeException dE) {
}
}
return null;
}
use of io.vertx.core.json.DecodeException in project raml-module-builder by folio-org.
the class SchemaDereferencer method dereferencedSchema.
/**
* Return a schema with all $ref dereferenced.
*
* @param inputPath path of the schema file, may be relative to the current directory
* @param dereferenceStack stack of the files chain for file
* @return dereferenced RAML
* @throws IOException when any $ref file cannot be read
* @throws IllegalStateException when the $ref chain has a loop
* @throws DecodeException when the $ref file is not a JSON
*/
protected JsonObject dereferencedSchema(Path inputPath, Deque<Path> dereferenceStack) throws IOException {
Path path = inputPath.normalize().toAbsolutePath();
if (dereferenced.containsKey(path)) {
return dereferenced.get(path);
}
boolean loop = dereferenceStack.contains(path);
dereferenceStack.push(path);
if (loop) {
throw new IllegalStateException("$ref chain has a loop: " + allPaths(dereferenceStack));
}
String schemaString;
try (InputStream reader = new FileInputStream(path.toFile())) {
schemaString = IoUtil.toStringUtf8(reader);
}
JsonObject schema;
if (schemaString.indexOf('{') == -1) {
// schemaString contains the filename to open
Path newInputPath = inputPath.resolveSibling(Paths.get(schemaString)).normalize();
schema = dereferencedSchema(newInputPath, dereferenceStack);
} else {
try {
schema = new JsonObject(schemaString);
} catch (DecodeException e) {
throw new DecodeException(allPaths(dereferenceStack), e);
}
dereference(schema, inputPath, dereferenceStack);
}
dereferenceStack.pop();
dereferenced.put(path, schema);
return schema;
}
use of io.vertx.core.json.DecodeException in project vertx-web by vert-x3.
the class EventBusBridgeImpl method handleSocketData.
private void handleSocketData(SockJSSocket sock, Buffer data, Map<String, MessageConsumer> registrations) {
JsonObject msg;
try {
msg = new JsonObject(data.toString());
} catch (DecodeException e) {
replyError(sock, "invalid_json");
return;
}
String type = msg.getString("type");
if (type == null) {
replyError(sock, "missing_type");
return;
}
if (type.equals("ping")) {
internalHandlePing(sock);
} else {
String address = msg.getString("address");
if (address == null) {
replyError(sock, "missing_address");
return;
}
switch(type) {
case "send":
internalHandleSendOrPub(sock, true, msg);
break;
case "publish":
internalHandleSendOrPub(sock, false, msg);
break;
case "register":
internalHandleRegister(sock, msg, registrations);
break;
case "unregister":
internalHandleUnregister(sock, msg, registrations);
break;
default:
log.error("Invalid type in incoming message: " + type);
replyError(sock, "invalid_type");
}
}
}
use of io.vertx.core.json.DecodeException in project okapi by folio-org.
the class InternalModule method pullModules.
private void pullModules(String body, Handler<ExtendedAsyncResult<String>> fut) {
try {
final PullDescriptor pmd = Json.decodeValue(body, PullDescriptor.class);
pullManager.pull(pmd, res -> {
if (res.failed()) {
fut.handle(new Failure<>(res.getType(), res.cause()));
return;
}
fut.handle(new Success<>(Json.encodePrettily(res.result())));
});
} catch (DecodeException ex) {
fut.handle(new Failure<>(USER, ex));
}
}
Aggregations