Bug 3640 - RPC call error - impossible to call rpc 21/22221/2
authorJan Hajnar <jhajnar@cisco.com>
Tue, 9 Jun 2015 11:02:45 +0000 (13:02 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 10 Jun 2015 09:48:38 +0000 (09:48 +0000)
* disabled children search in post if request is rpc input
* fixed XmlNormalizedNodeBodyReader tests that were testing on wrong rpc
input data

Change-Id: I2602d34a4ab42169959b867acaffa988a11601f3
Signed-off-by: Jan Hajnar <jhajnar@cisco.com>
(cherry picked from commit bc9579fb5cbb7db3b5ce071a9ce4a858c819caf7)

opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlNormalizedNodeBodyReader.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReader.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReaderMountPoint.java
opendaylight/md-sal/sal-rest-connector/src/test/resources/invoke-rpc/xml/rpc-input.xml

index 1933c91e6bd65d210c3b5cf0375f2c4460eb6db3..294e56a651b83294c491a639f52f674555c636da 100644 (file)
@@ -123,8 +123,10 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
         final List<Element> elements = Collections.singletonList(doc.getDocumentElement());
         final SchemaNode schemaNodeContext = pathContext.getSchemaNode();
         DataSchemaNode schemaNode;
         final List<Element> elements = Collections.singletonList(doc.getDocumentElement());
         final SchemaNode schemaNodeContext = pathContext.getSchemaNode();
         DataSchemaNode schemaNode;
+        boolean isRpc = false;
         if (schemaNodeContext instanceof RpcDefinition) {
             schemaNode = ((RpcDefinition) schemaNodeContext).getInput();
         if (schemaNodeContext instanceof RpcDefinition) {
             schemaNode = ((RpcDefinition) schemaNodeContext).getInput();
+            isRpc = true;
         } else if (schemaNodeContext instanceof DataSchemaNode) {
             schemaNode = (DataSchemaNode) schemaNodeContext;
         } else {
         } else if (schemaNodeContext instanceof DataSchemaNode) {
             schemaNode = (DataSchemaNode) schemaNodeContext;
         } else {
@@ -140,14 +142,14 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
         final DomToNormalizedNodeParserFactory parserFactory =
                 DomToNormalizedNodeParserFactory.getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER, pathContext.getSchemaContext());
 
         final DomToNormalizedNodeParserFactory parserFactory =
                 DomToNormalizedNodeParserFactory.getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER, pathContext.getSchemaContext());
 
-        if (isPost()) {
+        if (isPost() && !isRpc) {
             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 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();
+                final Object child = foundSchemaNodes.pop();
                 if (child instanceof AugmentationSchema) {
                     final AugmentationSchema augmentSchemaNode = (AugmentationSchema) child;
                     iiToDataList.add(SchemaUtils.getNodeIdentifierForAugmentation(augmentSchemaNode));
                 if (child instanceof AugmentationSchema) {
                     final AugmentationSchema augmentSchemaNode = (AugmentationSchema) child;
                     iiToDataList.add(SchemaUtils.getNodeIdentifierForAugmentation(augmentSchemaNode));
index bb55b45221239a3a3ce2750816b9f63308aeff32..67f4822c304a5a6e8f4c61c9e00a3e904e686d55 100644 (file)
@@ -162,8 +162,14 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest {
                 .readFrom(null, null, null, mediaType, null, inputStream);
         checkNormalizedNodeContext(returnValue);
         final ContainerNode contNode = (ContainerNode) returnValue.getData();
                 .readFrom(null, null, null, mediaType, null, inputStream);
         checkNormalizedNodeContext(returnValue);
         final ContainerNode contNode = (ContainerNode) returnValue.getData();
-        final YangInstanceIdentifier yangleaf = YangInstanceIdentifier.of(QName.create(contNode.getNodeType(), "lf"));
-        final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = contNode.getChild(yangleaf.getLastPathArgument());
+        final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName.create(contNode.getNodeType(), "cont"));
+        final Optional<DataContainerChild<? extends PathArgument, ?>> contDataNodePotential = contNode.getChild(yangCont
+                .getLastPathArgument());
+        assertTrue(contDataNodePotential.isPresent());
+        final ContainerNode contDataNode = (ContainerNode) contDataNodePotential.get();
+        final YangInstanceIdentifier yangLeaf = YangInstanceIdentifier.of(QName.create(contDataNode.getNodeType(), "lf"));
+        final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = contDataNode.getChild(yangLeaf
+                .getLastPathArgument());
         assertTrue(leafDataNode.isPresent());
         assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue().toString()));
     }
         assertTrue(leafDataNode.isPresent());
         assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue().toString()));
     }
index f1be296c4dc642542fa5bdd4c63c5c2d1db7bac4..888008ca604b02573d0d29b8a9cf9bf41f2741d6 100644 (file)
@@ -132,13 +132,16 @@ public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest {
                 null, null, mediaType, null, inputStream);
         checkNormalizedNodeContext(returnValue);
         final ContainerNode contNode = (ContainerNode) returnValue.getData();
                 null, null, mediaType, null, inputStream);
         checkNormalizedNodeContext(returnValue);
         final ContainerNode contNode = (ContainerNode) returnValue.getData();
-        final YangInstanceIdentifier yangleaf = YangInstanceIdentifier.of(QName
-                .create(contNode.getNodeType(), "lf"));
-        final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = contNode
-                .getChild(yangleaf.getLastPathArgument());
+        final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName.create(contNode.getNodeType(), "cont"));
+        final Optional<DataContainerChild<? extends PathArgument, ?>> contDataNodePotential = contNode.getChild(yangCont
+                .getLastPathArgument());
+        assertTrue(contDataNodePotential.isPresent());
+        final ContainerNode contDataNode = (ContainerNode) contDataNodePotential.get();
+        final YangInstanceIdentifier yangLeaf = YangInstanceIdentifier.of(QName.create(contDataNode.getNodeType(), "lf"));
+        final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = contDataNode.getChild(yangLeaf
+                .getLastPathArgument());
         assertTrue(leafDataNode.isPresent());
         assertTrue(leafDataNode.isPresent());
-        assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue()
-                .toString()));
+        assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue().toString()));
     }
 
     private void checkExpectValueNormalizeNodeContext(
     }
 
     private void checkExpectValueNormalizeNodeContext(
index 20a3ecb93f8e3dc1ea3b3f738a57b82b9ea548e4..48fb55707095908521d981eb64b4bae733fbeed3 100644 (file)
@@ -1,3 +1,5 @@
-<cont xmlns="invoke:rpc:module">
-    <lf>lf-test</lf>
-</cont>
\ No newline at end of file
+<input xmlns="invoke:rpc:module">
+    <cont>
+        <lf>lf-test</lf>
+    </cont>
+</input>
\ No newline at end of file