Improve validation of request body for Telemetry Rest Calls.
This commit is contained in:
parent
582ef1f63c
commit
d644d2d5fd
@ -217,7 +217,9 @@ public class TelemetryRestMsgHandler extends DefaultRestMsgHandler {
|
||||
JsonNode jsonNode = jsonMapper.readTree(request.getRequestBody());
|
||||
if (jsonNode.isObject()) {
|
||||
List<AttributeKvEntry> attributes = extractRequestAttributes(jsonNode);
|
||||
if (!attributes.isEmpty()) {
|
||||
if (attributes.isEmpty()) {
|
||||
throw new IllegalArgumentException("No attributes data found in request body!");
|
||||
}
|
||||
ctx.saveAttributes(ctx.getSecurityCtx().orElseThrow(IllegalArgumentException::new).getTenantId(), entityId, scope, attributes, new PluginCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(PluginContext ctx, Void value) {
|
||||
@ -234,7 +236,6 @@ public class TelemetryRestMsgHandler extends DefaultRestMsgHandler {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -269,6 +270,9 @@ public class TelemetryRestMsgHandler extends DefaultRestMsgHandler {
|
||||
throw new UncheckedApiException(new InvalidParametersException(e.getMessage()));
|
||||
}
|
||||
List<TsKvEntry> entries = new ArrayList<>();
|
||||
if (entries.isEmpty()) {
|
||||
throw new IllegalArgumentException("No timeseries data found in request body!");
|
||||
}
|
||||
for (Map.Entry<Long, List<KvEntry>> entry : telemetryRequest.getData().entrySet()) {
|
||||
for (KvEntry kv : entry.getValue()) {
|
||||
entries.add(new BasicTsKvEntry(entry.getKey(), kv));
|
||||
@ -399,6 +403,8 @@ public class TelemetryRestMsgHandler extends DefaultRestMsgHandler {
|
||||
ResponseEntity responseEntity;
|
||||
if (e != null && e instanceof ToErrorResponseEntity) {
|
||||
responseEntity = ((ToErrorResponseEntity) e).toErrorResponseEntity();
|
||||
} else if (e != null && e instanceof IllegalArgumentException) {
|
||||
responseEntity = new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
|
||||
} else {
|
||||
responseEntity = new ResponseEntity<>(defaultErrorStatus);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user