use of io.vertx.core.json.DecodeException in project okapi by folio-org.
the class InternalModule method createTenant.
private void createTenant(ProxyContext pc, String body, Handler<ExtendedAsyncResult<String>> fut) {
try {
final TenantDescriptor td = Json.decodeValue(body, TenantDescriptor.class);
if (td.getId() == null || td.getId().isEmpty()) {
td.setId(UUID.randomUUID().toString());
}
final String id = td.getId();
if (!id.matches("^[a-z0-9_-]+$")) {
fut.handle(new Failure<>(USER, "Invalid tenant id '" + id + "'"));
return;
}
Tenant t = new Tenant(td);
tenantManager.insert(t, res -> {
if (res.failed()) {
fut.handle(new Failure<>(res.getType(), res.cause()));
return;
}
location(pc, id, null, Json.encodePrettily(t.getDescriptor()), fut);
});
} catch (DecodeException ex) {
fut.handle(new Failure<>(USER, ex));
}
}
use of io.vertx.core.json.DecodeException in project okapi by folio-org.
the class InternalModule method updateModule.
private void updateModule(ProxyContext pc, String id, String body, Handler<ExtendedAsyncResult<String>> fut) {
try {
final ModuleDescriptor md = Json.decodeValue(body, ModuleDescriptor.class);
if (!id.equals(md.getId())) {
fut.handle(new Failure<>(USER, "Module.id=" + md.getId() + " id=" + id));
return;
}
String validerr = md.validate(pc);
if (!validerr.isEmpty()) {
fut.handle(new Failure<>(USER, validerr));
return;
}
moduleManager.update(md, res -> {
if (res.failed()) {
fut.handle(new Failure<>(res.getType(), res.cause()));
return;
}
final String s = Json.encodePrettily(md);
fut.handle(new Success<>(s));
});
} catch (DecodeException ex) {
fut.handle(new Failure<>(USER, ex));
}
}
use of io.vertx.core.json.DecodeException in project okapi by folio-org.
the class BeanTest method testModuleDescriptor1.
@Test
public void testModuleDescriptor1() {
int fail = 0;
final String docModuleDescriptor = "{" + LS + " \"id\" : \"sample-module-1\"," + LS + " \"name\" : \"sample module\"," + LS + " \"provides\" : [ {" + LS + " \"id\" : \"sample\"," + LS + " \"version\" : \"1.0.0\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\" ]," + LS + " \"pathPattern\" : \"/users/{id}\"," + LS + " \"level\" : \"30\"," + LS + " \"type\" : \"request-response\"," + LS + " \"permissionsRequired\" : [ \"sample.needed\" ]," + LS + " \"permissionsDesired\" : [ \"sample.extra\" ]," + LS + " \"modulePermissions\" : [ \"sample.modperm\" ]" + LS + " } ]" + LS + " }, {" + LS + " \"id\" : \"_tenant\"," + LS + " \"version\" : \"1.0.0\"," + LS + " \"interfaceType\" : \"system\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"POST\", \"DELETE\" ]," + LS + " \"path\" : \"/_/tenant\"," + LS + " \"level\" : \"10\"," + LS + " \"type\" : \"system\"" + LS + " } ]" + LS + " } ]" + LS + "}";
try {
final ModuleDescriptor md = Json.decodeValue(docModuleDescriptor, ModuleDescriptor.class);
String pretty = Json.encodePrettily(md);
assertEquals(docModuleDescriptor, 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 testDeploymentDescriptor4.
@Test
public void testDeploymentDescriptor4() {
int fail = 0;
final String docSampleDeployment = "{" + LS + " \"srvcId\" : \"sample-module-1\"," + LS + " \"descriptor\" : {" + LS + " \"dockerImage\" : \"my-image\"," + LS + " \"dockerArgs\" : {" + LS + " \"Hostname\" : \"localhost\"," + LS + " \"User\" : \"nobody\"" + 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 testDeploymentDescriptor1.
@Test
public void testDeploymentDescriptor1() {
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 + " \"value\" : \"hej\"" + 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);
}
Aggregations