Search in sources :

Example 16 with DecodeException

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);
}
Also used : DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor) DecodeException(io.vertx.core.json.DecodeException) Test(org.junit.Test)

Example 17 with DecodeException

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);
}
Also used : DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor) DecodeException(io.vertx.core.json.DecodeException) Test(org.junit.Test)

Example 18 with DecodeException

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);
}
Also used : RoutingEntry(org.folio.okapi.bean.RoutingEntry) DecodeException(io.vertx.core.json.DecodeException) Test(org.junit.Test)

Example 19 with DecodeException

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;
}
Also used : Scanner(java.util.Scanner) InputStream(java.io.InputStream) JsonObject(io.vertx.core.json.JsonObject) DecodeException(io.vertx.core.json.DecodeException) NoSuchElementException(java.util.NoSuchElementException)

Example 20 with DecodeException

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;
}
Also used : JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) IOException(java.io.IOException) File(java.io.File) DecodeException(io.vertx.core.json.DecodeException) Yaml(org.yaml.snakeyaml.Yaml)

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