Bug 3039 - PUT augmentNode like last path element 85/22085/2
authorVaclav Demcak <vdemcak@cisco.com>
Thu, 4 Jun 2015 16:13:48 +0000 (18:13 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 8 Jun 2015 11:33:40 +0000 (11:33 +0000)
* fixed JsonNormalizedNodeBodyReader error when PUT operation was used
and data were wrapped in augmentation or choice nodes
* fixed bug that allowed XmlNormalizedNodeBodyReader to parse PUT with
incorrect data (when PUT request was written as POST)

note: testet manualy describled scenario + CSIT OFP_test_suite

Change-Id: Ia25b6b45a1154866dea29c763be67cdb17fa0ce1
Signed-off-by: Jan Hajnar <jhajnar@cisco.com>
Signed-off-by: Vaclav Demcak <vdemcak@cisco.com>
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonNormalizedNodeBodyReader.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlNormalizedNodeBodyReader.java

index 265811a86b006ab50c70dc75a780100a2712f9d1..42024cab08748cadc9abf338f496e055a616722d 100644 (file)
@@ -96,12 +96,15 @@ public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPr
             final List<YangInstanceIdentifier.PathArgument> iiToDataList = new ArrayList<>();
             InstanceIdentifierContext<? extends SchemaNode> newIIContext;
 
-            if (isPost()) {
-                while (result instanceof AugmentationNode || result instanceof ChoiceNode) {
-                    final Object childNode = ((DataContainerNode) result).getValue().iterator().next();
+            while (result instanceof AugmentationNode || result instanceof ChoiceNode) {
+                final Object childNode = ((DataContainerNode) result).getValue().iterator().next();
+                if (isPost()) {
                     iiToDataList.add(result.getIdentifier());
-                    result = (NormalizedNode<?, ?>) childNode;
                 }
+                result = (NormalizedNode<?, ?>) childNode;
+            }
+
+            if (isPost()) {
                 if (result instanceof MapEntryNode) {
                     iiToDataList.add(new YangInstanceIdentifier.NodeIdentifier(result.getNodeType()));
                     iiToDataList.add(result.getIdentifier());
index d2c75f7e0ccfb6b8f4d82d78e7ea0b0a1e0c7971..1933c91e6bd65d210c3b5cf0375f2c4460eb6db3 100644 (file)
@@ -142,6 +142,10 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
 
         if (isPost()) {
             final Deque<Object> foundSchemaNodes = findPathToSchemaNodeByName(schemaNode, docRootElm);
+            if (foundSchemaNodes.isEmpty()) {
+                throw new IllegalStateException(String.format("Child \"%s\" was not found in parent schema node \"%s\"",
+                        docRootElm, schemaNode.getQName()));
+            }
             while (!foundSchemaNodes.isEmpty()) {
                 final Object child  = foundSchemaNodes.pop();
                 if (child instanceof AugmentationSchema) {