|
@@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
|
@@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
20
|
import com.google.common.util.concurrent.FutureCallback;
|
20
|
import com.google.common.util.concurrent.FutureCallback;
|
21
|
import lombok.extern.slf4j.Slf4j;
|
21
|
import lombok.extern.slf4j.Slf4j;
|
22
|
import org.springframework.beans.factory.annotation.Autowired;
|
22
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
23
|
+import org.springframework.beans.factory.annotation.Value;
|
23
|
import org.springframework.http.HttpStatus;
|
24
|
import org.springframework.http.HttpStatus;
|
24
|
import org.springframework.http.ResponseEntity;
|
25
|
import org.springframework.http.ResponseEntity;
|
25
|
import org.springframework.security.access.prepost.PreAuthorize;
|
26
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
@@ -65,7 +66,6 @@ import java.util.UUID; |
|
@@ -65,7 +66,6 @@ import java.util.UUID; |
65
|
@Slf4j
|
66
|
@Slf4j
|
66
|
public class RpcController extends BaseController {
|
67
|
public class RpcController extends BaseController {
|
67
|
|
68
|
|
68
|
- public static final int DEFAULT_TIMEOUT = 10000;
|
|
|
69
|
protected final ObjectMapper jsonMapper = new ObjectMapper();
|
69
|
protected final ObjectMapper jsonMapper = new ObjectMapper();
|
70
|
|
70
|
|
71
|
@Autowired
|
71
|
@Autowired
|
|
@@ -74,6 +74,12 @@ public class RpcController extends BaseController { |
|
@@ -74,6 +74,12 @@ public class RpcController extends BaseController { |
74
|
@Autowired
|
74
|
@Autowired
|
75
|
private AccessValidator accessValidator;
|
75
|
private AccessValidator accessValidator;
|
76
|
|
76
|
|
|
|
77
|
+ @Value("${server.rest.server_side_rpc.min_timeout:5000}")
|
|
|
78
|
+ private long minTimeout;
|
|
|
79
|
+
|
|
|
80
|
+ @Value("${server.rest.server_side_rpc.default_timeout:10000}")
|
|
|
81
|
+ private long defaultTimeout;
|
|
|
82
|
+
|
77
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
83
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
78
|
@RequestMapping(value = "/oneway/{deviceId}", method = RequestMethod.POST)
|
84
|
@RequestMapping(value = "/oneway/{deviceId}", method = RequestMethod.POST)
|
79
|
@ResponseBody
|
85
|
@ResponseBody
|
|
@@ -100,7 +106,8 @@ public class RpcController extends BaseController { |
|
@@ -100,7 +106,8 @@ public class RpcController extends BaseController { |
100
|
SecurityUser currentUser = getCurrentUser();
|
106
|
SecurityUser currentUser = getCurrentUser();
|
101
|
TenantId tenantId = currentUser.getTenantId();
|
107
|
TenantId tenantId = currentUser.getTenantId();
|
102
|
final DeferredResult<ResponseEntity> response = new DeferredResult<>();
|
108
|
final DeferredResult<ResponseEntity> response = new DeferredResult<>();
|
103
|
- long timeout = System.currentTimeMillis() + (cmd.getTimeout() != null ? cmd.getTimeout() : DEFAULT_TIMEOUT);
|
109
|
+ long timeout = cmd.getTimeout() != null ? cmd.getTimeout() : defaultTimeout;
|
|
|
110
|
+ long expTime = System.currentTimeMillis() + Math.max(minTimeout, timeout);
|
104
|
ToDeviceRpcRequestBody body = new ToDeviceRpcRequestBody(cmd.getMethodName(), cmd.getRequestData());
|
111
|
ToDeviceRpcRequestBody body = new ToDeviceRpcRequestBody(cmd.getMethodName(), cmd.getRequestData());
|
105
|
accessValidator.validate(currentUser, Operation.RPC_CALL, deviceId, new HttpValidationCallback(response, new FutureCallback<DeferredResult<ResponseEntity>>() {
|
112
|
accessValidator.validate(currentUser, Operation.RPC_CALL, deviceId, new HttpValidationCallback(response, new FutureCallback<DeferredResult<ResponseEntity>>() {
|
106
|
@Override
|
113
|
@Override
|
|
@@ -109,7 +116,7 @@ public class RpcController extends BaseController { |
|
@@ -109,7 +116,7 @@ public class RpcController extends BaseController { |
109
|
tenantId,
|
116
|
tenantId,
|
110
|
deviceId,
|
117
|
deviceId,
|
111
|
oneWay,
|
118
|
oneWay,
|
112
|
- timeout,
|
119
|
+ expTime,
|
113
|
body
|
120
|
body
|
114
|
);
|
121
|
);
|
115
|
deviceRpcService.processRestApiRpcRequest(rpcRequest, fromDeviceRpcResponse -> reply(new LocalRequestMetaData(rpcRequest, currentUser, result), fromDeviceRpcResponse));
|
122
|
deviceRpcService.processRestApiRpcRequest(rpcRequest, fromDeviceRpcResponse -> reply(new LocalRequestMetaData(rpcRequest, currentUser, result), fromDeviceRpcResponse));
|