Upgrade fasterXML libraries for OS-9
Upgrade fasterXML to version 2.9.5 to address security vulnerability
Wrap calls to treeRead(InputStream) to handle new behavior of null streams
Change-Id: Id199cfacd0cf9e5371dc33de9f1e058c2e72eaa5
diff --git a/apps/acl/src/main/java/org/onosproject/acl/AclWebResource.java b/apps/acl/src/main/java/org/onosproject/acl/AclWebResource.java
index ff58ba6..0cda20b 100644
--- a/apps/acl/src/main/java/org/onosproject/acl/AclWebResource.java
+++ b/apps/acl/src/main/java/org/onosproject/acl/AclWebResource.java
@@ -42,6 +42,8 @@
import java.net.URISyntaxException;
import java.util.List;
+import static org.onlab.util.Tools.readTreeFromStream;
+
/**
* Manage ACL rules.
*/
@@ -141,7 +143,7 @@
private AclRule jsonToRule(InputStream stream) {
JsonNode node;
try {
- node = mapper().readTree(stream);
+ node = readTreeFromStream(mapper(), stream);
} catch (IOException e) {
throw new IllegalArgumentException("Unable to parse ACL request", e);
}
diff --git a/apps/cfm/src/main/java/org/onosproject/cfm/rest/MaWebResource.java b/apps/cfm/src/main/java/org/onosproject/cfm/rest/MaWebResource.java
index 85b7ac4..2ccfc7d 100644
--- a/apps/cfm/src/main/java/org/onosproject/cfm/rest/MaWebResource.java
+++ b/apps/cfm/src/main/java/org/onosproject/cfm/rest/MaWebResource.java
@@ -46,6 +46,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import static org.onlab.util.Tools.readTreeFromStream;
+
/**
* Layer 2 CFM Maintenance Association web resource.
*/
@@ -142,7 +144,7 @@
}
ObjectMapper mapper = new ObjectMapper();
- JsonNode cfg = mapper.readTree(input);
+ JsonNode cfg = readTreeFromStream(mapper, input);
JsonCodec<MaintenanceAssociation> maCodec =
codec(MaintenanceAssociation.class);
diff --git a/apps/cfm/src/main/java/org/onosproject/cfm/rest/MdWebResource.java b/apps/cfm/src/main/java/org/onosproject/cfm/rest/MdWebResource.java
index c642f4a..af85aca 100644
--- a/apps/cfm/src/main/java/org/onosproject/cfm/rest/MdWebResource.java
+++ b/apps/cfm/src/main/java/org/onosproject/cfm/rest/MdWebResource.java
@@ -43,6 +43,8 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import static org.onlab.util.Tools.readTreeFromStream;
+
/**
* Layer 2 CFM Maintenance Domain web resource.
*/
@@ -136,7 +138,7 @@
log.debug("POST called to Create MD");
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode cfg = mapper.readTree(input);
+ JsonNode cfg = readTreeFromStream(mapper, input);
MaintenanceDomain md = codec(MaintenanceDomain.class).decode((ObjectNode) cfg, this);
if (get(CfmMdService.class).createMaintenanceDomain(md)) {
diff --git a/apps/cfm/src/main/java/org/onosproject/cfm/rest/MepWebResource.java b/apps/cfm/src/main/java/org/onosproject/cfm/rest/MepWebResource.java
index fa8c728..0edad53 100644
--- a/apps/cfm/src/main/java/org/onosproject/cfm/rest/MepWebResource.java
+++ b/apps/cfm/src/main/java/org/onosproject/cfm/rest/MepWebResource.java
@@ -55,6 +55,8 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import static org.onlab.util.Tools.readTreeFromStream;
+
/**
* Layer 2 CFM Maintenance Association Endpoint (MEP) web resource.
*/
@@ -182,7 +184,7 @@
MaintenanceAssociation ma = get(CfmMdService.class).getMaintenanceAssociation(mdId, maId).get();
ObjectMapper mapper = new ObjectMapper();
- JsonNode cfg = mapper.readTree(input);
+ JsonNode cfg = readTreeFromStream(mapper(), input);
JsonCodec<Mep> mepCodec = codec(Mep.class);
Mep mep = ((MepCodec) mepCodec).decode((ObjectNode) cfg, this, mdName, maName);
@@ -236,7 +238,7 @@
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode cfg = mapper.readTree(input);
+ JsonNode cfg = readTreeFromStream(mapper(), input);
JsonCodec<MepLbCreate> mepLbCreateCodec = codec(MepLbCreate.class);
MepLbCreate lbCreate = mepLbCreateCodec.decode((ObjectNode) cfg, this);
@@ -326,7 +328,7 @@
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode cfg = mapper.readTree(input);
+ JsonNode cfg = readTreeFromStream(mapper, input);
JsonCodec<MepLtCreate> mepLtCreateCodec = codec(MepLtCreate.class);
MepLtCreate ltCreate = mepLtCreateCodec.decode((ObjectNode) cfg, this);
diff --git a/apps/cfm/src/main/java/org/onosproject/soam/rest/DmWebResource.java b/apps/cfm/src/main/java/org/onosproject/soam/rest/DmWebResource.java
index 386ed8c..8677419 100644
--- a/apps/cfm/src/main/java/org/onosproject/soam/rest/DmWebResource.java
+++ b/apps/cfm/src/main/java/org/onosproject/soam/rest/DmWebResource.java
@@ -55,6 +55,8 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import static org.onlab.util.Tools.readTreeFromStream;
+
/**
* Layer 2 SOAM Delay Measurement web resource.
*/
@@ -199,7 +201,7 @@
}
ObjectMapper mapper = new ObjectMapper();
- JsonNode cfg = mapper.readTree(input);
+ JsonNode cfg = readTreeFromStream(mapper, input);
JsonCodec<DelayMeasurementCreate> dmCodec = codec(DelayMeasurementCreate.class);
DelayMeasurementCreate dm = dmCodec.decode((ObjectNode) cfg, this);
diff --git a/apps/cfm/src/main/java/org/onosproject/soam/rest/LmWebResource.java b/apps/cfm/src/main/java/org/onosproject/soam/rest/LmWebResource.java
index 245396c..0c5307f 100644
--- a/apps/cfm/src/main/java/org/onosproject/soam/rest/LmWebResource.java
+++ b/apps/cfm/src/main/java/org/onosproject/soam/rest/LmWebResource.java
@@ -53,6 +53,8 @@
import java.net.URISyntaxException;
import java.util.Collection;
+import static org.onlab.util.Tools.readTreeFromStream;
+
/**
* Layer 2 SOAM Loss Measurement web resource.
*/
@@ -197,7 +199,7 @@
}
ObjectMapper mapper = new ObjectMapper();
- JsonNode cfg = mapper.readTree(input);
+ JsonNode cfg = readTreeFromStream(mapper, input);
JsonCodec<LossMeasurementCreate> lmCodec = codec(LossMeasurementCreate.class);
LossMeasurementCreate lm = lmCodec.decode((ObjectNode) cfg, this);
diff --git a/apps/cpman/app/src/main/java/org/onosproject/cpman/rest/SystemMetricsCollectorWebResource.java b/apps/cpman/app/src/main/java/org/onosproject/cpman/rest/SystemMetricsCollectorWebResource.java
index dc7ea22..0fd18e0 100644
--- a/apps/cpman/app/src/main/java/org/onosproject/cpman/rest/SystemMetricsCollectorWebResource.java
+++ b/apps/cpman/app/src/main/java/org/onosproject/cpman/rest/SystemMetricsCollectorWebResource.java
@@ -46,6 +46,7 @@
import java.util.stream.Collectors;
import static org.onlab.util.Tools.nullIsIllegal;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Collect system metrics.
@@ -90,7 +91,7 @@
ObjectNode root = mapper().createObjectNode();
ControlMetric cm;
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
if (jsonTree == null || !checkFields(jsonTree, CPU_FIELD_SET)) {
return ok(root).build();
@@ -151,7 +152,7 @@
ObjectNode root = mapper().createObjectNode();
ControlMetric cm;
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
if (jsonTree == null || !checkFields(jsonTree, MEMORY_FIELD_SET)) {
return ok(root).build();
@@ -206,7 +207,7 @@
ObjectNode root = mapper().createObjectNode();
ControlMetric cm;
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
ArrayNode diskRes =
jsonTree.get("disks") == null ?
mapper().createArrayNode() : (ArrayNode) jsonTree.get("disks");
@@ -252,7 +253,7 @@
ObjectNode root = mapper().createObjectNode();
ControlMetric cm;
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
ArrayNode networkRes = jsonTree.get("networks") == null
? mapper().createArrayNode() : (ArrayNode) jsonTree.get("networks");
@@ -315,7 +316,7 @@
ObjectNode root = mapper().createObjectNode();
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode numOfCores = jsonTree.get("numOfCores");
JsonNode numOfCpus = jsonTree.get("numOfCpus");
JsonNode cpuSpeed = jsonTree.get("cpuSpeed");
diff --git a/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DhcpWebResource.java b/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DhcpWebResource.java
index 7cae850..fb4ee79 100644
--- a/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DhcpWebResource.java
+++ b/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DhcpWebResource.java
@@ -38,6 +38,7 @@
import java.util.Date;
import java.util.Map;
+import static org.onlab.util.Tools.readTreeFromStream;
import static org.onosproject.dhcp.IpAssignment.AssignmentStatus.Option_Requested;
/**
@@ -118,7 +119,7 @@
public Response setMapping(InputStream stream) {
ObjectNode root = mapper().createObjectNode();
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode macID = jsonTree.get("mac");
JsonNode ip = jsonTree.get("ip");
if (macID != null && ip != null) {
diff --git a/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/AlarmsWebResource.java b/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/AlarmsWebResource.java
index 004f45b..6eb4117 100644
--- a/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/AlarmsWebResource.java
+++ b/apps/faultmanagement/fmweb/src/main/java/org/onosproject/faultmanagement/web/AlarmsWebResource.java
@@ -43,6 +43,7 @@
import org.onosproject.net.DeviceId;
import org.slf4j.Logger;
+import static org.onlab.util.Tools.readTreeFromStream;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -121,7 +122,7 @@
log.debug("PUT NEW ALARM at /{}", alarmIdPath);
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
log.debug("jsonTree={}", jsonTree);
Alarm alarm = new AlarmCodec().decode(jsonTree, this);
diff --git a/apps/kafka-integration/web/src/main/java/org/onosproject/kafkaintegration/rest/EventExporterWebResource.java b/apps/kafka-integration/web/src/main/java/org/onosproject/kafkaintegration/rest/EventExporterWebResource.java
index 155a250..8f2c025 100644
--- a/apps/kafka-integration/web/src/main/java/org/onosproject/kafkaintegration/rest/EventExporterWebResource.java
+++ b/apps/kafka-integration/web/src/main/java/org/onosproject/kafkaintegration/rest/EventExporterWebResource.java
@@ -36,6 +36,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Rest Interfaces for subscribing/unsubscribing to event notifications.
@@ -140,7 +141,7 @@
throws IOException {
ObjectMapper mapper = new ObjectMapper();
- ObjectNode node = (ObjectNode) mapper.readTree(input);
+ ObjectNode node = readTreeFromStream(mapper, input);
checkNotNull(node, JSON_NOT_NULL);
EventSubscriber codec = codec(EventSubscriber.class).decode(node, this);
checkNotNull(codec, JSON_NOT_NULL);
diff --git a/apps/ofagent/src/main/java/org/onosproject/ofagent/rest/OFAgentWebResource.java b/apps/ofagent/src/main/java/org/onosproject/ofagent/rest/OFAgentWebResource.java
index 26ca793..6b9f9eb 100644
--- a/apps/ofagent/src/main/java/org/onosproject/ofagent/rest/OFAgentWebResource.java
+++ b/apps/ofagent/src/main/java/org/onosproject/ofagent/rest/OFAgentWebResource.java
@@ -39,6 +39,7 @@
import java.io.InputStream;
import static javax.ws.rs.core.Response.Status.*;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
@@ -117,7 +118,7 @@
public Response createOFAgent(InputStream stream) throws IOException {
OFAgentAdminService adminService = get(OFAgentAdminService.class);
- OFAgent ofAgent = (new OFAgentCodec()).decode((ObjectNode) mapper().readTree(stream), this);
+ OFAgent ofAgent = (new OFAgentCodec()).decode(readTreeFromStream(mapper(), stream), this);
if (ofAgent == null) {
return Response.status(BAD_REQUEST)
.entity(OFAGENT_NOT_CREATED).build();
@@ -141,7 +142,7 @@
public Response startOFAgent(InputStream stream) throws IOException {
OFAgentAdminService adminService = get(OFAgentAdminService.class);
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode networkId = jsonTree.get("networkId");
if (networkId == null) {
@@ -170,7 +171,7 @@
public Response updateOFAgent(InputStream stream) throws IOException {
OFAgentAdminService adminService = get(OFAgentAdminService.class);
- OFAgent ofAgent = (new OFAgentCodec()).decode((ObjectNode) mapper().readTree(stream), this);
+ OFAgent ofAgent = (new OFAgentCodec()).decode(readTreeFromStream(mapper(), stream), this);
if (ofAgent == null) {
return Response.status(NOT_FOUND)
@@ -199,7 +200,7 @@
public Response stopOFAgent(InputStream stream) throws IOException {
OFAgentAdminService adminService = get(OFAgentAdminService.class);
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode networkId = jsonTree.get("networkId");
if (get(OFAgentService.class).agent(NetworkId.networkId(networkId.asLong())) == null) {
diff --git a/apps/openstacknetworkingui/src/main/java/org/onosproject/openstacknetworkingui/web/FlowTraceWebResource.java b/apps/openstacknetworkingui/src/main/java/org/onosproject/openstacknetworkingui/web/FlowTraceWebResource.java
index d4fbf28..36b5bd3 100644
--- a/apps/openstacknetworkingui/src/main/java/org/onosproject/openstacknetworkingui/web/FlowTraceWebResource.java
+++ b/apps/openstacknetworkingui/src/main/java/org/onosproject/openstacknetworkingui/web/FlowTraceWebResource.java
@@ -37,6 +37,7 @@
import java.io.InputStream;
import static javax.ws.rs.core.Response.status;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Handles REST API from monitoring server.
@@ -58,7 +59,7 @@
@Produces(MediaType.APPLICATION_JSON)
public Response flowTraceResponse(InputStream inputStream) throws IOException {
try {
- JsonNode jsonNode = mapper().enable(SerializationFeature.INDENT_OUTPUT).readTree(inputStream);
+ JsonNode jsonNode = readTreeFromStream(mapper().enable(SerializationFeature.INDENT_OUTPUT), inputStream);
ObjectNode objectNode = jsonNode.deepCopy();
log.debug("FlowTraceResponse: {}", jsonNode.toString());
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeWebResource.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeWebResource.java
index 9d311b2..a729fe5 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeWebResource.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeWebResource.java
@@ -46,6 +46,11 @@
import static com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT;
import static javax.ws.rs.core.Response.created;
+import static org.onlab.util.Tools.readTreeFromStream;
+
+/**
+ * Handles REST API call of openstack node config.
+ */
@Path("configure")
public class OpenstackNodeWebResource extends AbstractWebResource {
@@ -140,7 +145,7 @@
private Set<OpenstackNode> readNodeConfiguration(InputStream input) {
Set<OpenstackNode> nodeSet = Sets.newHashSet();
try {
- JsonNode jsonTree = mapper().enable(INDENT_OUTPUT).readTree(input);
+ JsonNode jsonTree = readTreeFromStream(mapper().enable(INDENT_OUTPUT), input);
ArrayNode nodes = (ArrayNode) jsonTree.path(NODES);
nodes.forEach(node -> {
try {
diff --git a/apps/optical-rest/src/main/java/org/onosproject/net/optical/rest/OpticalIntentsWebResource.java b/apps/optical-rest/src/main/java/org/onosproject/net/optical/rest/OpticalIntentsWebResource.java
index d803fe1..2d16e02 100644
--- a/apps/optical-rest/src/main/java/org/onosproject/net/optical/rest/OpticalIntentsWebResource.java
+++ b/apps/optical-rest/src/main/java/org/onosproject/net/optical/rest/OpticalIntentsWebResource.java
@@ -47,8 +47,10 @@
import static org.slf4j.LoggerFactory.getLogger;
+import static org.onlab.util.Tools.readTreeFromStream;
import static org.onosproject.net.optical.util.OpticalIntentUtility.createOpticalIntent;
+
/**
* Query, submit and withdraw optical network intents.
*/
@@ -91,7 +93,7 @@
public Response createIntent(InputStream stream) {
try {
IntentService service = get(IntentService.class);
- ObjectNode root = (ObjectNode) mapper().readTree(stream);
+ ObjectNode root = readTreeFromStream(mapper(), stream);
Intent intent = decode(root);
service.submit(intent);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
diff --git a/apps/pce/pcerest/src/main/java/org/onosproject/pcerest/PcePathWebResource.java b/apps/pce/pcerest/src/main/java/org/onosproject/pcerest/PcePathWebResource.java
index be81702..de2e84a 100644
--- a/apps/pce/pcerest/src/main/java/org/onosproject/pcerest/PcePathWebResource.java
+++ b/apps/pce/pcerest/src/main/java/org/onosproject/pcerest/PcePathWebResource.java
@@ -17,6 +17,7 @@
import static javax.ws.rs.core.Response.Status.OK;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
import java.util.Collection;
import java.io.IOException;
@@ -130,7 +131,7 @@
public Response setupPath(InputStream stream) {
log.debug("Setup path.");
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode port = jsonTree.get("path");
TunnelService tunnelService = get(TunnelService.class);
PcePath path = codec(PcePath.class).decode((ObjectNode) port, this);
@@ -190,7 +191,7 @@
final InputStream stream) {
log.debug("Update path by identifier {}.", id);
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode pathNode = jsonTree.get("path");
PcePath path = codec(PcePath.class).decode((ObjectNode) pathNode, this);
if (path == null) {
diff --git a/apps/powermanagement/src/main/java/org/onosproject/powermanagement/PowerConfigWebResource.java b/apps/powermanagement/src/main/java/org/onosproject/powermanagement/PowerConfigWebResource.java
index afcdfbd..ecae8dd 100644
--- a/apps/powermanagement/src/main/java/org/onosproject/powermanagement/PowerConfigWebResource.java
+++ b/apps/powermanagement/src/main/java/org/onosproject/powermanagement/PowerConfigWebResource.java
@@ -54,6 +54,8 @@
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;
+import static org.onlab.util.Tools.readTreeFromStream;
+
/**
* Manage inventory of infrastructure devices with Power Config behaviour.
*/
@@ -119,7 +121,7 @@
@Consumes(MediaType.APPLICATION_JSON)
public Response setTargetPower(InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
decode(jsonTree);
return Response.ok().build();
} catch (IOException e) {
diff --git a/apps/restconf/utils/src/main/java/org/onosproject/restconf/utils/RestconfUtils.java b/apps/restconf/utils/src/main/java/org/onosproject/restconf/utils/RestconfUtils.java
index e14477f..134f71e 100644
--- a/apps/restconf/utils/src/main/java/org/onosproject/restconf/utils/RestconfUtils.java
+++ b/apps/restconf/utils/src/main/java/org/onosproject/restconf/utils/RestconfUtils.java
@@ -50,6 +50,8 @@
import static javax.ws.rs.core.Response.Status.NO_CONTENT;
import static javax.ws.rs.core.Response.Status.OK;
import static javax.ws.rs.core.Response.Status.REQUEST_TIMEOUT;
+import static org.onlab.util.Tools.readTreeFromStream;
+
/**
* Utilities used by the RESTCONF app.
@@ -82,7 +84,7 @@
ObjectNode rootNode;
ObjectMapper mapper = new ObjectMapper();
try {
- rootNode = (ObjectNode) mapper.readTree(inputStream);
+ rootNode = readTreeFromStream(mapper, inputStream);
} catch (IOException e) {
throw new RestconfUtilsException("ERROR: InputStream failed to parse");
}
diff --git a/apps/route-service/app/src/main/java/org/onosproject/routeservice/rest/RouteServiceWebResource.java b/apps/route-service/app/src/main/java/org/onosproject/routeservice/rest/RouteServiceWebResource.java
index eb17d79..fc1a09a 100644
--- a/apps/route-service/app/src/main/java/org/onosproject/routeservice/rest/RouteServiceWebResource.java
+++ b/apps/route-service/app/src/main/java/org/onosproject/routeservice/rest/RouteServiceWebResource.java
@@ -39,6 +39,7 @@
import java.util.stream.Collectors;
import static org.onlab.util.Tools.nullIsIllegal;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Manage the unicast routing information.
@@ -88,7 +89,7 @@
public Response createRoute(InputStream route) {
RouteAdminService service = get(RouteAdminService.class);
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(route);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), route);
Route r = codec(Route.class).decode(jsonTree, this);
service.update(Collections.singletonList(r));
} catch (IOException ex) {
@@ -118,7 +119,7 @@
public Response createRoutes(InputStream routesStream) {
RouteAdminService service = get(RouteAdminService.class);
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(routesStream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), routesStream);
ArrayNode routesArray = nullIsIllegal((ArrayNode) jsonTree.get(ROUTES),
ROUTES_KEY_ERROR);
List<Route> routes = codec(Route.class).decode(routesArray, this);
@@ -146,7 +147,7 @@
public Response deleteRoute(InputStream route) {
RouteAdminService service = get(RouteAdminService.class);
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(route);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), route);
Route r = codec(Route.class).decode(jsonTree, this);
service.withdraw(Collections.singletonList(r));
} catch (IOException ex) {
@@ -168,7 +169,7 @@
public Response deleteRoutes(InputStream routesStream) {
RouteAdminService service = get(RouteAdminService.class);
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(routesStream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), routesStream);
ArrayNode routesArray = nullIsIllegal((ArrayNode) jsonTree.get(ROUTES),
ROUTES_KEY_ERROR);
List<Route> routes = codec(Route.class).decode(routesArray, this);
diff --git a/apps/segmentrouting/web/src/main/java/org/onosproject/segmentrouting/web/PolicyWebResource.java b/apps/segmentrouting/web/src/main/java/org/onosproject/segmentrouting/web/PolicyWebResource.java
index cebcf84..08663e4 100644
--- a/apps/segmentrouting/web/src/main/java/org/onosproject/segmentrouting/web/PolicyWebResource.java
+++ b/apps/segmentrouting/web/src/main/java/org/onosproject/segmentrouting/web/PolicyWebResource.java
@@ -33,6 +33,8 @@
import java.io.InputStream;
import java.util.List;
+import static org.onlab.util.Tools.readTreeFromStream;
+
/**
* Query, create and remove segment routing plicies.
*/
@@ -69,7 +71,7 @@
@Consumes(MediaType.APPLICATION_JSON)
public Response createPolicy(InputStream input) throws IOException {
ObjectMapper mapper = new ObjectMapper();
- ObjectNode policyJson = (ObjectNode) mapper.readTree(input);
+ ObjectNode policyJson = readTreeFromStream(mapper, input);
SegmentRoutingService srService = get(SegmentRoutingService.class);
Policy policyInfo = POLICY_CODEC.decode(policyJson, this);
@@ -92,7 +94,7 @@
@Consumes(MediaType.APPLICATION_JSON)
public Response removePolicy(InputStream input) throws IOException {
ObjectMapper mapper = new ObjectMapper();
- ObjectNode policyJson = (ObjectNode) mapper.readTree(input);
+ ObjectNode policyJson = readTreeFromStream(mapper, input);
SegmentRoutingService srService = get(SegmentRoutingService.class);
Policy policyInfo = POLICY_CODEC.decode(policyJson, this);
// TODO: Check the result
diff --git a/apps/segmentrouting/web/src/main/java/org/onosproject/segmentrouting/web/PseudowireWebResource.java b/apps/segmentrouting/web/src/main/java/org/onosproject/segmentrouting/web/PseudowireWebResource.java
index fd4c906..1d8bb76 100644
--- a/apps/segmentrouting/web/src/main/java/org/onosproject/segmentrouting/web/PseudowireWebResource.java
+++ b/apps/segmentrouting/web/src/main/java/org/onosproject/segmentrouting/web/PseudowireWebResource.java
@@ -44,6 +44,7 @@
import java.util.stream.Collectors;
import static org.onlab.util.Tools.nullIsIllegal;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Query, create and remove pseudowires.
@@ -107,7 +108,7 @@
public Response createPseudowire(InputStream input) throws IOException {
ObjectMapper mapper = new ObjectMapper();
- ObjectNode pseudowireJson = (ObjectNode) mapper.readTree(input);
+ ObjectNode pseudowireJson = readTreeFromStream(mapper, input);
SegmentRoutingService srService = get(SegmentRoutingService.class);
DefaultL2TunnelDescription pseudowire = PSEUDOWIRE_CODEC.decode(pseudowireJson, this);
@@ -147,7 +148,7 @@
public Response createPseudowiresBulk(InputStream input) throws IOException {
ObjectMapper mapper = new ObjectMapper();
- ObjectNode pseudowireJson = (ObjectNode) mapper.readTree(input);
+ ObjectNode pseudowireJson = readTreeFromStream(mapper, input);
SegmentRoutingService srService = get(SegmentRoutingService.class);
List<DefaultL2TunnelDescription> pseudowires;
@@ -189,7 +190,7 @@
public Response removePseudowire(InputStream input) throws IOException {
ObjectMapper mapper = new ObjectMapper();
- ObjectNode pseudowireJson = (ObjectNode) mapper.readTree(input);
+ ObjectNode pseudowireJson = readTreeFromStream(mapper, input);
SegmentRoutingService srService = get(SegmentRoutingService.class);
Integer pseudowireId = PSEUDOWIRE_CODEC.decodeId(pseudowireJson);
@@ -229,7 +230,7 @@
public Response removePseudowiresBulk(InputStream input) throws IOException {
ObjectMapper mapper = new ObjectMapper();
- ObjectNode pseudowireJson = (ObjectNode) mapper.readTree(input);
+ ObjectNode pseudowireJson = readTreeFromStream(mapper, input);
SegmentRoutingService srService = get(SegmentRoutingService.class);
List<Integer> ids = new ArrayList<>();
diff --git a/apps/segmentrouting/web/src/main/java/org/onosproject/segmentrouting/web/TunnelWebResource.java b/apps/segmentrouting/web/src/main/java/org/onosproject/segmentrouting/web/TunnelWebResource.java
index 476bcd8..010f6c9 100644
--- a/apps/segmentrouting/web/src/main/java/org/onosproject/segmentrouting/web/TunnelWebResource.java
+++ b/apps/segmentrouting/web/src/main/java/org/onosproject/segmentrouting/web/TunnelWebResource.java
@@ -33,6 +33,8 @@
import java.io.InputStream;
import java.util.List;
+import static org.onlab.util.Tools.readTreeFromStream;
+
/**
* Query, create and remove segment routing tunnels.
*/
@@ -69,7 +71,7 @@
@Consumes(MediaType.APPLICATION_JSON)
public Response createTunnel(InputStream input) throws IOException {
ObjectMapper mapper = new ObjectMapper();
- ObjectNode tunnelJson = (ObjectNode) mapper.readTree(input);
+ ObjectNode tunnelJson = readTreeFromStream(mapper, input);
SegmentRoutingService srService = get(SegmentRoutingService.class);
Tunnel tunnelInfo = TUNNEL_CODEC.decode(tunnelJson, this);
srService.createTunnel(tunnelInfo);
@@ -88,7 +90,7 @@
@Consumes(MediaType.APPLICATION_JSON)
public Response removeTunnel(InputStream input) throws IOException {
ObjectMapper mapper = new ObjectMapper();
- ObjectNode tunnelJson = (ObjectNode) mapper.readTree(input);
+ ObjectNode tunnelJson = readTreeFromStream(mapper, input);
SegmentRoutingService srService = get(SegmentRoutingService.class);
Tunnel tunnelInfo = TUNNEL_CODEC.decode(tunnelJson, this);
srService.removeTunnel(tunnelInfo);
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FloatingIpWebResource.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FloatingIpWebResource.java
index e958765..67af86e 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FloatingIpWebResource.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FloatingIpWebResource.java
@@ -60,6 +60,7 @@
import static javax.ws.rs.core.Response.Status.CONFLICT;
import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
+import static org.onlab.util.Tools.readTreeFromStream;
@Path("floatingips")
public class FloatingIpWebResource extends AbstractWebResource {
@@ -114,7 +115,7 @@
public Response createFloatingIp(final InputStream input) {
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode subnode = mapper.readTree(input);
+ JsonNode subnode = readTreeFromStream(mapper, input);
Collection<FloatingIp> floatingIps = createOrUpdateByInputStream(subnode);
Boolean result = nullIsNotFound((get(FloatingIpService.class)
.createFloatingIps(floatingIps)),
@@ -137,7 +138,7 @@
final InputStream input) {
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode subnode = mapper.readTree(input);
+ JsonNode subnode = readTreeFromStream(mapper, input);
Collection<FloatingIp> floatingIps = createOrUpdateByInputStream(subnode);
Boolean result = nullIsNotFound(get(FloatingIpService.class)
.updateFloatingIps(floatingIps), UPDATE_FAIL);
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java
index 29e67c5..47e249f 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java
@@ -17,6 +17,7 @@
import static javax.ws.rs.core.Response.Status.OK;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
import java.io.IOException;
import java.io.InputStream;
@@ -107,7 +108,7 @@
@Produces(MediaType.APPLICATION_JSON)
public Response createFlowClassifier(InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode flow = jsonTree.get("flow_classifier");
FlowClassifier flowClassifier = codec(FlowClassifier.class).decode((ObjectNode) flow, this);
@@ -136,7 +137,7 @@
public Response updateFlowClassifier(@PathParam("flow_id") String id, final InputStream stream) {
try {
- JsonNode jsonTree = mapper().readTree(stream);
+ JsonNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode flow = jsonTree.get("flow_classifier");
FlowClassifier flowClassifier = codec(FlowClassifier.class).decode((ObjectNode) flow, this);
Boolean result = nullIsNotFound(get(FlowClassifierService.class).updateFlowClassifier(flowClassifier),
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortChainWebResource.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortChainWebResource.java
index 0a6f6e7..1bfa44f 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortChainWebResource.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortChainWebResource.java
@@ -17,6 +17,7 @@
import static javax.ws.rs.core.Response.Status.OK;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
import java.io.IOException;
import java.io.InputStream;
@@ -106,7 +107,7 @@
@Produces(MediaType.APPLICATION_JSON)
public Response createPortChain(InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode port = jsonTree.get("port_chain");
PortChain portChain = codec(PortChain.class).decode((ObjectNode) port, this);
Boolean issuccess = nullIsNotFound(get(PortChainService.class).createPortChain(portChain),
@@ -132,7 +133,7 @@
public Response updatePortPain(@PathParam("chain_id") String id,
final InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode port = jsonTree.get("port_chain");
PortChain portChain = codec(PortChain.class).decode((ObjectNode) port, this);
Boolean result = nullIsNotFound(get(PortChainService.class).updatePortChain(portChain),
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairGroupWebResource.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairGroupWebResource.java
index 42b9563..91793ca 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairGroupWebResource.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairGroupWebResource.java
@@ -18,6 +18,7 @@
import static javax.ws.rs.core.Response.Status.OK;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
import java.io.IOException;
import java.io.InputStream;
@@ -111,7 +112,7 @@
try {
ObjectMapper mapper = new ObjectMapper();
- ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper, stream);
JsonNode port = jsonTree.get("port_pair_group");
PortPairGroup portPairGroup = codec(PortPairGroup.class).decode((ObjectNode) port, this);
@@ -139,7 +140,7 @@
final InputStream stream) {
try {
ObjectMapper mapper = new ObjectMapper();
- ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper, stream);
JsonNode port = jsonTree.get("port_pair_group");
PortPairGroup portPairGroup = codec(PortPairGroup.class).decode((ObjectNode) port, this);
Boolean isSuccess = nullIsNotFound(get(PortPairGroupService.class).updatePortPairGroup(portPairGroup),
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java
index 96cf9ac..2c88f6f 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java
@@ -18,6 +18,7 @@
import static javax.ws.rs.core.Response.Status.OK;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
import java.io.IOException;
import java.io.InputStream;
@@ -105,7 +106,7 @@
@Produces(MediaType.APPLICATION_JSON)
public Response createPortPair(InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode port = jsonTree.get("port_pair");
PortPair portPair = codec(PortPair.class).decode((ObjectNode) port, this);
Boolean isSuccess = nullIsNotFound(get(PortPairService.class).createPortPair(portPair),
@@ -131,7 +132,7 @@
public Response updatePortPair(@PathParam("pair_id") String id,
final InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode port = jsonTree.get("port_pair");
PortPair portPair = codec(PortPair.class).decode((ObjectNode) port, this);
Boolean isSuccess = nullIsNotFound(get(PortPairService.class).updatePortPair(portPair),
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/RouterWebResource.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/RouterWebResource.java
index c09b5cd..fc8d7bc 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/RouterWebResource.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/RouterWebResource.java
@@ -68,6 +68,7 @@
import static javax.ws.rs.core.Response.Status.CONFLICT;
import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
+import static org.onlab.util.Tools.readTreeFromStream;
@Path("routers")
public class RouterWebResource extends AbstractWebResource {
@@ -121,7 +122,7 @@
public Response createRouter(final InputStream input) {
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode subnode = mapper.readTree(input);
+ JsonNode subnode = readTreeFromStream(mapper, input);
Collection<Router> routers = createOrUpdateByInputStream(subnode);
Boolean result = nullIsNotFound((get(RouterService.class)
@@ -144,7 +145,7 @@
final InputStream input) {
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode subnode = mapper.readTree(input);
+ JsonNode subnode = readTreeFromStream(mapper, input);
Collection<Router> routers = changeUpdateJsonToSub(subnode, id);
Boolean result = nullIsNotFound(get(RouterService.class)
.updateRouters(routers), UPDATE_FAIL);
@@ -184,7 +185,7 @@
}
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode subnode = mapper.readTree(input);
+ JsonNode subnode = readTreeFromStream(mapper, input);
if (!subnode.hasNonNull("id")) {
throw new IllegalArgumentException("id should not be null");
} else if (subnode.get("id").asText().isEmpty()) {
@@ -233,7 +234,7 @@
}
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode subnode = mapper.readTree(input);
+ JsonNode subnode = readTreeFromStream(mapper, input);
if (!subnode.hasNonNull("id")) {
throw new IllegalArgumentException("id should not be null");
} else if (subnode.get("id").asText().isEmpty()) {
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/SubnetWebResource.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/SubnetWebResource.java
index 2d122d7..b0951f4 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/SubnetWebResource.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/SubnetWebResource.java
@@ -19,6 +19,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
+import static org.onlab.util.Tools.readTreeFromStream;
import java.io.IOException;
import java.io.InputStream;
@@ -109,7 +110,7 @@
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode subnode = mapper.readTree(input);
+ JsonNode subnode = readTreeFromStream(mapper, input);
Iterable<Subnet> subnets = createOrUpdateByInputStream(subnode);
Boolean result = nullIsNotFound((get(SubnetService.class)
.createSubnets(subnets)),
@@ -134,7 +135,7 @@
final InputStream input) {
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode subnode = mapper.readTree(input);
+ JsonNode subnode = readTreeFromStream(mapper, input);
Iterable<Subnet> subnets = createOrUpdateByInputStream(subnode);
Boolean result = nullIsNotFound(get(SubnetService.class)
.updateSubnets(subnets), SUBNET_NOT_FOUND);
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/TenantNetworkWebResource.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/TenantNetworkWebResource.java
index c984c4f..ef32818 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/TenantNetworkWebResource.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/TenantNetworkWebResource.java
@@ -58,6 +58,7 @@
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import static javax.ws.rs.core.Response.Status.OK;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* REST resource for interacting with the inventory of networks.
@@ -170,7 +171,7 @@
public Response createNetworks(InputStream input) {
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode cfg = mapper.readTree(input);
+ JsonNode cfg = readTreeFromStream(mapper, input);
JsonNode nodes = null;
Iterable<TenantNetwork> networks = null;
if (cfg.get("network") != null) {
@@ -207,7 +208,7 @@
public Response updateNetworks(@PathParam("id") String id, InputStream input) {
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode cfg = mapper.readTree(input);
+ JsonNode cfg = readTreeFromStream(mapper, input);
JsonNode nodes = null;
Iterable<TenantNetwork> networks = null;
if (cfg.get("network") != null) {
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/VirtualPortWebResource.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/VirtualPortWebResource.java
index cb5b7d6..8a89383 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/VirtualPortWebResource.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/VirtualPortWebResource.java
@@ -65,6 +65,7 @@
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import static javax.ws.rs.core.Response.Status.OK;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* REST resource for interacting with the inventory of infrastructure
@@ -113,7 +114,7 @@
public Response createPorts(InputStream input) {
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode cfg = mapper.readTree(input);
+ JsonNode cfg = readTreeFromStream(mapper, input);
Iterable<VirtualPort> vPorts = createOrUpdateByInputStream(cfg);
Boolean issuccess = nullIsNotFound(get(VirtualPortService.class)
.createPorts(vPorts), VPORT_NOT_FOUND);
@@ -162,7 +163,7 @@
public Response updatePorts(@PathParam("id") String id, InputStream input) {
try {
ObjectMapper mapper = new ObjectMapper();
- JsonNode cfg = mapper.readTree(input);
+ JsonNode cfg = readTreeFromStream(mapper, input);
Iterable<VirtualPort> vPorts = createOrUpdateByInputStream(cfg);
Boolean issuccess = nullIsNotFound(get(VirtualPortService.class)
.updatePorts(vPorts), VPORT_NOT_FOUND);
diff --git a/lib/BUCK b/lib/BUCK
index 611f3dd..9431c45 100644
--- a/lib/BUCK
+++ b/lib/BUCK
@@ -1,4 +1,4 @@
-# ***** This file was auto-generated at Wed, 14 Mar 2018 22:16:36 GMT. Do not edit this file manually. *****
+# ***** This file was auto-generated at Tue, 3 Apr 2018 17:03:35 GMT. Do not edit this file manually. *****
# ***** Use onos-lib-gen *****
pass_thru_pom(
@@ -486,28 +486,28 @@
remote_jar (
name = 'jackson-annotations',
- out = 'jackson-annotations-2.8.10.jar',
- url = 'mvn:com.fasterxml.jackson.core:jackson-annotations:jar:2.8.10',
- sha1 = '5e924646d6f893bc9036939c5f2b4ecaee85e5da',
- maven_coords = 'com.fasterxml.jackson.core:jackson-annotations:2.8.10',
+ out = 'jackson-annotations-2.9.5.jar',
+ url = 'mvn:com.fasterxml.jackson.core:jackson-annotations:jar:2.9.5',
+ sha1 = '9056ec9db21c57d43219a84bb18c129ae51c6a5d',
+ maven_coords = 'com.fasterxml.jackson.core:jackson-annotations:2.9.5',
visibility = [ 'PUBLIC' ],
)
remote_jar (
name = 'jackson-core',
- out = 'jackson-core-2.8.10.jar',
- url = 'mvn:com.fasterxml.jackson.core:jackson-core:jar:2.8.10',
- sha1 = 'eb21a035c66ad307e66ec8fce37f5d50fd62d039',
- maven_coords = 'com.fasterxml.jackson.core:jackson-core:2.8.10',
+ out = 'jackson-core-2.9.5.jar',
+ url = 'mvn:com.fasterxml.jackson.core:jackson-core:jar:2.9.5',
+ sha1 = 'a22ac51016944b06fd9ffbc9541c6e7ce5eea117',
+ maven_coords = 'com.fasterxml.jackson.core:jackson-core:2.9.5',
visibility = [ 'PUBLIC' ],
)
remote_jar (
name = 'jackson-databind',
- out = 'jackson-databind-2.8.10.jar',
- url = 'mvn:com.fasterxml.jackson.core:jackson-databind:jar:2.8.10',
- sha1 = 'f7b83cb2bc4b88d53961e749e1ad32f49ef017b7',
- maven_coords = 'com.fasterxml.jackson.core:jackson-databind:2.8.10',
+ out = 'jackson-databind-2.9.5.jar',
+ url = 'mvn:com.fasterxml.jackson.core:jackson-databind:jar:2.9.5',
+ sha1 = '3490508379d065fe3fcb80042b62f630f7588606',
+ maven_coords = 'com.fasterxml.jackson.core:jackson-databind:2.9.5',
visibility = [ 'PUBLIC' ],
)
diff --git a/lib/deps.json b/lib/deps.json
index dfa5f30..ff0fe09 100644
--- a/lib/deps.json
+++ b/lib/deps.json
@@ -148,9 +148,9 @@
"retrofit": "mvn:com.squareup.retrofit:retrofit:1.9.0",
"okhttp": "mvn:com.squareup.okhttp:okhttp:2.4.0",
"okio": "mvn:com.squareup.okio:okio:1.4.0",
- "jackson-annotations": "mvn:com.fasterxml.jackson.core:jackson-annotations:2.8.10",
- "jackson-core": "mvn:com.fasterxml.jackson.core:jackson-core:2.8.10",
- "jackson-databind": "mvn:com.fasterxml.jackson.core:jackson-databind:2.8.10",
+ "jackson-annotations": "mvn:com.fasterxml.jackson.core:jackson-annotations:2.9.5",
+ "jackson-core": "mvn:com.fasterxml.jackson.core:jackson-core:2.9.5",
+ "jackson-databind": "mvn:com.fasterxml.jackson.core:jackson-databind:2.9.5",
"javax.annotation-api": "mvn:javax.annotation:javax.annotation-api:1.2",
"javax.inject": "mvn:org.glassfish.hk2.external:javax.inject:2.5.0-b32",
"javax.ws.rs-api": "mvn:javax.ws.rs:javax.ws.rs-api:2.1",
diff --git a/lib/pom.xml b/lib/pom.xml
index 42ea1a7..ce9e5d0 100644
--- a/lib/pom.xml
+++ b/lib/pom.xml
@@ -45,7 +45,7 @@
<karaf.version>3.0.8</karaf.version>
<jersey.version>2.25.1</jersey.version>
<jetty.version>9.2.21.v20170120</jetty.version>
- <jackson.version>2.8.10</jackson.version>
+ <jackson.version>2.9.5</jackson.version>
<slf4j.version>1.7.21</slf4j.version>
<guava.version>22.0</guava.version>
<commons.io.version>2.6</commons.io.version>
diff --git a/protocols/restconf/server/rpp/src/main/java/org/onosproject/protocol/restconf/server/rpp/RestconfWebResource.java b/protocols/restconf/server/rpp/src/main/java/org/onosproject/protocol/restconf/server/rpp/RestconfWebResource.java
index f1853e6..da75fab 100644
--- a/protocols/restconf/server/rpp/src/main/java/org/onosproject/protocol/restconf/server/rpp/RestconfWebResource.java
+++ b/protocols/restconf/server/rpp/src/main/java/org/onosproject/protocol/restconf/server/rpp/RestconfWebResource.java
@@ -48,6 +48,7 @@
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import static javax.ws.rs.core.Response.Status.OK;
+import static org.onlab.util.Tools.readTreeFromStream;
import static org.slf4j.LoggerFactory.getLogger;
@@ -180,7 +181,7 @@
URI uri = uriInfo.getRequestUri();
try {
- ObjectNode rootNode = (ObjectNode) mapper().readTree(stream);
+ ObjectNode rootNode = readTreeFromStream(mapper(), stream);
service.runPostOperationOnDataResource(uri, rootNode);
return Response.created(uriInfo.getRequestUri()).build();
@@ -216,7 +217,7 @@
@Context HttpServletRequest request) {
URI uri = uriInfo.getRequestUri();
try {
- ObjectNode inputNode = (ObjectNode) mapper().readTree(rpcInput);
+ ObjectNode inputNode = readTreeFromStream(mapper(), rpcInput);
CompletableFuture<RestconfRpcOutput> rpcFuture = service.runRpc(uri,
inputNode,
request.getRemoteAddr());
@@ -266,7 +267,7 @@
URI uri = uriInfo.getRequestUri();
try {
- ObjectNode rootNode = (ObjectNode) mapper().readTree(stream);
+ ObjectNode rootNode = readTreeFromStream(mapper(), stream);
service.runPutOperationOnDataResource(uri, rootNode);
return Response.created(uriInfo.getRequestUri()).build();
@@ -334,7 +335,7 @@
URI uri = uriInfo.getRequestUri();
try {
- ObjectNode rootNode = (ObjectNode) mapper().readTree(stream);
+ ObjectNode rootNode = readTreeFromStream(mapper(), stream);
service.runPatchOperationOnDataResource(uri, rootNode);
return Response.ok().build();
diff --git a/providers/ietfte/utils/src/main/java/org/onosproject/provider/te/utils/CodecTools.java b/providers/ietfte/utils/src/main/java/org/onosproject/provider/te/utils/CodecTools.java
index 7839378..d10c877 100644
--- a/providers/ietfte/utils/src/main/java/org/onosproject/provider/te/utils/CodecTools.java
+++ b/providers/ietfte/utils/src/main/java/org/onosproject/provider/te/utils/CodecTools.java
@@ -26,6 +26,7 @@
import java.io.IOException;
import java.io.InputStream;
+import static org.onlab.util.Tools.readTreeFromStream;
import static org.slf4j.LoggerFactory.getLogger;
@@ -50,7 +51,7 @@
public static ObjectNode toJson(InputStream stream) {
ObjectNode response = null;
try {
- response = (ObjectNode) MAPPER.readTree(stream);
+ response = readTreeFromStream(MAPPER, stream);
} catch (IOException e) {
log.error("Parse json string failed {}", e.getMessage());
}
diff --git a/utils/misc/BUCK b/utils/misc/BUCK
index 5b06b9c..aef407f 100644
--- a/utils/misc/BUCK
+++ b/utils/misc/BUCK
@@ -4,6 +4,7 @@
'//lib:METRICS',
'//lib:KRYO',
'//lib:netty',
+ '//lib:JACKSON',
]
osgi_jar_with_tests(
diff --git a/utils/misc/src/main/java/org/onlab/util/Tools.java b/utils/misc/src/main/java/org/onlab/util/Tools.java
index 057441e..ebcf472 100644
--- a/utils/misc/src/main/java/org/onlab/util/Tools.java
+++ b/utils/misc/src/main/java/org/onlab/util/Tools.java
@@ -15,6 +15,8 @@
*/
package org.onlab.util;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Charsets;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
@@ -24,6 +26,7 @@
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
@@ -73,6 +76,8 @@
private static Random random = new Random();
+ private static final String INPUT_JSON_CANNOT_BE_NULL = "Input JSON cannot be null";
+
/**
* Returns a thread factory that produces threads named according to the
* supplied name pattern.
@@ -216,6 +221,19 @@
}
/**
+ * Utility to convert a mapper and an input stream into a JSON tree,
+ * and be tolerant of a null tree being returned.
+ *
+ * @param mapper JSON object mapper
+ * @param stream IO stream containing the JSON
+ * @return object node for the given
+ * @throws IOException if JSON parsing fails
+ */
+ public static ObjectNode readTreeFromStream(ObjectMapper mapper, InputStream stream) throws IOException {
+ return nullIsIllegal((ObjectNode) mapper.readTree(stream), INPUT_JSON_CANNOT_BE_NULL);
+ }
+
+ /**
* Converts a string from hex to long.
*
* @param string hex number in string form; sans 0x
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
index 4a71ffd..24ad50a 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
@@ -39,6 +39,7 @@
import java.util.Set;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Manage inventory of applications.
@@ -96,7 +97,7 @@
public Response installApp(InputStream raw) {
Application app;
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(raw);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), raw);
URL url = new URL(jsonTree.get(URL).asText());
boolean activate = false;
if (jsonTree.has(ACTIVATE)) {
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/ClusterWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/ClusterWebResource.java
index 4ffb445..664f0eb 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/ClusterWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/ClusterWebResource.java
@@ -38,6 +38,7 @@
import java.util.List;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Manage cluster of ONOS instances.
@@ -92,7 +93,7 @@
@Produces(MediaType.APPLICATION_JSON)
public Response formCluster(InputStream config) throws IOException {
JsonCodec<ControllerNode> codec = codec(ControllerNode.class);
- ObjectNode root = (ObjectNode) mapper().readTree(config);
+ ObjectNode root = readTreeFromStream(mapper(), config);
List<ControllerNode> nodes = codec.decode((ArrayNode) root.path("nodes"), this);
JsonNode partitionSizeNode = root.get("partitionSize");
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/ComponentConfigWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/ComponentConfigWebResource.java
index 13b8375..9d3bcca 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/ComponentConfigWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/ComponentConfigWebResource.java
@@ -39,6 +39,7 @@
import java.util.Set;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Manage component configurations.
@@ -105,7 +106,7 @@
@DefaultValue("false") @QueryParam("preset") boolean preset,
InputStream request) throws IOException {
ComponentConfigService service = get(ComponentConfigService.class);
- ObjectNode props = (ObjectNode) mapper().readTree(request);
+ ObjectNode props = readTreeFromStream(mapper(), request);
List<String> errorMsgs = new ArrayList<String>();
if (preset) {
props.fieldNames().forEachRemaining(k -> {
@@ -151,7 +152,7 @@
public Response unsetConfigs(@PathParam("component") String component,
InputStream request) throws IOException {
ComponentConfigService service = get(ComponentConfigService.class);
- ObjectNode props = (ObjectNode) mapper().readTree(request);
+ ObjectNode props = readTreeFromStream(mapper(), request);
props.fieldNames().forEachRemaining(k -> service.unsetProperty(component, k));
return Response.noContent().build();
}
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/DeviceKeyWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/DeviceKeyWebResource.java
index 52f8ae7..2bed18b 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/DeviceKeyWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/DeviceKeyWebResource.java
@@ -39,6 +39,7 @@
import java.io.InputStream;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Query and Manage Device Keys.
@@ -96,7 +97,7 @@
public Response addDeviceKey(InputStream stream) {
try {
DeviceKeyAdminService service = get(DeviceKeyAdminService.class);
- ObjectNode root = (ObjectNode) mapper().readTree(stream);
+ ObjectNode root = readTreeFromStream(mapper(), stream);
DeviceKey deviceKey = codec(DeviceKey.class).decode(root, this);
service.addKey(deviceKey);
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/DpisWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/DpisWebResource.java
index d3ff886..b59c7e8 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/DpisWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/DpisWebResource.java
@@ -40,6 +40,7 @@
import java.util.List;
import java.util.stream.Collectors;
+import static org.onlab.util.Tools.readTreeFromStream;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -292,7 +293,7 @@
ObjectNode result;
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
log.debug("jsonTree={}", jsonTree);
DpiStatistics ds = codec(DpiStatistics.class).decode(jsonTree, this);
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/FlowObjectiveWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/FlowObjectiveWebResource.java
index e6f7e9c..56a4755 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/FlowObjectiveWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/FlowObjectiveWebResource.java
@@ -39,6 +39,8 @@
import java.io.IOException;
import java.io.InputStream;
+import static org.onlab.util.Tools.readTreeFromStream;
+
/**
* Manage flow objectives.
*/
@@ -74,7 +76,7 @@
InputStream stream) {
try {
UriBuilder locationBuilder = null;
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
validateDeviceId(deviceId, jsonTree);
if (appId != null) {
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 1bc7e98..f70382d 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
@@ -52,6 +52,7 @@
import static org.onlab.util.Tools.nullIsIllegal;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Query and program flow rules.
@@ -113,7 +114,7 @@
@Produces(MediaType.APPLICATION_JSON)
public Response createFlows(@QueryParam("appId") String appId, InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
ArrayNode flowsArray = nullIsIllegal((ArrayNode) jsonTree.get(FLOWS),
FLOW_ARRAY_REQUIRED);
@@ -248,7 +249,7 @@
@QueryParam("appId") String appId,
InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
if (specifiedDeviceId != null &&
!specifiedDeviceId.asText().equals(deviceId)) {
@@ -312,7 +313,7 @@
List<FlowEntry> rulesToRemove = new ArrayList<>();
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode jsonFlows = jsonTree.get("flows");
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/GroupsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/GroupsWebResource.java
index 1af502b..a0875d5 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/GroupsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/GroupsWebResource.java
@@ -46,6 +46,7 @@
import org.onlab.util.HexString;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Query and program group rules.
@@ -148,7 +149,7 @@
InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
if (specifiedDeviceId != null &&
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java
index 26adef8..3e5dc21 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java
@@ -57,6 +57,7 @@
import java.util.Set;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
import static org.onosproject.net.HostId.hostId;
/**
@@ -139,7 +140,7 @@
URI location;
try {
// Parse the input stream
- ObjectNode root = (ObjectNode) mapper().readTree(stream);
+ ObjectNode root = readTreeFromStream(mapper(), stream);
HostProviderRegistry hostProviderRegistry = get(HostProviderRegistry.class);
InternalHostProvider hostProvider = new InternalHostProvider();
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
index 463f822..38465ac 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
@@ -57,6 +57,7 @@
import java.util.concurrent.TimeUnit;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
import static org.onosproject.net.intent.IntentState.FAILED;
import static org.onosproject.net.intent.IntentState.WITHDRAWN;
import static org.slf4j.LoggerFactory.getLogger;
@@ -297,7 +298,7 @@
public Response createIntent(InputStream stream) {
try {
IntentService service = get(IntentService.class);
- ObjectNode root = (ObjectNode) mapper().readTree(stream);
+ ObjectNode root = readTreeFromStream(mapper(), stream);
Intent intent = codec(Intent.class).decode(root, this);
service.submit(intent);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/MastershipWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/MastershipWebResource.java
index 99ec5a4..cfd0f26 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/MastershipWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/MastershipWebResource.java
@@ -40,6 +40,7 @@
import java.util.Set;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Manage the mastership of ONOS instances.
@@ -190,7 +191,7 @@
public Response setRole(InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode deviceIdJson = jsonTree.get(DEVICE_ID);
JsonNode nodeIdJson = jsonTree.get(NODE_ID);
MastershipRole role = codec(MastershipRole.class).decode(jsonTree, this);
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/MetersWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/MetersWebResource.java
index 31f91c7..6fbe1b3 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/MetersWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/MetersWebResource.java
@@ -44,6 +44,7 @@
import java.io.InputStream;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -138,7 +139,7 @@
public Response createMeter(@PathParam("deviceId") String deviceId,
InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
if ((specifiedDeviceId != null &&
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/MulticastRouteWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/MulticastRouteWebResource.java
index 374605b..cdfd76e 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/MulticastRouteWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/MulticastRouteWebResource.java
@@ -25,6 +25,7 @@
import org.onosproject.rest.AbstractWebResource;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@@ -79,7 +80,7 @@
final String ingressStr = "ingress";
MulticastRouteService service = get(MulticastRouteService.class);
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
McastRoute route = codec(McastRoute.class).decode(jsonTree, this);
service.add(route);
if (jsonTree.has(ingressStr)) {
@@ -110,7 +111,7 @@
public Response deleteRoute(InputStream stream) {
MulticastRouteService service = get(MulticastRouteService.class);
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
McastRoute route = codec(McastRoute.class).decode(jsonTree, this);
service.remove(route);
} catch (IOException ex) {
@@ -141,7 +142,7 @@
try {
McastRoute route = new McastRoute(IpAddress.valueOf(source), IpAddress.valueOf(group),
McastRoute.Type.STATIC);
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
jsonTree.path("sinks").forEach(node -> {
ConnectPoint sink = ConnectPoint.deviceConnectPoint(node.asText());
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java
index 8aacbb6..e50e011 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java
@@ -41,6 +41,7 @@
import static org.onlab.util.Tools.emptyIsNotFound;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Manage network configurations.
@@ -207,7 +208,7 @@
@SuppressWarnings("unchecked")
public Response upload(InputStream request) throws IOException {
NetworkConfigService service = get(NetworkConfigService.class);
- ObjectNode root = (ObjectNode) mapper().readTree(request);
+ ObjectNode root = readTreeFromStream(mapper(), request);
List<String> errorMsgs = new ArrayList<String>();
root.fieldNames()
.forEachRemaining(sk -> {
@@ -241,7 +242,7 @@
public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
InputStream request) throws IOException {
NetworkConfigService service = get(NetworkConfigService.class);
- ObjectNode root = (ObjectNode) mapper().readTree(request);
+ ObjectNode root = readTreeFromStream(mapper(), request);
SubjectFactory subjectFactory =
nullIsNotFound(service.getSubjectFactory(subjectClassKey),
subjectClassNotValidErrorString(subjectClassKey));
@@ -269,7 +270,7 @@
@PathParam("subjectKey") String subjectKey,
InputStream request) throws IOException {
NetworkConfigService service = get(NetworkConfigService.class);
- ObjectNode root = (ObjectNode) mapper().readTree(request);
+ ObjectNode root = readTreeFromStream(mapper(), request);
SubjectFactory subjectFactory =
nullIsNotFound(service.getSubjectFactory(subjectClassKey),
subjectClassNotValidErrorString(subjectClassKey));
@@ -301,7 +302,7 @@
@PathParam("configKey") String configKey,
InputStream request) throws IOException {
NetworkConfigService service = get(NetworkConfigService.class);
- JsonNode root = mapper().readTree(request);
+ JsonNode root = readTreeFromStream(mapper(), request);
SubjectFactory subjectFactory =
nullIsNotFound(service.getSubjectFactory(subjectClassKey),
subjectClassNotValidErrorString(subjectClassKey));
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/RegionsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/RegionsWebResource.java
index 5f1119e..04fb8ad 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/RegionsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/RegionsWebResource.java
@@ -43,6 +43,7 @@
import java.util.Set;
import static org.onlab.util.Tools.nullIsNotFound;
+import static org.onlab.util.Tools.readTreeFromStream;
/**
* Manages region and device membership.
@@ -119,7 +120,7 @@
public Response createRegion(InputStream stream) {
URI location;
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
final Region region = codec(Region.class).decode(jsonTree, this);
final Region resultRegion = regionAdminService.createRegion(region.id(),
region.name(), region.type(), region.masters());
@@ -146,7 +147,7 @@
public Response updateRegion(@PathParam("regionId") String regionId,
InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode specifiedRegionId = jsonTree.get("id");
if (specifiedRegionId != null &&
@@ -242,7 +243,7 @@
* @throws IOException
*/
private Set<DeviceId> extractDeviceIds(InputStream stream) throws IOException {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode deviceIdsJson = jsonTree.get("deviceIds");
if (deviceIdsJson == null || deviceIdsJson.size() == 0) {
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/TenantWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/TenantWebResource.java
index 6e7627e..9250edf 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/TenantWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/TenantWebResource.java
@@ -38,6 +38,8 @@
import java.io.IOException;
import java.io.InputStream;
+import static org.onlab.util.Tools.readTreeFromStream;
+
/**
* Query and manage tenants of virtual networks.
*/
@@ -116,7 +118,7 @@
* @throws IOException if unable to parse the request
*/
private TenantId getTenantIdFromJsonStream(InputStream stream) throws IOException {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode specifiedTenantId = jsonTree.get("id");
if (specifiedTenantId == null) {
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/VirtualNetworkWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/VirtualNetworkWebResource.java
index d9b39f7..0e3504c 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/VirtualNetworkWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/VirtualNetworkWebResource.java
@@ -51,6 +51,8 @@
import java.util.Set;
import java.util.stream.Collectors;
+import static org.onlab.util.Tools.readTreeFromStream;
+
/**
* Query and Manage Virtual Network elements.
*/
@@ -176,7 +178,7 @@
public Response createVirtualDevice(@PathParam("networkId") long networkId,
InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
final VirtualDevice vdevReq = codec(VirtualDevice.class).decode(jsonTree, this);
JsonNode specifiedNetworkId = jsonTree.get("networkId");
if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) {
@@ -250,7 +252,7 @@
@PathParam("deviceId") String virtDeviceId,
InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
// final VirtualPort vportReq = codec(VirtualPort.class).decode(jsonTree, this);
JsonNode specifiedNetworkId = jsonTree.get("networkId");
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
@@ -335,7 +337,7 @@
public Response createVirtualLink(@PathParam("networkId") long networkId,
InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode specifiedNetworkId = jsonTree.get("networkId");
if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) {
throw new IllegalArgumentException(INVALID_FIELD + "networkId");
@@ -368,7 +370,7 @@
public Response removeVirtualLink(@PathParam("networkId") long networkId,
InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode specifiedNetworkId = jsonTree.get("networkId");
if (specifiedNetworkId != null &&
specifiedNetworkId.asLong() != (networkId)) {
@@ -416,7 +418,7 @@
public Response createVirtualHost(@PathParam("networkId") long networkId,
InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode specifiedNetworkId = jsonTree.get("networkId");
if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) {
throw new IllegalArgumentException(INVALID_FIELD + "networkId");
@@ -450,7 +452,7 @@
public Response removeVirtualHost(@PathParam("networkId") long networkId,
InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode specifiedNetworkId = jsonTree.get("networkId");
if (specifiedNetworkId != null &&
specifiedNetworkId.asLong() != (networkId)) {
@@ -474,7 +476,7 @@
* @throws IOException if unable to parse the request
*/
private JsonNode getFromJsonStream(InputStream stream, String jsonFieldName) throws IOException {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode jsonNode = jsonTree.get(jsonFieldName);
if (jsonNode == null) {
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyResource.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyResource.java
index 7fed76b..e0b629c 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyResource.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyResource.java
@@ -32,6 +32,7 @@
import java.io.InputStream;
import java.util.Map;
+import static org.onlab.util.Tools.readTreeFromStream;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -114,7 +115,7 @@
@Consumes("application/json")
@Deprecated
public Response setSprites(InputStream stream) throws IOException {
- JsonNode root = mapper.readTree(stream);
+ JsonNode root = readTreeFromStream(mapper, stream);
String name = root.path("defn_name").asText("sprites");
get(SpriteService.class).put(name, root);
return Response.ok().build();