@HiveWebsocketAuth @PreAuthorize("isAuthenticated() and hasPermission(#deviceId, 'GET_DEVICE_COMMAND')") public void processCommandList(String deviceId, JsonObject request, WebSocketSession session) { CommandSearchRequest commandSearchRequest = createCommandSearchRequest(request); if (deviceId == null) { logger.error("command/list proceed with error. Device ID should be provided."); throw new HiveException(DEVICE_ID_REQUIRED, SC_BAD_REQUEST); } logger.debug("Device command query requested for device {}", deviceId); DeviceVO device = deviceService.findById(deviceId); if (device == null) { logger.error("command/list proceed with error. No Device with Device ID = {} found.", deviceId); throw new HiveException(String.format(DEVICE_NOT_FOUND, deviceId), SC_NOT_FOUND); } WebSocketResponse response = new WebSocketResponse(); commandService.find(commandSearchRequest) .thenAccept(sortedDeviceCommands -> { response.addValue(COMMANDS, sortedDeviceCommands, COMMAND_LISTED); clientHandler.sendMessage(request, response, session); }) .exceptionally(ex -> { logger.warn("Unable to get commands list.", ex); throw new HiveException(Messages.INTERNAL_SERVER_ERROR, SC_INTERNAL_SERVER_ERROR); }); }