[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/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
+}