Add netconf.api.NamespaceURN 50/105850/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 6 May 2023 10:44:17 +0000 (12:44 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 6 May 2023 11:00:16 +0000 (13:00 +0200)
XmlNetconfConstants is a huge constant holder, with very baroque names
for namespaces. Split out NamespaceURN, which holds these namespaces in
the same way CapabilityURN holds capability namespaces.

JIRA: NETCONF-1019
Change-Id: Iae8cd44438fac353877e282a0de451b095dd35e1
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
21 files changed:
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/exi/NetconfStartExiMessage.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/monitoring/Get.java
plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceCommunicatorTest.java
plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/AbstractConfigOperation.java
plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/AbstractGet.java
plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/CopyConfig.java
plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/RuntimeRpc.java
protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java
protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/NamespaceURN.java [new file with mode: 0644]
protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/HelloMessage.java
protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NotificationMessage.java
protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlNetconfConstants.java
protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/NetconfDocumentedExceptionTest.java
protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/XMLNetconfUtil.java
protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/NetconfServerSessionListener.java
protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/SendErrorExceptionUtil.java
protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/api/operations/AbstractNetconfOperation.java
protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/mapping/operations/DefaultStartExi.java
protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/mapping/operations/DefaultStopExi.java
protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/spi/SubtreeFilter.java

index 148d80ad5bca69c5e3fefcefad423408f644cd4b..a644150e67a6e5e374f9223379038dbcec9bf37f 100644 (file)
@@ -28,6 +28,7 @@ import org.checkerframework.checker.lock.qual.Holding;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.netconf.api.CapabilityURN;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.NetconfSessionListener;
@@ -321,9 +322,7 @@ public abstract class AbstractNetconfSessionNegotiator<S extends AbstractNetconf
     }
 
     private static boolean containsBase11Capability(final Document doc) {
-        final NodeList nList = doc.getElementsByTagNameNS(
-            XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-            XmlNetconfConstants.CAPABILITY);
+        final NodeList nList = doc.getElementsByTagNameNS(NamespaceURN.BASE, XmlNetconfConstants.CAPABILITY);
         for (int i = 0; i < nList.getLength(); i++) {
             if (nList.item(i).getTextContent().contains(CapabilityURN.BASE_1_1)) {
                 return true;
index b7e94bb77fa05ac6864789600fdc4b7375a8313c..2f7a44db083845f3b7c54b3c809f1954ef431e93 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.netconf.nettyutil.handler.exi;
 import com.google.common.annotations.VisibleForTesting;
 import java.util.ArrayList;
 import java.util.List;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.api.xml.XmlUtil;
@@ -31,15 +32,12 @@ public final class NetconfStartExiMessage extends NetconfMessage {
 
     public static NetconfStartExiMessage create(final EXIParameters exiOptions, final String messageId) {
         final Document doc = XmlUtil.newDocument();
-        final Element rpcElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-                XmlNetconfConstants.RPC_KEY);
-        rpcElement.setAttributeNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-                XmlNetconfConstants.MESSAGE_ID, messageId);
+        final Element rpcElement = doc.createElementNS(NamespaceURN.BASE, XmlNetconfConstants.RPC_KEY);
+        rpcElement.setAttributeNS(NamespaceURN.BASE, XmlNetconfConstants.MESSAGE_ID, messageId);
 
         // TODO draft http://tools.ietf.org/html/draft-varga-netconf-exi-capability-02#section-3.5.1 has no namespace
         // for start-exi element in xml
-        final Element startExiElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0,
-                START_EXI);
+        final Element startExiElement = doc.createElementNS(NamespaceURN.EXI, START_EXI);
 
         addAlignment(exiOptions, doc, startExiElement);
         addFidelity(exiOptions, doc, startExiElement);
@@ -53,8 +51,7 @@ public final class NetconfStartExiMessage extends NetconfMessage {
 
     private static void addAlignment(final EXIParameters exiOptions, final Document doc,
             final Element startExiElement) {
-        final Element alignmentElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0,
-            EXIParameters.EXI_PARAMETER_ALIGNMENT);
+        final Element alignmentElement = doc.createElementNS(NamespaceURN.EXI, EXIParameters.EXI_PARAMETER_ALIGNMENT);
 
         alignmentElement.setTextContent(exiOptions.getAlignment());
         startExiElement.appendChild(alignmentElement);
@@ -69,8 +66,7 @@ public final class NetconfStartExiMessage extends NetconfMessage {
         createFidelityElement(doc, fidelityElements, exiOptions.getPreservePrefixes());
 
         if (!fidelityElements.isEmpty()) {
-            final Element fidelityElement = doc.createElementNS(
-                    XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0, EXIParameters.EXI_PARAMETER_FIDELITY);
+            final Element fidelityElement = doc.createElementNS(NamespaceURN.EXI, EXIParameters.EXI_PARAMETER_FIDELITY);
             for (final Element element : fidelityElements) {
                 fidelityElement.appendChild(element);
             }
@@ -81,8 +77,7 @@ public final class NetconfStartExiMessage extends NetconfMessage {
     private static void addSchema(final EXIParameters exiOptions, final Document doc, final Element startExiElement) {
         final String schema = exiOptions.getSchema();
         if (schema != null) {
-            final Element child = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0,
-                EXIParameters.EXI_PARAMETER_SCHEMAS);
+            final Element child = doc.createElementNS(NamespaceURN.EXI, EXIParameters.EXI_PARAMETER_SCHEMAS);
             child.setTextContent(schema);
             startExiElement.appendChild(child);
         }
@@ -91,7 +86,7 @@ public final class NetconfStartExiMessage extends NetconfMessage {
     private static void createFidelityElement(final Document doc, final List<Element> elements,
                                               final String fidelity) {
         if (fidelity != null) {
-            elements.add(doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0, fidelity));
+            elements.add(doc.createElementNS(NamespaceURN.EXI, fidelity));
         }
     }
 }
index d704008c80d35bda73147098fa0d0e9b58478093..a5e2a66914a5160ffc5ba16d90e22c7f52cdc549 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.netconf.test.tool.monitoring;
 
 import java.util.Map;
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.server.api.monitoring.NetconfMonitoringService;
@@ -83,7 +84,7 @@ public class Get extends AbstractNetconfOperation {
 
     private static Element getPlaceholder(final Document innerResult) throws DocumentedException {
         return XmlElement.fromDomElementWithExpected(innerResult.getDocumentElement(),
-            XmlNetconfConstants.RPC_REPLY_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0)
+            XmlNetconfConstants.RPC_REPLY_KEY, NamespaceURN.BASE)
             .getOnlyChildElement(XmlNetconfConstants.DATA_KEY)
             .getDomElement();
     }
index a8a4cb36426cb31639506b2252bdd873a1713ba6..1f283eaa0060d51cd8693a9dacbfb15c7851fbfc 100644 (file)
@@ -24,7 +24,6 @@ import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.withSettings;
-import static org.opendaylight.netconf.api.xml.XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0;
 
 import com.google.common.base.CharMatcher;
 import com.google.common.base.Strings;
@@ -54,6 +53,7 @@ import org.mockito.Mock;
 import org.mockito.MockMakers;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.netconf.api.CapabilityURN;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.NetconfTerminationReason;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
@@ -266,8 +266,7 @@ public class NetconfDeviceCommunicatorTest {
     private static NetconfMessage createSuccessResponseMessage(final String messageID)
             throws ParserConfigurationException {
         Document doc = UntrustedXML.newDocumentBuilder().newDocument();
-        Element rpcReply =
-                doc.createElementNS(URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlNetconfConstants.RPC_REPLY_KEY);
+        Element rpcReply = doc.createElementNS(NamespaceURN.BASE, XmlNetconfConstants.RPC_REPLY_KEY);
         rpcReply.setAttribute("message-id", messageID);
         Element element = doc.createElementNS("ns", "data");
         element.setTextContent(messageID);
index 634bfbe9e8e8a0ef470970a27f5c8fbb943e6cd6..3d2ba73e3b67903d83d2b67fd8ba939374123335 100644 (file)
@@ -19,8 +19,8 @@ import java.net.URLStreamHandler;
 import java.util.Base64;
 import java.util.Optional;
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.xml.XmlElement;
-import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.server.api.operations.AbstractSingletonNetconfOperation;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
@@ -66,8 +66,7 @@ abstract class AbstractConfigOperation extends AbstractSingletonNetconfOperation
                 ErrorType.PROTOCOL, ErrorTag.MISSING_ELEMENT, ErrorSeverity.ERROR));
 
         final Document document = getDocumentFromUrl(urlElement.getTextContent());
-        return XmlElement.fromDomElementWithExpected(document.getDocumentElement(), CONFIG_KEY,
-            XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+        return XmlElement.fromDomElementWithExpected(document.getDocumentElement(), CONFIG_KEY, NamespaceURN.BASE);
     }
 
     /**
index cac853f207e5b4b2deae285e5c7f275af31d5251..577f7700d73b22e996d89fdee24a96b75c88ad7c 100644 (file)
@@ -17,6 +17,7 @@ import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.dom.DOMResult;
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.server.api.operations.AbstractSingletonNetconfOperation;
@@ -179,15 +180,15 @@ abstract class AbstractGet extends AbstractSingletonNetconfOperation {
 
         private static Optional<Datastore> parseSource(final XmlElement xml) throws DocumentedException {
             final Optional<XmlElement> sourceElement = xml.getOnlyChildElementOptionally(XmlNetconfConstants.SOURCE_KEY,
-                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+                NamespaceURN.BASE);
             return sourceElement.isEmpty() ? Optional.empty()
                 : Optional.of(Datastore.valueOf(sourceElement.orElseThrow().getOnlyChildElement().getName()));
         }
 
-        private static void validateInputRpc(final XmlElement xml, final String operationName) throws
-                DocumentedException {
+        private static void validateInputRpc(final XmlElement xml, final String operationName)
+                throws DocumentedException {
             xml.checkName(operationName);
-            xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+            xml.checkNamespace(NamespaceURN.BASE);
         }
 
         public Optional<Datastore> getDatastore() {
index fdab94dee424b1456ca76f0b9021cd9a2062de43..c1aeaad34bc3e935791b99e5e052f0517ea66869 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.netconf.server.mdsal.operations;
 
-import static org.opendaylight.netconf.api.xml.XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0;
-
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -26,6 +24,7 @@ import javax.xml.transform.dom.DOMResult;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.api.xml.XmlUtil;
@@ -184,7 +183,7 @@ public final class CopyConfig extends AbstractEdit {
     }
 
     private Node transformNormalizedNode(final Document document, final ContainerNode data) {
-        final Element configElement = document.createElementNS(URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, CONFIG_KEY);
+        final Element configElement = document.createElementNS(NamespaceURN.BASE, CONFIG_KEY);
         final DOMResult result = new DOMResult(configElement);
         try {
             final XMLStreamWriter xmlWriter = XML_OUTPUT_FACTORY.createXMLStreamWriter(result);
index 1e3efd4b59aa26f0ec5cc8606838d1c05625ca21..e4dc20071230494616df97c8367a4868faae4cd8 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
@@ -155,8 +156,7 @@ public class RuntimeRpc extends AbstractSingletonNetconfOperation {
             throw DocumentedException.wrap(e);
         }
         if (result.value() == null) {
-            return XmlUtil.createElement(document, XmlNetconfConstants.OK,
-                Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
+            return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.of(NamespaceURN.BASE));
         }
         return transformNormalizedNode(document, result.value(),
                 Absolute.of(rpcDefinition.getQName(), rpcDefinition.getOutput().getQName()));
@@ -172,7 +172,7 @@ public class RuntimeRpc extends AbstractSingletonNetconfOperation {
 
         final Element response = handle(document, operationElement, subsequentOperation);
         final Element rpcReply = XmlUtil.createElement(document, XmlNetconfConstants.RPC_REPLY_KEY,
-                Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
+                Optional.of(NamespaceURN.BASE));
 
         if (XmlElement.fromDomElement(response).hasNamespace()) {
             rpcReply.appendChild(response);
index b8224def1000887f311b1adf5fb633e3c30a4834..61eadb2b26b07f5ae4b1aef67381e6df3d1fb7b4 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.netconf.api;
 
 import static org.opendaylight.netconf.api.xml.XmlNetconfConstants.RPC_REPLY_KEY;
-import static org.opendaylight.netconf.api.xml.XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -199,19 +198,19 @@ public class DocumentedException extends Exception {
 
     // FIXME: NETCONF-793: remove all of these in favor of YangNetconfErrorAware
     public ErrorType getErrorType() {
-        return this.errorType;
+        return errorType;
     }
 
     public ErrorTag getErrorTag() {
-        return this.errorTag;
+        return errorTag;
     }
 
     public ErrorSeverity getErrorSeverity() {
-        return this.errorSeverity;
+        return errorSeverity;
     }
 
     public Map<String, String> getErrorInfo() {
-        return this.errorInfo;
+        return errorInfo;
     }
 
     // FIXME: this really should be an spi/util method (or even netconf-util-w3c-dom?) as this certainly is not the
@@ -221,10 +220,10 @@ public class DocumentedException extends Exception {
         try {
             doc = BUILDER_FACTORY.newDocumentBuilder().newDocument();
 
-            Node rpcReply = doc.createElementNS(URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, RPC_REPLY_KEY);
+            Node rpcReply = doc.createElementNS(NamespaceURN.BASE, RPC_REPLY_KEY);
             doc.appendChild(rpcReply);
 
-            Node rpcError = doc.createElementNS(URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, RPC_ERROR);
+            Node rpcError = doc.createElementNS(NamespaceURN.BASE, RPC_ERROR);
             rpcReply.appendChild(rpcError);
 
             rpcError.appendChild(createTextNode(doc, ERROR_TYPE, getErrorType().elementBody()));
@@ -239,7 +238,7 @@ public class DocumentedException extends Exception {
                  * <bad-element>rpc</bad-element> </error-info>
                  */
 
-                Node errorInfoNode = doc.createElementNS(URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, ERROR_INFO);
+                Node errorInfoNode = doc.createElementNS(NamespaceURN.BASE, ERROR_INFO);
                 errorInfoNode.setPrefix(rpcReply.getPrefix());
                 rpcError.appendChild(errorInfoNode);
 
@@ -256,15 +255,15 @@ public class DocumentedException extends Exception {
     }
 
     private static Node createTextNode(final Document doc, final String tag, final String textContent) {
-        Node node = doc.createElementNS(URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, tag);
+        Node node = doc.createElementNS(NamespaceURN.BASE, tag);
         node.setTextContent(textContent);
         return node;
     }
 
     @Override
     public String toString() {
-        return "NetconfDocumentedException{" + "message=" + getMessage() + ", errorType=" + this.errorType
-                + ", errorTag=" + this.errorTag + ", errorSeverity=" + this.errorSeverity + ", errorInfo="
-                + this.errorInfo + '}';
+        return "NetconfDocumentedException{" + "message=" + getMessage() + ", errorType=" + errorType
+                + ", errorTag=" + errorTag + ", errorSeverity=" + errorSeverity + ", errorInfo="
+                + errorInfo + '}';
     }
 }
diff --git a/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/NamespaceURN.java b/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/NamespaceURN.java
new file mode 100644 (file)
index 0000000..1cc0145
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.api;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * The contents of
+ * <a href="https://www.iana.org/assignments/xml-registry/xml-registry.xhtml#ns">IETF XML ns Registry</a>relevant to
+ * NETCONF.
+ */
+@NonNullByDefault
+public final class NamespaceURN {
+    /**
+     * The NETCONF protocol XML namespace, as defined by <a href="https://www.rfc-editor.org/rfc/rfc6241">RFC6241</a>.
+     */
+    public static final String BASE = "urn:ietf:params:xml:ns:netconf:base:1.0";
+    /**
+     * The namespace used by the
+     * <a href="https://www.rfc-editor.org/rfc/rfc6243">With-defaults Capability for NETCONF</a> extension.
+     */
+    public static final String DEFAULT = "urn:ietf:params:xml:ns:netconf:default:1.0";
+    /**
+     * The namespace used by the
+     * <a href="https://datatracker.ietf.org/doc/html/draft-varga-netconf-exi-capability-01">
+     * Efficient XML Interchange Capability for NETCONF</a> extension. Note this is an expired IETF draft capability and
+     * subject to change.
+     */
+    @Beta
+    public static final String EXI = "urn:ietf:params:xml:ns:netconf:exi:1.0";
+    /**
+     * The namespace used by the <a href="https://www.rfc-editor.org/rfc/rfc5277">NETCONF Event Notifications</a>
+     * extension.
+     */
+    public static final String NOTIFICATION = "urn:ietf:params:xml:ns:netconf:notification:1.0";
+    /**
+     * The namespace used by the <a href="https://www.rfc-editor.org/rfc/rfc5717">
+     * Partial Lock Remote Procedure Call (RPC) for NETCONF</a> extension.
+     */
+    public static final String PARTIAL_LOCK = "urn:ietf:params:xml:ns:netconf:partial-lock:1.0";
+
+    private NamespaceURN() {
+        // Hidden on purpose
+    }
+}
index 57c8e33af81bdbd17c9273efe945ff7feedda4c8..4409adaaa507fd7991c854f9bef2697c293b2538 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.api.messages;
 import com.google.common.collect.Sets;
 import java.util.Optional;
 import java.util.Set;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
@@ -47,7 +48,7 @@ public final class HelloMessage extends NetconfMessage {
         if (!isHelloMessage(doc)) {
             throw new IllegalArgumentException(String.format(
                 "Hello message invalid format, should contain %s tag from namespace %s, but is: %s", HELLO_TAG,
-                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlUtil.toString(doc)));
+                NamespaceURN.BASE, XmlUtil.toString(doc)));
         }
     }
 
@@ -58,14 +59,11 @@ public final class HelloMessage extends NetconfMessage {
 
     private static Document createHelloMessageDoc(final Iterable<String> capabilities) {
         Document doc = UntrustedXML.newDocumentBuilder().newDocument();
-        Element helloElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-                HELLO_TAG);
-        Element capabilitiesElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-                XmlNetconfConstants.CAPABILITIES);
+        Element helloElement = doc.createElementNS(NamespaceURN.BASE, HELLO_TAG);
+        Element capabilitiesElement = doc.createElementNS(NamespaceURN.BASE, XmlNetconfConstants.CAPABILITIES);
 
         for (String capability : Sets.newHashSet(capabilities)) {
-            Element capElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-                    XmlNetconfConstants.CAPABILITY);
+            Element capElement = doc.createElementNS(NamespaceURN.BASE, XmlNetconfConstants.CAPABILITY);
             capElement.setTextContent(capability);
             capabilitiesElement.appendChild(capElement);
         }
@@ -78,8 +76,7 @@ public final class HelloMessage extends NetconfMessage {
 
     public static HelloMessage createServerHello(final Set<String> capabilities, final SessionIdType sessionId) {
         Document doc = createHelloMessageDoc(capabilities);
-        Element sessionIdElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-                XmlNetconfConstants.SESSION_ID);
+        Element sessionIdElement = doc.createElementNS(NamespaceURN.BASE, XmlNetconfConstants.SESSION_ID);
         sessionIdElement.setTextContent(sessionId.getValue().toCanonicalString());
         doc.getDocumentElement().appendChild(sessionIdElement);
         return new HelloMessage(doc);
@@ -97,6 +94,6 @@ public final class HelloMessage extends NetconfMessage {
 
         final var namespace = element.namespace();
         // accept even if hello has no namespace
-        return namespace == null || XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0.equals(namespace);
+        return namespace == null || NamespaceURN.BASE.equals(namespace);
     }
 }
index f7b31d8442c2634e7b4ed3492d90adf7632f31ac..66da0ffe79f8ecba336020c8fd45f70983b9f0ff 100644 (file)
@@ -21,6 +21,7 @@ import java.time.temporal.ChronoField;
 import java.time.temporal.TemporalAccessor;
 import java.util.function.Function;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.slf4j.Logger;
@@ -195,12 +196,11 @@ public final class NotificationMessage extends NetconfMessage {
 
         final Element baseNotification = notificationContent.getDocumentElement();
         final Element entireNotification = notificationContent.createElementNS(
-            XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_NOTIFICATION_1_0,
-            XmlNetconfConstants.NOTIFICATION_ELEMENT_NAME);
+            NamespaceURN.NOTIFICATION, XmlNetconfConstants.NOTIFICATION_ELEMENT_NAME);
         entireNotification.appendChild(baseNotification);
 
         final Element eventTimeElement = notificationContent.createElementNS(
-            XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_NOTIFICATION_1_0, XmlNetconfConstants.EVENT_TIME);
+            NamespaceURN.NOTIFICATION, XmlNetconfConstants.EVENT_TIME);
         eventTimeElement.setTextContent(RFC3339_DATE_FORMATTER.apply(eventTime));
         entireNotification.appendChild(eventTimeElement);
 
index 726d1913419c73dc0e67d6d1a2303b797bc0c00b..12558ffe0b0881b89709eb6dacb8c6cc3b7999d8 100644 (file)
@@ -30,11 +30,6 @@ public final class XmlNetconfConstants {
 
     public static final String RPC_REPLY_KEY = "rpc-reply";
 
-    public static final String URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0 = "urn:ietf:params:xml:ns:netconf:base:1.0";
-    public static final String URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0 = "urn:ietf:params:xml:ns:netconf:exi:1.0";
-    public static final String URN_IETF_PARAMS_XML_NS_NETCONF_NOTIFICATION_1_0 =
-        "urn:ietf:params:xml:ns:netconf:notification:1.0";
-
     private XmlNetconfConstants() {
         // Hidden on purpose
     }
index f4261f0a7fc0bda515fa0bf8d8fb213382b4b6b9..91ad34e50f1def5d0c85f47214a55c08a6b8ef5c 100644 (file)
@@ -20,7 +20,6 @@ import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
@@ -54,7 +53,7 @@ public class NetconfDocumentedExceptionTest {
 
             @Override
             public String getNamespaceURI(final String prefix) {
-                return XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0;
+                return NamespaceURN.BASE;
             }
         });
     }
index a819edf4582cb6120e35afaccfd0c505465874c1..381ddfd4b0c2513a7f66a4ea735e9683af5bcc37 100644 (file)
@@ -12,12 +12,11 @@ import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathExpression;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
-import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
+import org.opendaylight.netconf.api.NamespaceURN;
 
 final class XMLNetconfUtil {
     private static final XPathFactory FACTORY = XPathFactory.newInstance();
-    private static final NamespaceContext NS_CONTEXT = new HardcodedNamespaceResolver("netconf",
-        XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+    private static final NamespaceContext NS_CONTEXT = new HardcodedNamespaceResolver("netconf", NamespaceURN.BASE);
 
     private XMLNetconfUtil() {
         // Hidden on purpose
index f03d8d3914de37cf5d99d704ba0c607291f01a26..9e7cc53e51049f6eabb16bf89ea5120a5fee32b0 100644 (file)
@@ -12,6 +12,7 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.NetconfSessionListener;
 import org.opendaylight.netconf.api.NetconfTerminationReason;
@@ -151,14 +152,10 @@ public class NetconfServerSessionListener implements NetconfSessionListener<Netc
     }
 
     private static void checkMessageId(final Node rootNode) throws DocumentedException {
-
         final NamedNodeMap attributes = rootNode.getAttributes();
-
-        if (attributes.getNamedItemNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-                XmlNetconfConstants.MESSAGE_ID) != null) {
+        if (attributes.getNamedItemNS(NamespaceURN.BASE, XmlNetconfConstants.MESSAGE_ID) != null) {
             return;
         }
-
         if (attributes.getNamedItem(XmlNetconfConstants.MESSAGE_ID) != null) {
             return;
         }
index 63cb3194a2ebe8c8a5365dbc57a7b99719571643..6a68b333e69931c2d52cc6050d9fdd4b97d76a2d 100644 (file)
@@ -13,6 +13,7 @@ import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelFutureListener;
 import javax.xml.XMLConstants;
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.NetconfSession;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
@@ -64,7 +65,7 @@ public final class SendErrorExceptionUtil {
             final Element incommingRpc = incommingDocument.getDocumentElement();
             Preconditions.checkState(
                 XmlNetconfConstants.RPC_KEY.equals(incommingRpc.getLocalName())
-                && XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0.equals(incommingRpc.getNamespaceURI()),
+                && NamespaceURN.BASE.equals(incommingRpc.getNamespaceURI()),
                     "Missing %s element", XmlNetconfConstants.RPC_KEY);
 
             final Element rpcReply = errorDocument.getDocumentElement();
index e910409d93ebaa53b6ed9fffcf1e01d8bd8ce148..47884c9c8ffa9a23c6a49fea4b2bf98eacfcf8a7 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Map;
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.api.xml.XmlUtil;
@@ -73,7 +74,7 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
 
     protected static XmlElement getRequestElementWithCheck(final Document message) throws DocumentedException {
         return XmlElement.fromDomElementWithExpected(message.getDocumentElement(), XmlNetconfConstants.RPC_KEY,
-                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+            NamespaceURN.BASE);
     }
 
     protected HandlingPriority getHandlingPriority() {
@@ -81,7 +82,7 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
     }
 
     protected String getOperationNamespace() {
-        return XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0;
+        return NamespaceURN.BASE;
     }
 
     protected abstract String getOperationName();
@@ -99,13 +100,13 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
 
         Element response = handle(document, operationElement, subsequentOperation);
         Element rpcReply = XmlUtil.createElement(document, XmlNetconfConstants.RPC_REPLY_KEY,
-                Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
+                Optional.of(NamespaceURN.BASE));
 
         if (XmlElement.fromDomElement(response).hasNamespace()) {
             rpcReply.appendChild(response);
         } else {
             Element responseNS = XmlUtil.createElement(document, response.getNodeName(),
-                    Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
+                    Optional.of(NamespaceURN.BASE));
             NodeList list = response.getChildNodes();
             while (list.getLength() != 0) {
                 responseNS.appendChild(list.item(0));
index 55a278ce6393ba9aeb1c8a4261fd3e2423943a65..b1e6ba3e317f0e9bc21c01b5b4a9cde1d8334874 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netconf.server.mapping.operations;
 
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
@@ -54,8 +55,7 @@ public class DefaultStartExi extends AbstractSingletonNetconfOperation implement
     @Override
     protected Element handleWithNoSubsequentOperations(final Document document,
                                                        final XmlElement operationElement) {
-        final Element getSchemaResult = document.createElementNS(
-                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlNetconfConstants.OK);
+        final Element getSchemaResult = document.createElementNS(NamespaceURN.BASE, XmlNetconfConstants.OK);
         LOG.trace("{} operation successful", START_EXI);
         return getSchemaResult;
     }
@@ -67,7 +67,7 @@ public class DefaultStartExi extends AbstractSingletonNetconfOperation implement
 
     @Override
     protected String getOperationNamespace() {
-        return XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0;
+        return NamespaceURN.EXI;
     }
 
     @Override
index acccb52e4136f31b4f3f29e2512511b0a5654e73..ed23a75204608ed8db360ed9cd1d84c382b456b0 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netconf.server.mapping.operations;
 
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.api.xml.XmlUtil;
@@ -34,8 +35,7 @@ public class DefaultStopExi extends AbstractSingletonNetconfOperation implements
 
         netconfSession.stopExiCommunication();
 
-        Element getSchemaResult = document.createElementNS(
-                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlNetconfConstants.OK);
+        Element getSchemaResult = document.createElementNS(NamespaceURN.BASE, XmlNetconfConstants.OK);
         LOG.trace("{} operation successful", STOP_EXI);
         return getSchemaResult;
     }
@@ -47,7 +47,7 @@ public class DefaultStopExi extends AbstractSingletonNetconfOperation implements
 
     @Override
     protected String getOperationNamespace() {
-        return XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0;
+        return NamespaceURN.EXI;
     }
 
     @Override
index 3db13d873de8c1f910c6ee1712e6a45d3316d998..5466c3d45567adb7fa0d77cebb12aed97fd368c0 100644 (file)
@@ -12,6 +12,7 @@ import java.util.Objects;
 import java.util.Optional;
 import javax.xml.XMLConstants;
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.api.xml.XmlUtil;
@@ -36,14 +37,13 @@ public final class SubtreeFilter {
     public static Document applyRpcSubtreeFilter(final Document requestDocument,
                                                  final Document rpcReply) throws DocumentedException {
         OperationNameAndNamespace operationNameAndNamespace = new OperationNameAndNamespace(requestDocument);
-        if (XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0.equals(operationNameAndNamespace.getNamespace())
+        if (NamespaceURN.BASE.equals(operationNameAndNamespace.getNamespace())
                 && XmlNetconfConstants.GET.equals(operationNameAndNamespace.getOperationName())
                 || XmlNetconfConstants.GET_CONFIG.equals(operationNameAndNamespace.getOperationName())) {
             // process subtree filtering here, in case registered netconf operations do
             // not implement filtering.
             Optional<XmlElement> maybeFilter = operationNameAndNamespace.getOperationElement()
-                    .getOnlyChildElementOptionally(XmlNetconfConstants.FILTER,
-                            XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+                    .getOnlyChildElementOptionally(XmlNetconfConstants.FILTER, NamespaceURN.BASE);
             if (maybeFilter.isEmpty()) {
                 return rpcReply;
             }
@@ -77,16 +77,14 @@ public final class SubtreeFilter {
 
     private static void removeEventTimeNode(final Document document) {
         final Node eventTimeNode = document.getDocumentElement()
-            .getElementsByTagNameNS(
-                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_NOTIFICATION_1_0, XmlNetconfConstants.EVENT_TIME)
+            .getElementsByTagNameNS(NamespaceURN.NOTIFICATION, XmlNetconfConstants.EVENT_TIME)
             .item(0);
         document.getDocumentElement().removeChild(eventTimeNode);
     }
 
     private static boolean isSupported(final XmlElement filter) {
         return "subtree".equals(filter.getAttribute("type"))
-                || "subtree".equals(filter.getAttribute("type",
-                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
+                || "subtree".equals(filter.getAttribute("type", NamespaceURN.BASE));
     }
 
     private static Document extractNotificationContent(final Document notification) throws DocumentedException {
@@ -119,8 +117,7 @@ public final class SubtreeFilter {
         Element rpcReply = originalReplyDocument.getDocumentElement();
         Node rpcReplyDst = result.importNode(rpcReply, false);
         result.appendChild(rpcReplyDst);
-        XmlElement dataSrc = XmlElement.fromDomElement(rpcReply).getOnlyChildElement("data",
-                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+        XmlElement dataSrc = XmlElement.fromDomElement(rpcReply).getOnlyChildElement("data", NamespaceURN.BASE);
         Element dataDst = (Element) result.importNode(dataSrc.getDomElement(), false);
         rpcReplyDst.appendChild(dataDst);
         addSubtree(filter, dataSrc, XmlElement.fromDomElement(dataDst));