Use well-known Status enumeration 08/97108/1
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 13:08:01 +0000 (15:08 +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>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java

index b8eebc06faa17b27ef40a0ccbd2a1d6f02cfd5d5..7b4e67a0278f9dea8994c464d49ef81dacd68fa6 100644 (file)
@@ -31,6 +31,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;
@@ -176,7 +177,7 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         if (parameters.getContent().equals(RestconfDataServiceConstant.ReadData.ALL)
                     || parameters.getContent().equals(RestconfDataServiceConstant.ReadData.CONFIG)) {
             final QName type = node.getIdentifier().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() + '"')
@@ -184,7 +185,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();
     }
 
     private void createAllYangNotificationStreams(final EffectiveModelContext schemaContext, final UriInfo uriInfo) {
@@ -412,11 +415,14 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         }
 
         if (resultData != null && resultData.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();
     }
 
     /**