use of org.thingsboard.server.extensions.core.plugin.rpc.LocalRequestMetaData in project thingsboard by thingsboard.
the class RpcRestMsgHandler method handleDeviceRPCRequest.
private boolean handleDeviceRPCRequest(PluginContext ctx, final PluginRestMsg msg, TenantId tenantId, DeviceId deviceId, RpcRequest cmd, boolean oneWay) throws JsonProcessingException {
long timeout = System.currentTimeMillis() + (cmd.getTimeout() != null ? cmd.getTimeout() : defaultTimeout);
ToDeviceRpcRequestBody body = new ToDeviceRpcRequestBody(cmd.getMethodName(), cmd.getRequestData());
ctx.checkAccess(deviceId, new PluginCallback<Void>() {
@Override
public void onSuccess(PluginContext ctx, Void value) {
ToDeviceRpcRequest rpcRequest = new ToDeviceRpcRequest(UUID.randomUUID(), msg.getSecurityCtx(), tenantId, deviceId, oneWay, timeout, body);
rpcManager.process(ctx, new LocalRequestMetaData(rpcRequest, msg.getResponseHolder()));
}
@Override
public void onFailure(PluginContext ctx, Exception e) {
ResponseEntity response;
if (e instanceof ToErrorResponseEntity) {
response = ((ToErrorResponseEntity) e).toErrorResponseEntity();
} else {
response = new ResponseEntity(HttpStatus.UNAUTHORIZED);
}
ctx.logRpcRequest(msg.getSecurityCtx(), deviceId, body, oneWay, Optional.empty(), e);
msg.getResponseHolder().setResult(response);
}
});
return true;
}
Aggregations