Search in sources :

Example 1 with RpcError

use of org.thingsboard.server.common.data.rpc.RpcError in project thingsboard by thingsboard.

the class AbstractRpcController method reply.

public void reply(LocalRequestMetaData rpcRequest, FromDeviceRpcResponse response, HttpStatus timeoutStatus, HttpStatus noActiveConnectionStatus) {
    Optional<RpcError> rpcError = response.getError();
    DeferredResult<ResponseEntity> responseWriter = rpcRequest.getResponseWriter();
    if (rpcError.isPresent()) {
        logRpcCall(rpcRequest, rpcError, null);
        RpcError error = rpcError.get();
        switch(error) {
            case TIMEOUT:
                responseWriter.setResult(new ResponseEntity<>(timeoutStatus));
                break;
            case NO_ACTIVE_CONNECTION:
                responseWriter.setResult(new ResponseEntity<>(noActiveConnectionStatus));
                break;
            default:
                responseWriter.setResult(new ResponseEntity<>(timeoutStatus));
                break;
        }
    } else {
        Optional<String> responseData = response.getResponse();
        if (responseData.isPresent() && !StringUtils.isEmpty(responseData.get())) {
            String data = responseData.get();
            try {
                logRpcCall(rpcRequest, rpcError, null);
                responseWriter.setResult(new ResponseEntity<>(JacksonUtil.toJsonNode(data), HttpStatus.OK));
            } catch (IllegalArgumentException e) {
                log.debug("Failed to decode device response: {}", data, e);
                logRpcCall(rpcRequest, rpcError, e);
                responseWriter.setResult(new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE));
            }
        } else {
            logRpcCall(rpcRequest, rpcError, null);
            responseWriter.setResult(new ResponseEntity<>(HttpStatus.OK));
        }
    }
}
Also used : ToErrorResponseEntity(org.thingsboard.server.service.telemetry.exception.ToErrorResponseEntity) ResponseEntity(org.springframework.http.ResponseEntity) RpcError(org.thingsboard.server.common.data.rpc.RpcError)

Example 2 with RpcError

use of org.thingsboard.server.common.data.rpc.RpcError in project thingsboard by thingsboard.

the class DefaultTbRuleEngineConsumerService method handleNotification.

@Override
protected void handleNotification(UUID id, TbProtoQueueMsg<ToRuleEngineNotificationMsg> msg, TbCallback callback) throws Exception {
    ToRuleEngineNotificationMsg nfMsg = msg.getValue();
    if (nfMsg.getComponentLifecycleMsg() != null && !nfMsg.getComponentLifecycleMsg().isEmpty()) {
        handleComponentLifecycleMsg(id, nfMsg.getComponentLifecycleMsg());
        callback.onSuccess();
    } else if (nfMsg.hasFromDeviceRpcResponse()) {
        TransportProtos.FromDeviceRPCResponseProto proto = nfMsg.getFromDeviceRpcResponse();
        RpcError error = proto.getError() > 0 ? RpcError.values()[proto.getError()] : null;
        FromDeviceRpcResponse response = new FromDeviceRpcResponse(new UUID(proto.getRequestIdMSB(), proto.getRequestIdLSB()), proto.getResponse(), error);
        tbDeviceRpcService.processRpcResponseFromDevice(response);
        callback.onSuccess();
    } else {
        log.trace("Received notification with missing handler");
        callback.onSuccess();
    }
}
Also used : FromDeviceRpcResponse(org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse) ToRuleEngineNotificationMsg(org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg) RpcError(org.thingsboard.server.common.data.rpc.RpcError) UUID(java.util.UUID)

Example 3 with RpcError

use of org.thingsboard.server.common.data.rpc.RpcError in project thingsboard by thingsboard.

the class DefaultTbCoreConsumerService method forwardToCoreRpcService.

private void forwardToCoreRpcService(FromDeviceRPCResponseProto proto, TbCallback callback) {
    RpcError error = proto.getError() > 0 ? RpcError.values()[proto.getError()] : null;
    FromDeviceRpcResponse response = new FromDeviceRpcResponse(new UUID(proto.getRequestIdMSB(), proto.getRequestIdLSB()), proto.getResponse(), error);
    tbCoreDeviceRpcService.processRpcResponseFromRuleEngine(response);
    callback.onSuccess();
}
Also used : FromDeviceRpcResponse(org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse) RpcError(org.thingsboard.server.common.data.rpc.RpcError) UUID(java.util.UUID)

Aggregations

RpcError (org.thingsboard.server.common.data.rpc.RpcError)3 UUID (java.util.UUID)2 FromDeviceRpcResponse (org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse)2 ResponseEntity (org.springframework.http.ResponseEntity)1 ToRuleEngineNotificationMsg (org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg)1 ToErrorResponseEntity (org.thingsboard.server.service.telemetry.exception.ToErrorResponseEntity)1