X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frest%2Fimpl%2FXmlNormalizedNodeBodyReader.java;h=294e56a651b83294c491a639f52f674555c636da;hb=31a4027d1a9dff2e0e44e5d4cf97dfd957efa805;hp=50186b8dc76ecece25002c1f6f288f6922d0044d;hpb=349acd05b07357df658d5be5c57e3bdd98add1fe;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlNormalizedNodeBodyReader.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlNormalizedNodeBodyReader.java index 50186b8dc7..294e56a651 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlNormalizedNodeBodyReader.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlNormalizedNodeBodyReader.java @@ -123,8 +123,10 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro final List elements = Collections.singletonList(doc.getDocumentElement()); final SchemaNode schemaNodeContext = pathContext.getSchemaNode(); DataSchemaNode schemaNode; + boolean isRpc = false; if (schemaNodeContext instanceof RpcDefinition) { schemaNode = ((RpcDefinition) schemaNodeContext).getInput(); + isRpc = true; } else if (schemaNodeContext instanceof DataSchemaNode) { schemaNode = (DataSchemaNode) schemaNodeContext; } else { @@ -132,18 +134,22 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro } final String docRootElm = doc.getDocumentElement().getLocalName(); - List iiToDataList = new ArrayList<>(); - InstanceIdentifierContext outIIContext; + final List iiToDataList = new ArrayList<>(); + InstanceIdentifierContext outIIContext; // FIXME the factory instance should be cached if the schema context is the same final DomToNormalizedNodeParserFactory parserFactory = DomToNormalizedNodeParserFactory.getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER, pathContext.getSchemaContext()); - if (isPost()) { + if (isPost() && !isRpc) { final Deque 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()) { - Object child = foundSchemaNodes.pop(); + final Object child = foundSchemaNodes.pop(); if (child instanceof AugmentationSchema) { final AugmentationSchema augmentSchemaNode = (AugmentationSchema) child; iiToDataList.add(SchemaUtils.getNodeIdentifierForAugmentation(augmentSchemaNode)); @@ -161,11 +167,13 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro } else if(schemaNode instanceof ListSchemaNode) { final ListSchemaNode casted = (ListSchemaNode) schemaNode; parsed = parserFactory.getMapEntryNodeParser().parse(elements, casted); - iiToDataList.add(parsed.getIdentifier()); + if (isPost()) { + iiToDataList.add(parsed.getIdentifier()); + } } // FIXME : add another DataSchemaNode extensions e.g. LeafSchemaNode - YangInstanceIdentifier fullIIToData = YangInstanceIdentifier.create(Iterables.concat( + final YangInstanceIdentifier fullIIToData = YangInstanceIdentifier.create(Iterables.concat( pathContext.getInstanceIdentifier().getPathArguments(), iiToDataList)); outIIContext = new InstanceIdentifierContext<>(fullIIToData, pathContext.getSchemaNode(), pathContext.getMountPoint(), @@ -174,7 +182,7 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro return new NormalizedNodeContext(outIIContext, parsed); } - private static Deque findPathToSchemaNodeByName(DataSchemaNode schemaNode, String elementName) { + private static Deque findPathToSchemaNodeByName(final DataSchemaNode schemaNode, final String elementName) { final Deque result = new ArrayDeque<>(); final ArrayList choiceSchemaNodes = new ArrayList<>(); final Collection children = ((DataNodeContainer) schemaNode).getChildNodes(); @@ -213,8 +221,8 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro private static AugmentationSchema findCorrespondingAugment(final DataSchemaNode parent, final DataSchemaNode child) { if (parent instanceof AugmentationTarget && !(parent instanceof ChoiceSchemaNode)) { - for (AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) { - DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName()); + for (final AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) { + final DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName()); if (childInAugmentation != null) { return augmentation; }