Use well-known Status enumeration 10/97110/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 9 Aug 2021 13:08:01 +0000 (15:08 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 9 Aug 2021 14:51:22 +0000 (16:51 +0200)
Response.status() can be used with an int, but that ends up walking all
Status.values() in an attempt to find the corresponding constant. While
we end up hitting the first element, use Status.OK explicitly to speed
things up a bit.

Change-Id: I7c72a88602c95ec4c7274369a9e5c613c3ce3b9b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit fdf3ba286a9fd8312abf6e4e5547fe8004987d61)

restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java

index 8b020cff5896daa0aab14a511cd1ee0448b06554..eeff1134026f366fdadbe07be4d18f6ea8ddec6f 100644 (file)
@@ -28,6 +28,7 @@ import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import javax.ws.rs.Path;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.UriInfo;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@@ -179,7 +180,7 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         if (parameters.getContent().equals(RestconfDataServiceConstant.ReadData.ALL)
                     || parameters.getContent().equals(RestconfDataServiceConstant.ReadData.CONFIG)) {
             final QName type = node.getNodeType();
-            return Response.status(200)
+            return Response.status(Status.OK)
                     .entity(new NormalizedNodeContext(instanceIdentifier, node, parameters))
                     .header("ETag", '"' + type.getModule().getRevision().map(Revision::toString).orElse(null)
                         + "-" + type.getLocalName() + '"')
@@ -187,7 +188,9 @@ public class RestconfDataServiceImpl implements RestconfDataService {
                     .build();
         }
 
-        return Response.status(200).entity(new NormalizedNodeContext(instanceIdentifier, node, parameters)).build();
+        return Response.status(Status.OK)
+            .entity(new NormalizedNodeContext(instanceIdentifier, node, parameters))
+            .build();
     }
 
     /**
@@ -441,11 +444,14 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         }
 
         if (resultData != null && resultData.getValue().isEmpty()) {
-            return Response.status(Response.Status.NO_CONTENT).build();
+            return Response.status(Status.NO_CONTENT).build();
         }
 
-        return Response.status(200).entity(new NormalizedNodeContext(new InstanceIdentifierContext<>(yangIIdContext,
-                resultNodeSchema, mountPoint, schemaContextRef), resultData)).build();
+        return Response.status(Status.OK)
+            .entity(new NormalizedNodeContext(
+                new InstanceIdentifierContext<>(yangIIdContext, resultNodeSchema, mountPoint, schemaContextRef),
+                resultData))
+            .build();
     }
 
     private static EffectiveModelContext modelContext(final DOMMountPoint mountPoint) {