Cleanups to REST code suggested by Sonar
Change-Id: Ia399da70e7cd140514e07b63d9b2965fe86bbce7
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
index f77bb43..45529a4 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
@@ -142,21 +142,21 @@
InputStream stream) {
URI location;
try {
- FlowRuleService service = get(FlowRuleService.class);
- ObjectNode root = (ObjectNode) mapper().readTree(stream);
- JsonNode specifiedDeviceId = root.get("deviceId");
+ ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ JsonNode specifiedDeviceId = jsonTree.get("deviceId");
if (specifiedDeviceId != null &&
!specifiedDeviceId.asText().equals(deviceId)) {
throw new IllegalArgumentException(
"Invalid deviceId in flow creation request");
}
- root.put("deviceId", deviceId);
- FlowRule rule = codec(FlowRule.class).decode(root, this);
+ jsonTree.put("deviceId", deviceId);
+ FlowRule rule = codec(FlowRule.class).decode(jsonTree, this);
service.applyFlowRules(rule);
location = new URI(Long.toString(rule.id().value()));
} catch (IOException | URISyntaxException ex) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+ throw new IllegalArgumentException(ex);
}
+
return Response
.created(location)
.build();