From fdf3ba286a9fd8312abf6e4e5547fe8004987d61 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 9 Aug 2021 15:08:01 +0200 Subject: [PATCH] Use well-known Status enumeration 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 --- .../services/impl/RestconfDataServiceImpl.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java index b8eebc06fa..7b4e67a027 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java @@ -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(); } /** -- 2.36.6