Bug 7172 - Correct error-info for missing-attribute errors 85/48785/1
authorJakub Morvay <jmorvay@cisco.com>
Mon, 14 Nov 2016 14:22:25 +0000 (15:22 +0100)
committerJakub Morvay <jmorvay@cisco.com>
Tue, 29 Nov 2016 13:28:52 +0000 (14:28 +0100)
Add bad-attribute and bad-element information to error-info when
constructing missing-attribute rpc-error.

Change-Id: I96652e3154c8ebdba53396360f5ddfe6a5ec0211
Signed-off-by: Jakub Morvay <jmorvay@cisco.com>
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditConfig.java
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionListener.java

index 48c353ec5ed38bf4432619ae45cfe1301a96e63c..4b5b80aa0cc94a55efc1988d3773b15d213f6cf2 100644 (file)
@@ -9,11 +9,13 @@
 package org.opendaylight.netconf.mdsal.connector.ops;
 
 import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMap;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Collections;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.Map;
 import org.opendaylight.controller.config.util.xml.DocumentedException;
 import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorSeverity;
 import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorTag;
@@ -193,7 +195,9 @@ public class EditConfig extends AbstractSingletonNetconfOperation {
         final NodeList elementsByTagName = operationElement.getDomElement().getElementsByTagName(TARGET_KEY);
         // Direct lookup instead of using XmlElement class due to performance
         if (elementsByTagName.getLength() == 0) {
-            throw new DocumentedException("Missing target element", ErrorType.rpc, ErrorTag.missing_attribute, ErrorSeverity.error);
+            Map<String, String> errorInfo = ImmutableMap.of("bad-attribute", TARGET_KEY, "bad-element", OPERATION_NAME);
+            throw new DocumentedException("Missing target element",
+                    ErrorType.protocol, ErrorTag.missing_attribute, ErrorSeverity.error, errorInfo);
         } else if (elementsByTagName.getLength() > 1) {
             throw new DocumentedException("Multiple target elements", ErrorType.rpc, ErrorTag.unknown_attribute, ErrorSeverity.error);
         } else {
index 4117c3189f29e8cf13a1913238e54ec7f9995518..fba5f6dc0c4ec16c8cd33c76199ebcb6634c811b 100644 (file)
@@ -153,10 +153,10 @@ public class NetconfServerSessionListener implements NetconfSessionListener<Netc
             return;
         }
 
-        throw new DocumentedException("Missing attribute" + rootNode.getNodeName(),
-                DocumentedException.ErrorType.protocol, DocumentedException.ErrorTag.missing_attribute,
+        throw new DocumentedException("Missing attribute " + rootNode.getNodeName(),
+                DocumentedException.ErrorType.rpc, DocumentedException.ErrorTag.missing_attribute,
                 DocumentedException.ErrorSeverity.error,
-                ImmutableMap.of(DocumentedException.ErrorTag.missing_attribute.toString(),
-                        XmlNetconfConstants.MESSAGE_ID));
+                ImmutableMap.of("bad-attribute", XmlNetconfConstants.MESSAGE_ID,
+                        "bad-element", XmlNetconfConstants.RPC_KEY));
     }
 }