use of io.vertx.core.json.DecodeException in project okapi by folio-org.
the class BeanTest method testDeploymentDescriptor2.
@Test
public void testDeploymentDescriptor2() {
int fail = 0;
final String docSampleDeployment = "{" + LS + " \"srvcId\" : \"sample-module-1\"," + LS + " \"descriptor\" : {" + LS + " \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"," + LS + " \"env\" : [ {" + LS + " \"name\" : \"helloGreeting\"" + LS + " } ]" + LS + " }" + LS + "}";
try {
final DeploymentDescriptor md = Json.decodeValue(docSampleDeployment, DeploymentDescriptor.class);
String pretty = Json.encodePrettily(md);
assertEquals(docSampleDeployment, pretty);
} catch (DecodeException ex) {
ex.printStackTrace();
fail = 400;
}
assertEquals(0, fail);
}
use of io.vertx.core.json.DecodeException in project okapi by folio-org.
the class BeanTest method testDeploymentDescriptor3.
@Test
public void testDeploymentDescriptor3() {
int fail = 0;
final String docSampleDeployment = "{" + LS + " \"srvcId\" : \"sample-module-1\"," + LS + " \"descriptor\" : {" + LS + " \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS + " }" + LS + "}";
try {
final DeploymentDescriptor md = Json.decodeValue(docSampleDeployment, DeploymentDescriptor.class);
String pretty = Json.encodePrettily(md);
assertEquals(docSampleDeployment, pretty);
} catch (DecodeException ex) {
ex.printStackTrace();
fail = 400;
}
assertEquals(0, fail);
}
use of io.vertx.core.json.DecodeException in project okapi by folio-org.
the class RoutingEntryTest method test1.
@Test
public void test1() {
RoutingEntry t = new RoutingEntry();
String[] methods = new String[1];
methods[0] = "GET";
t.setPathPattern("/");
t.setMethods(methods);
assertTrue(t.match("/", "GET"));
assertFalse(t.match("/", "POST"));
assertFalse(t.match("/a", "GET"));
assertFalse(t.match("/a/", "GET"));
assertFalse(t.match("", "GET"));
assertTrue(t.match("/?query", "GET"));
assertTrue(t.match("/#x", "GET"));
t.setPathPattern("/*");
assertTrue(t.match("/", "GET"));
assertFalse(t.match("/", "POST"));
assertTrue(t.match("/a", "GET"));
assertTrue(t.match("/a/", "GET"));
assertFalse(t.match("", "GET"));
assertTrue(t.match("/?query", "GET"));
assertTrue(t.match("/#x", "GET"));
t.setPathPattern("/*/a");
assertFalse(t.match("/", "GET"));
assertFalse(t.match("/", "POST"));
assertFalse(t.match("/a", "GET"));
assertFalse(t.match("/a/", "GET"));
assertFalse(t.match("", "GET"));
assertFalse(t.match("/?query", "GET"));
assertFalse(t.match("/#x", "GET"));
assertTrue(t.match("/b/a", "GET"));
assertTrue(t.match("/c/b/a", "GET"));
t.setPathPattern("/a/{id}");
assertFalse(t.match("/", "GET"));
assertFalse(t.match("/", "POST"));
assertFalse(t.match("/a", "GET"));
assertFalse(t.match("/a/", "GET"));
assertFalse(t.match("", "GET"));
assertFalse(t.match("/?query", "GET"));
assertFalse(t.match("/#x", "GET"));
assertTrue(t.match("/a/b", "GET"));
assertTrue(t.match("/a/0-9", "GET"));
assertFalse(t.match("/a/b/", "GET"));
assertFalse(t.match("/a/b/", "GET"));
assertFalse(t.match("/a/b/c", "GET"));
t.setPathPattern("/a/{id}/c");
assertFalse(t.match("/", "GET"));
assertFalse(t.match("/", "POST"));
assertFalse(t.match("/a", "GET"));
assertFalse(t.match("/a/", "GET"));
assertFalse(t.match("", "GET"));
assertFalse(t.match("/?query", "GET"));
assertFalse(t.match("/#x", "GET"));
assertFalse(t.match("/a/b", "GET"));
assertFalse(t.match("/a/0-9", "GET"));
assertFalse(t.match("/a/b/", "GET"));
assertFalse(t.match("/a/b/", "GET"));
assertTrue(t.match("/a/b/c", "GET"));
boolean caught = false;
try {
t.setPathPattern("/a{a{");
} catch (DecodeException e) {
caught = true;
}
assertTrue(caught);
caught = false;
try {
t.setPathPattern("/a{");
} catch (DecodeException e) {
caught = true;
}
assertTrue(caught);
caught = false;
try {
t.setPathPattern("/?a=b");
} catch (DecodeException e) {
caught = true;
}
assertTrue(caught);
caught = false;
try {
t.setPathPattern("/a.b");
} catch (DecodeException e) {
caught = true;
}
assertTrue(caught);
caught = false;
try {
t.setPathPattern("/a\\b");
} catch (DecodeException e) {
caught = true;
}
assertTrue(caught);
caught = false;
try {
t.setPathPattern("/a{:}b");
} catch (DecodeException e) {
caught = true;
}
assertTrue(caught);
caught = false;
try {
t.setPathPattern("/a{}b");
} catch (DecodeException e) {
caught = true;
}
assertFalse(caught);
}
use of io.vertx.core.json.DecodeException in project knotx by Cognifide.
the class KnotxModuleVerticleFactory method readDescriptor.
private JsonObject readDescriptor(ClassLoader classLoader, String descriptorFile) throws IOException {
JsonObject descriptor;
try (InputStream is = classLoader.getResourceAsStream(descriptorFile)) {
if (is == null) {
throw new IllegalArgumentException("Cannot find module descriptor file " + descriptorFile + " on classpath");
}
try (Scanner scanner = new Scanner(is, "UTF-8").useDelimiter("\\A")) {
String conf = scanner.next();
descriptor = new JsonObject(conf);
} catch (NoSuchElementException e) {
throw new IllegalArgumentException(descriptorFile + " is empty", e);
} catch (DecodeException e) {
throw new IllegalArgumentException(descriptorFile + " contains invalid json", e);
}
}
return descriptor;
}
use of io.vertx.core.json.DecodeException in project georocket by georocket.
the class GeoRocketCli method config.
@Override
protected JsonObject config() {
JsonObject config = super.config();
if (config == null || config.isEmpty()) {
// load configuration file
File confFile;
if (confFilePath != null) {
confFile = new File(confFilePath);
} else {
File confDir = new File(geoRocketCliHome, "conf");
confFile = new File(confDir, "georocket.yaml");
if (!confFile.exists()) {
confFile = new File(confDir, "georocket.yml");
if (!confFile.exists()) {
confFile = new File(confDir, "georocket.json");
}
}
}
config = new JsonObject();
try {
String confFileStr = FileUtils.readFileToString(confFile, "UTF-8");
if (confFile.getName().endsWith(".json")) {
config = new JsonObject(confFileStr);
} else {
Yaml yaml = new Yaml();
@SuppressWarnings("unchecked") Map<String, Object> m = yaml.loadAs(confFileStr, Map.class);
config = JsonUtils.flatten(new JsonObject(m));
}
} catch (IOException e) {
System.err.println("Could not read config file " + confFile + ": " + e.getMessage());
System.exit(1);
} catch (DecodeException e) {
System.err.println("Invalid config file: " + e.getMessage());
System.exit(1);
}
// set default values
if (!config.containsKey(ConfigConstants.HOST)) {
config.put(ConfigConstants.HOST, GeoRocketClient.DEFAULT_HOST);
}
if (!config.containsKey(ConfigConstants.PORT)) {
config.put(ConfigConstants.PORT, GeoRocketClient.DEFAULT_PORT);
}
// overwrite with values from command line
if (host != null) {
config.put(ConfigConstants.HOST, host);
}
if (port != null) {
config.put(ConfigConstants.PORT, port);
}
setConfig(config);
}
return config;
}
Aggregations