Commit 10c32f63da47fa52aa7a6cbee2af025313301fc4

Authored by Andrew Shvayka
Committed by GitHub
2 parents 8f2217d9 d4236dc2

Merge pull request #68 from thingsboard/feature/TB-44

TB-44: Major bug in RPC functionality
... ... @@ -25,6 +25,8 @@ import org.springframework.util.StringUtils;
25 25 import org.springframework.web.context.request.async.DeferredResult;
26 26 import org.thingsboard.server.common.data.DataConstants;
27 27 import org.thingsboard.server.common.data.id.DeviceId;
  28 +import org.thingsboard.server.common.data.id.TenantId;
  29 +import org.thingsboard.server.extensions.api.plugins.PluginApiCallSecurityContext;
28 30 import org.thingsboard.server.extensions.api.plugins.PluginCallback;
29 31 import org.thingsboard.server.extensions.api.plugins.PluginContext;
30 32 import org.thingsboard.server.extensions.api.plugins.handlers.DefaultRestMsgHandler;
... ... @@ -40,6 +42,7 @@ import org.thingsboard.server.extensions.core.plugin.rpc.cmd.RpcRequest;
40 42
41 43 import javax.servlet.ServletException;
42 44 import java.io.IOException;
  45 +import java.util.Optional;
43 46 import java.util.UUID;
44 47
45 48 /**
... ... @@ -67,17 +70,19 @@ public class RpcRestMsgHandler extends DefaultRestMsgHandler {
67 70
68 71 RpcRequest cmd = new RpcRequest(rpcRequestBody.get("method").asText(),
69 72 jsonMapper.writeValueAsString(rpcRequestBody.get("params")));
  73 + if (rpcRequestBody.has("timeout")) {
  74 + cmd.setTimeout(rpcRequestBody.get("timeout").asLong());
  75 + }
  76 +
  77 + final TenantId tenantId = ctx.getSecurityCtx().orElseThrow(() -> new IllegalStateException("Security context is empty!")).getTenantId();
70 78
71 79 ctx.checkAccess(deviceId, new PluginCallback<Void>() {
72 80 @Override
73 81 public void onSuccess(PluginContext ctx, Void value) {
74   - if (rpcRequestBody.has("timeout")) {
75   - cmd.setTimeout(rpcRequestBody.get("timeout").asLong());
76   - }
77 82 long timeout = cmd.getTimeout() != null ? cmd.getTimeout() : defaultTimeout;
78 83 ToDeviceRpcRequestBody body = new ToDeviceRpcRequestBody(cmd.getMethodName(), cmd.getRequestData());
79 84 ToDeviceRpcRequest rpcRequest = new ToDeviceRpcRequest(UUID.randomUUID(),
80   - ctx.getSecurityCtx().orElseThrow(() -> new IllegalStateException("Security context is empty!")).getTenantId(),
  85 + tenantId,
81 86 deviceId,
82 87 DataConstants.ONEWAY.equals(method),
83 88 System.currentTimeMillis() + timeout,
... ...