use of io.swagger.server.api.MainApiException in project azure-iot-sdk-java by Azure.
the class ModuleGlue method waitForDesiredPropertyPatch.
public void waitForDesiredPropertyPatch(String connectionId, Handler<AsyncResult<Object>> handler) {
System.out.printf("waitForDesiredPropertyPatch with %s%n", connectionId);
ModuleClient client = getClient(connectionId);
if (client == null) {
handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id")));
} else {
this._deviceTwinPropertyCallback.setHandler(res -> {
if (res.succeeded()) {
JsonObject obj = (JsonObject) res.result();
Object desiredProps = obj.getJsonObject("properties").getJsonObject("desired");
handler.handle(Future.succeededFuture(desiredProps));
} else {
handler.handle(res);
}
});
}
}
use of io.swagger.server.api.MainApiException in project azure-iot-sdk-java by Azure.
the class ServiceGlue method invokeMethodCommon.
private void invokeMethodCommon(String connectionId, String deviceId, String moduleId, Object methodInvokeParameters, Handler<AsyncResult<Object>> handler) {
System.out.printf("invoking method on %s with deviceId = %s moduleId = %s%n", connectionId, deviceId, moduleId);
System.out.println(methodInvokeParameters);
DeviceMethod client = getClient(connectionId);
if (client == null) {
handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id")));
} else {
JsonObject params = (JsonObject) methodInvokeParameters;
String methodName = params.getString("methodName");
String payload = params.getString("payload");
Long responseTimeout = params.getLong("responseTimeoutInSeconds", 0L);
Long connectionTimeout = params.getLong("connectTimeoutInSeconds", 0L);
MethodResult result = null;
System.out.printf("invoking%n");
try {
if (moduleId == null) {
result = client.invoke(deviceId, methodName, responseTimeout, connectionTimeout, payload);
} else {
result = client.invoke(deviceId, moduleId, methodName, responseTimeout, connectionTimeout, payload);
}
} catch (IotHubException e) {
handler.handle(Future.failedFuture(e));
} catch (IOException e) {
e.printStackTrace();
}
System.out.printf("invoke returned%n");
System.out.println(result);
handler.handle(Future.succeededFuture(result));
}
}
use of io.swagger.server.api.MainApiException in project azure-iot-sdk-java by Azure.
the class RegistryGlue method sendModuleTwinPatch.
public void sendModuleTwinPatch(String connectionId, String deviceId, String moduleId, Object props, Handler<AsyncResult<Void>> handler) {
System.out.printf("sendModuleTwinPatch called for %s with deviceId = %s and moduleId = %s%n", connectionId, deviceId, moduleId);
System.out.println(props.toString());
DeviceTwin client = getClient(connectionId);
if (client == null) {
handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id")));
} else {
DeviceTwinDevice twin = new DeviceTwinDevice(deviceId, moduleId);
Set<Pair> newProps = new HashSet<>();
Map<String, Object> desiredProps = ((JsonObject) props).getJsonObject("properties").getJsonObject("desired").getMap();
for (String key : desiredProps.keySet()) {
newProps.add(new Pair(key, desiredProps.get(key)));
}
twin.setDesiredProperties(newProps);
try {
client.updateTwin(twin);
} catch (IotHubException | IOException e) {
handler.handle(Future.failedFuture(e));
}
handler.handle(Future.succeededFuture());
}
}
Aggregations