Check error conditions before processing 99/99799/1
authorIvan Hrasko <ivan.hrasko@pantheon.tech>
Fri, 18 Feb 2022 19:12:31 +0000 (20:12 +0100)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Fri, 18 Feb 2022 19:16:11 +0000 (20:16 +0100)
First we have to check if yangIIdContext empty content does not mean
the error and only then we can use it in further processing.

JIRA: NETCONF-818
Change-Id: I81593f323a48ea47d91f5aeb424729408efed2ad
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java

index 5434ac373d47427e946a1d247723e42ebea0ffbf..f50951d5d7d641b7a817a2bd54e39eb2aff096d7 100644 (file)
@@ -320,20 +320,21 @@ public class RestconfDataServiceImpl implements RestconfDataService {
     public Response invokeAction(final NormalizedNodePayload payload) {
         final InstanceIdentifierContext<?> context = payload.getInstanceIdentifierContext();
         final DOMMountPoint mountPoint = context.getMountPoint();
-        final List<QName> qNames = context.getInstanceIdentifier().getPathArguments().stream()
+
+        final YangInstanceIdentifier yangIIdContext = context.getInstanceIdentifier();
+        final NormalizedNode data = payload.getData();
+        if (yangIIdContext.isEmpty() && !NETCONF_BASE_QNAME.equals(data.getIdentifier().getNodeType())) {
+            throw new RestconfDocumentedException("Instance identifier need to contain at least one path argument",
+                    ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
+        }
+
+        final List<QName> qNames = yangIIdContext.getPathArguments().stream()
                 .filter(arg -> !(arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates))
                 .filter(arg -> !(arg instanceof YangInstanceIdentifier.AugmentationIdentifier))
                 .map(PathArgument::getNodeType)
                 .collect(Collectors.toList());
         qNames.add(context.getSchemaNode().getQName());
         final Absolute schemaPath = Absolute.of(qNames);
-        final YangInstanceIdentifier yangIIdContext = context.getInstanceIdentifier();
-        final NormalizedNode data = payload.getData();
-
-        if (yangIIdContext.isEmpty() && !NETCONF_BASE_QNAME.equals(data.getIdentifier().getNodeType())) {
-            throw new RestconfDocumentedException("Instance identifier need to contain at least one path argument",
-                ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
-        }
 
         final DOMActionResult response;
         final EffectiveModelContext schemaContextRef;
@@ -367,7 +368,6 @@ public class RestconfDataServiceImpl implements RestconfDataService {
             .build();
     }
 
-
     /**
      * Invoking Action via mount point.
      *