use of io.vertx.core.json.DecodeException in project mod-inventory-storage by folio-org.
the class LoanTypeTest method send.
private JsonObject send(URL url, HttpMethod method, String content, int expectedStatusCode) {
CompletableFuture<Response> future = new CompletableFuture<>();
Handler<HttpClientResponse> handler = ResponseHandler.any(future);
send(url, method, content, handler);
Response response;
try {
response = future.get(5, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new IllegalStateException(e);
}
assertThat(url + " - " + method + " - " + content + ":" + response.getBody(), response.getStatusCode(), is(expectedStatusCode));
try {
return response.getJson();
} catch (DecodeException e) {
// No body at all or not in JSON format.
return null;
}
}
use of io.vertx.core.json.DecodeException in project vert.x by eclipse.
the class BufferTest method testToJsonObject.
@Test
public void testToJsonObject() throws Exception {
JsonObject obj = new JsonObject();
obj.put("wibble", "wibble_value");
obj.put("foo", 5);
obj.put("bar", true);
Buffer buff = Buffer.buffer(obj.encode());
assertEquals(obj, buff.toJsonObject());
buff = Buffer.buffer(TestUtils.randomAlphaString(10));
try {
buff.toJsonObject();
fail();
} catch (DecodeException ignore) {
}
}
use of io.vertx.core.json.DecodeException in project vert.x by eclipse.
the class RunCommand method getConfiguration.
protected JsonObject getConfiguration() {
JsonObject conf;
if (config != null) {
try (Scanner scanner = new Scanner(new File(config)).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 null;
}
} catch (FileNotFoundException e) {
try {
conf = new JsonObject(config);
} catch (DecodeException e2) {
// The configuration is not printed for security purpose, it can contain sensitive data.
log.error("The -conf option does not point to an existing file or is not a valid JSON object");
e2.printStackTrace();
return null;
}
}
} else {
conf = null;
}
return conf;
}
use of io.vertx.core.json.DecodeException in project hono by eclipse.
the class RegistrationTestSupport method send.
private CompletableFuture<RegistrationResult> send(final String deviceId, final String action, final Integer expectedStatus) {
try {
final String correlationId = UUID.randomUUID().toString();
final Message message = session.createMessage();
message.setStringProperty(MessageHelper.APP_PROPERTY_DEVICE_ID, deviceId);
message.setJMSType(action);
message.setJMSReplyTo(reply);
message.setJMSCorrelationID(correlationId);
LOGGER.debug("adding response handler for request [correlation ID: {}]", correlationId);
final CompletableFuture<RegistrationResult> result = c.add(correlationId, response -> {
final Integer status = getIntProperty(response, MessageHelper.APP_PROPERTY_STATUS);
LOGGER.debug("received response [type: {}, status: {}] for request [correlation ID: {}]", response.getClass().getName(), status, correlationId);
int httpStatus = status;
if (status == null || httpStatus <= 0) {
throw new IllegalStateException("Response to " + getMessageID(response) + " contained no valid status: " + httpStatus);
}
if (expectedStatus != null && expectedStatus != httpStatus) {
throw new IllegalStateException("returned status " + httpStatus);
}
try {
if (response.isBodyAssignableTo(String.class)) {
String body = response.getBody(String.class);
if (body != null) {
LOGGER.debug("extracting response body");
return RegistrationResult.from(httpStatus, new JsonObject(body));
}
}
} catch (JMSException | DecodeException e) {
LOGGER.debug("cannot extract body from response", e);
}
return RegistrationResult.from(httpStatus);
});
producer.send(message);
return result;
} catch (final JMSException jmsException) {
throw new IllegalStateException("Failed to send message.", jmsException);
}
}
use of io.vertx.core.json.DecodeException in project hono by eclipse.
the class FileBasedCredentialsService method addAll.
private Future<Void> addAll(final Buffer credentials) {
Future<Void> result = Future.future();
try {
int credentialsCount = 0;
final JsonArray allObjects = credentials.toJsonArray();
log.debug("trying to load credentials for {} tenants", allObjects.size());
for (Object obj : allObjects) {
if (JsonObject.class.isInstance(obj)) {
credentialsCount += addCredentialsForTenant((JsonObject) obj);
}
}
log.info("successfully loaded {} credentials from file [{}]", credentialsCount, getConfig().getFilename());
result.complete();
} catch (DecodeException e) {
log.warn("cannot read malformed JSON from credentials file [{}]", getConfig().getFilename());
result.fail(e);
}
return result;
}
Aggregations