Merge "Bug 7172 - Correct error-info for missing-attribute errors"
authorTomas Cere <tcere@cisco.com>
Tue, 29 Nov 2016 13:08:31 +0000 (13:08 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 29 Nov 2016 13:08:31 +0000 (13:08 +0000)
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 c142e5b3b5bb70691b0da9cdd3354a5cd4a6c0ed..5dca727c4cc99a63bea1b46ce7846beeaa22db47 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;
@@ -221,7 +223,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 d6ad19ae0c0835aeb08c622f6f195163cbc14295..b6c8d11a95afaf85da9285b55829ad04adcf8c3a 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));
     }
 }