use of io.vertx.core.json.DecodeException in project okapi by folio-org.
the class OkapiToken method getPayload.
private JsonObject getPayload() {
String encodedJson;
try {
encodedJson = this.token.split("\\.")[1];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException(e.getMessage());
}
String decodedJson = new String(Base64.getDecoder().decode(encodedJson));
JsonObject j;
try {
j = new JsonObject(decodedJson);
} catch (DecodeException e) {
throw new IllegalArgumentException(e.getMessage());
}
return j;
}
use of io.vertx.core.json.DecodeException in project enmasse-workshop by EnMasseProject.
the class HeatingDevice method connected.
private void connected(AsyncResult<Client> done) {
if (done.succeeded()) {
log.info("Connected to the service");
Client client = done.result();
client.receivedHandler(messageDelivery -> {
try {
JsonObject json = new JsonObject(Buffer.buffer(messageDelivery.message()));
log.info("Received message on {} with payload {}", messageDelivery.address(), json);
String deviceId = json.getString("device-id");
if (!deviceId.equals(this.config.getProperty(DeviceConfig.DEVICE_ID))) {
log.error("Received control message for some other device with id {}", deviceId);
} else {
String operation = json.getString("operation");
if ("open".equals(json)) {
valve.open();
} else if ("close".equals(operation)) {
valve.close();
}
}
} catch (DecodeException e) {
log.error("Error decoding message, discarded !", e);
}
});
String controlAddress = this.config.getProperty(DeviceConfig.CONTROL_ADDRESS);
log.info("Registering to receive on {}", controlAddress);
client.receive(controlAddress);
int updateInterval = Integer.valueOf(this.config.getProperty(DeviceConfig.UPDATE_INTERVAL));
String temperatureAddress = this.config.getProperty(DeviceConfig.TEMPERATURE_ADDRESS);
this.vertx.setPeriodic(updateInterval, t -> {
int temperature = this.dht22.getTemperature();
JsonObject json = new JsonObject();
json.put("device-id", this.config.getProperty(DeviceConfig.DEVICE_ID));
json.put("temperature", temperature);
log.info("Sending temperature value = {} ...", temperature);
client.send(temperatureAddress, json.toString().getBytes(), v -> {
log.info("... sent {}", v);
});
});
} else {
log.error("Error connecting to the service", done.cause());
}
}
Aggregations