[ONOS-4042] Bump up Jersey from 1.19 to 2.22.2
- Fix unit test errors of web/api
- Fix default page redirection problem
- Fix compilation errors of web/gui
- Fix configuration of aaa, acl, cordfabric, cord-gui, dhcp, mfwd,
olt, openstack, segmentrouting, vtn, virtualbng, xos-integration
- Fix unit test errors of cpman, vtn, acl, faultmanagement
- Fix compilation errors of openstack, virtualbng, xos-integration,
REST SB controller
- Rearrange features.xml to resolve bundle dependencies
- Remove all of stale Jersey 1.x libraries
- Rearrange web.xml to point new Jersey 2.x servlet
Change-Id: Ic17f461ede0aa36fa8d470546d8069152dc1d134
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/ApiDocResource.java b/web/api/src/main/java/org/onosproject/rest/resources/ApiDocResource.java
index 804f05e..c85e0b6 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/ApiDocResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/ApiDocResource.java
@@ -165,6 +165,9 @@
@GET
@Path("{resource: .*}")
public Response getResource(@PathParam("resource") String resource) throws IOException {
+ if (resource != null && resource.equals("")) {
+ return getIndex();
+ }
InputStream stream = getClass().getClassLoader().getResourceAsStream(DOCS + resource);
return ok(nullIsNotFound(stream, resource + " not found"))
.header(CONTENT_TYPE, contentType(resource)).build();
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 be2fc87..effbe26 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
@@ -30,12 +30,13 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
/**
* Manage flow objectives.
@@ -43,6 +44,9 @@
@Path("flowobjectives")
public class FlowObjectiveWebResource extends AbstractWebResource {
+ @Context
+ UriInfo uriInfo;
+
public static final String DEVICE_INVALID =
"Invalid deviceId in objective creation request";
public static final String POLICY_INVALID = "Invalid policy";
@@ -65,23 +69,26 @@
@Produces(MediaType.APPLICATION_JSON)
public Response createFilteringObjective(@PathParam("deviceId") String deviceId,
InputStream stream) {
- URI location = null;
try {
+ UriBuilder locationBuilder = null;
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
if (validateDeviceId(deviceId, jsonTree)) {
DeviceId did = DeviceId.deviceId(deviceId);
FilteringObjective filteringObjective =
codec(FilteringObjective.class).decode(jsonTree, this);
flowObjectiveService.filter(did, filteringObjective);
- location = new URI(Integer.toString(filteringObjective.id()));
+ locationBuilder = uriInfo.getBaseUriBuilder()
+ .path("flowobjectives")
+ .path(did.toString())
+ .path("filter")
+ .path(Integer.toString(filteringObjective.id()));
}
- } catch (IOException | URISyntaxException e) {
+ return Response
+ .created(locationBuilder.build())
+ .build();
+ } catch (IOException e) {
throw new IllegalArgumentException(e);
}
-
- return Response
- .created(location)
- .build();
}
/**
@@ -99,23 +106,26 @@
@Produces(MediaType.APPLICATION_JSON)
public Response createForwardingObjective(@PathParam("deviceId") String deviceId,
InputStream stream) {
- URI location = null;
try {
+ UriBuilder locationBuilder = null;
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
if (validateDeviceId(deviceId, jsonTree)) {
DeviceId did = DeviceId.deviceId(deviceId);
ForwardingObjective forwardingObjective =
codec(ForwardingObjective.class).decode(jsonTree, this);
flowObjectiveService.forward(did, forwardingObjective);
- location = new URI(Integer.toString(forwardingObjective.id()));
+ locationBuilder = uriInfo.getBaseUriBuilder()
+ .path("flowobjectives")
+ .path(did.toString())
+ .path("forward")
+ .path(Integer.toString(forwardingObjective.id()));
}
- } catch (IOException | URISyntaxException e) {
+ return Response
+ .created(locationBuilder.build())
+ .build();
+ } catch (IOException e) {
throw new IllegalArgumentException(e);
}
-
- return Response
- .created(location)
- .build();
}
/**
@@ -133,23 +143,26 @@
@Produces(MediaType.APPLICATION_JSON)
public Response createNextObjective(@PathParam("deviceId") String deviceId,
InputStream stream) {
- URI location = null;
try {
+ UriBuilder locationBuilder = null;
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
if (validateDeviceId(deviceId, jsonTree)) {
DeviceId did = DeviceId.deviceId(deviceId);
NextObjective nextObjective =
codec(NextObjective.class).decode(jsonTree, this);
flowObjectiveService.next(did, nextObjective);
- location = new URI(Integer.toString(nextObjective.id()));
+ locationBuilder = uriInfo.getBaseUriBuilder()
+ .path("flowobjectives")
+ .path(did.toString())
+ .path("next")
+ .path(Integer.toString(nextObjective.id()));
}
- } catch (IOException | URISyntaxException e) {
+ return Response
+ .created(locationBuilder.build())
+ .build();
+ } catch (IOException e) {
throw new IllegalArgumentException(e);
}
-
- return Response
- .created(location)
- .build();
}
/**
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 1e58a0f..0404967 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
@@ -15,22 +15,9 @@
*/
package org.onosproject.rest.resources;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.stream.StreamSupport;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onlab.util.ItemNotFoundException;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
@@ -40,9 +27,21 @@
import org.onosproject.net.flow.FlowRuleService;
import org.onosproject.rest.AbstractWebResource;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.stream.StreamSupport;
/**
* Query and program flow rules.
@@ -50,6 +49,10 @@
@Path("flows")
public class FlowsWebResource extends AbstractWebResource {
+
+ @Context
+ UriInfo uriInfo;
+
public static final String DEVICE_NOT_FOUND = "Device is not found";
final FlowRuleService service = get(FlowRuleService.class);
@@ -91,7 +94,7 @@
final Iterable<FlowEntry> flowEntries =
service.getFlowEntries(DeviceId.deviceId(deviceId));
- if (!flowEntries.iterator().hasNext()) {
+ if (flowEntries == null || !flowEntries.iterator().hasNext()) {
throw new ItemNotFoundException(DEVICE_NOT_FOUND);
}
for (final FlowEntry entry : flowEntries) {
@@ -116,7 +119,7 @@
final Iterable<FlowEntry> flowEntries =
service.getFlowEntries(DeviceId.deviceId(deviceId));
- if (!flowEntries.iterator().hasNext()) {
+ if (flowEntries == null || !flowEntries.iterator().hasNext()) {
throw new ItemNotFoundException(DEVICE_NOT_FOUND);
}
for (final FlowEntry entry : flowEntries) {
@@ -148,7 +151,6 @@
@Produces(MediaType.APPLICATION_JSON)
public Response createFlow(@PathParam("deviceId") String deviceId,
InputStream stream) {
- URI location;
try {
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
@@ -160,14 +162,17 @@
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) {
+ UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
+ .path("flows")
+ .path(deviceId)
+ .path(rule.id().toString());
+
+ return Response
+ .created(locationBuilder.build())
+ .build();
+ } catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
-
- return Response
- .created(location)
- .build();
}
/**
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 2d917bb..01ebba0 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
@@ -36,12 +36,13 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
import static org.onlab.util.Tools.nullIsNotFound;
@@ -51,6 +52,10 @@
@Path("groups")
public class GroupsWebResource extends AbstractWebResource {
+
+ @Context
+ UriInfo uriInfo;
+
public static final String DEVICE_INVALID = "Invalid deviceId in group creation request";
public static final String GROUP_NOT_FOUND = "Group was not found";
@@ -135,8 +140,8 @@
@Produces(MediaType.APPLICATION_JSON)
public Response createGroup(@PathParam("deviceId") String deviceId,
InputStream stream) {
- URI location;
try {
+
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
@@ -150,14 +155,16 @@
group.deviceId(), group.type(), group.buckets(),
group.appCookie(), group.id().id(), group.appId());
groupService.addGroup(description);
- location = new URI(Long.toString(group.id().id()));
- } catch (IOException | URISyntaxException ex) {
+ UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
+ .path("groups")
+ .path(deviceId)
+ .path(Long.toString(group.id().id()));
+ return Response
+ .created(locationBuilder.build())
+ .build();
+ } catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
-
- return Response
- .created(location)
- .build();
}
/**
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 f42f9d4..db356ed 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
@@ -34,12 +34,13 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
import static org.onlab.util.Tools.nullIsNotFound;
import static org.slf4j.LoggerFactory.getLogger;
@@ -49,6 +50,10 @@
*/
@Path("meters")
public class MetersWebResource extends AbstractWebResource {
+
+ @Context
+ UriInfo uriInfo;
+
private final Logger log = getLogger(getClass());
public static final String DEVICE_INVALID = "Invalid deviceId in meter creation request";
public static final String METER_NOT_FOUND = "Meter is not found for ";
@@ -131,7 +136,6 @@
@Produces(MediaType.APPLICATION_JSON)
public Response createMeter(@PathParam("deviceId") String deviceId,
InputStream stream) {
- URI location;
try {
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
@@ -143,14 +147,17 @@
jsonTree.put("deviceId", deviceId);
final MeterRequest meterRequest = codec(MeterRequest.class).decode(jsonTree, this);
final Meter meter = meterService.submit(meterRequest);
- location = new URI(Long.toString(meter.id().id()));
- } catch (IOException | URISyntaxException ex) {
+
+ UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
+ .path("meters")
+ .path(deviceId)
+ .path(Long.toString(meter.id().id()));
+ return Response
+ .created(locationBuilder.build())
+ .build();
+ } catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
-
- return Response
- .created(location)
- .build();
}
/**
@@ -217,4 +224,4 @@
return meterRequest;
}
-}
\ No newline at end of file
+}
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 8c073ad..96e3bab 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
@@ -44,7 +44,6 @@
@Path("network/configuration")
public class NetworkConfigWebResource extends AbstractWebResource {
-
private String subjectClassNotFoundErrorString(String subjectClassKey) {
return "Config for '" + subjectClassKey + "' not found";
}