From 894d3e240e70c339f15cf73eabcff646d58051cc Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 6 May 2023 12:44:17 +0200 Subject: [PATCH] Add netconf.api.NamespaceURN 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 --- .../AbstractNetconfSessionNegotiator.java | 5 +- .../handler/exi/NetconfStartExiMessage.java | 21 +++----- .../netconf/test/tool/monitoring/Get.java | 3 +- .../mdsal/NetconfDeviceCommunicatorTest.java | 5 +- .../operations/AbstractConfigOperation.java | 5 +- .../server/mdsal/operations/AbstractGet.java | 9 ++-- .../server/mdsal/operations/CopyConfig.java | 5 +- .../server/mdsal/operations/RuntimeRpc.java | 6 +-- .../netconf/api/DocumentedException.java | 23 ++++----- .../netconf/api/NamespaceURN.java | 51 +++++++++++++++++++ .../netconf/api/messages/HelloMessage.java | 17 +++---- .../api/messages/NotificationMessage.java | 6 +-- .../netconf/api/xml/XmlNetconfConstants.java | 5 -- .../api/NetconfDocumentedExceptionTest.java | 3 +- .../netconf/client/XMLNetconfUtil.java | 5 +- .../server/NetconfServerSessionListener.java | 7 +-- .../server/SendErrorExceptionUtil.java | 3 +- .../operations/AbstractNetconfOperation.java | 9 ++-- .../mapping/operations/DefaultStartExi.java | 6 +-- .../mapping/operations/DefaultStopExi.java | 6 +-- .../netconf/server/spi/SubtreeFilter.java | 15 +++--- 21 files changed, 122 insertions(+), 93 deletions(-) create mode 100644 protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/NamespaceURN.java diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java index 148d80ad5b..a644150e67 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java @@ -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 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)); } } } diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/monitoring/Get.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/monitoring/Get.java index d704008c80..a5e2a66914 100644 --- a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/monitoring/Get.java +++ b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/monitoring/Get.java @@ -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(); } diff --git a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceCommunicatorTest.java b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceCommunicatorTest.java index a8a4cb3642..1f283eaa00 100644 --- a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceCommunicatorTest.java +++ b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceCommunicatorTest.java @@ -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); diff --git a/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/AbstractConfigOperation.java b/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/AbstractConfigOperation.java index 634bfbe9e8..3d2ba73e3b 100644 --- a/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/AbstractConfigOperation.java +++ b/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/AbstractConfigOperation.java @@ -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); } /** diff --git a/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/AbstractGet.java b/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/AbstractGet.java index cac853f207..577f7700d7 100644 --- a/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/AbstractGet.java +++ b/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/AbstractGet.java @@ -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 parseSource(final XmlElement xml) throws DocumentedException { final Optional 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 getDatastore() { diff --git a/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/CopyConfig.java b/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/CopyConfig.java index fdab94dee4..c1aeaad34b 100644 --- a/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/CopyConfig.java +++ b/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/CopyConfig.java @@ -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); diff --git a/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/RuntimeRpc.java b/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/RuntimeRpc.java index 1e3efd4b59..e4dc200712 100644 --- a/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/RuntimeRpc.java +++ b/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/operations/RuntimeRpc.java @@ -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); diff --git a/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java b/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java index b8224def10..61eadb2b26 100644 --- a/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java +++ b/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java @@ -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 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 { * rpc */ - 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 index 0000000000..1cc01452c5 --- /dev/null +++ b/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/NamespaceURN.java @@ -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 + * IETF XML ns Registryrelevant to + * NETCONF. + */ +@NonNullByDefault +public final class NamespaceURN { + /** + * The NETCONF protocol XML namespace, as defined by RFC6241. + */ + public static final String BASE = "urn:ietf:params:xml:ns:netconf:base:1.0"; + /** + * The namespace used by the + * With-defaults Capability for NETCONF extension. + */ + public static final String DEFAULT = "urn:ietf:params:xml:ns:netconf:default:1.0"; + /** + * The namespace used by the + * + * Efficient XML Interchange Capability for NETCONF 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 NETCONF Event Notifications + * extension. + */ + public static final String NOTIFICATION = "urn:ietf:params:xml:ns:netconf:notification:1.0"; + /** + * The namespace used by the + * Partial Lock Remote Procedure Call (RPC) for NETCONF extension. + */ + public static final String PARTIAL_LOCK = "urn:ietf:params:xml:ns:netconf:partial-lock:1.0"; + + private NamespaceURN() { + // Hidden on purpose + } +} diff --git a/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/HelloMessage.java b/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/HelloMessage.java index 57c8e33af8..4409adaaa5 100644 --- a/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/HelloMessage.java +++ b/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/HelloMessage.java @@ -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 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 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); } } diff --git a/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NotificationMessage.java b/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NotificationMessage.java index f7b31d8442..66da0ffe79 100644 --- a/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NotificationMessage.java +++ b/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NotificationMessage.java @@ -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); diff --git a/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlNetconfConstants.java b/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlNetconfConstants.java index 726d191341..12558ffe0b 100644 --- a/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlNetconfConstants.java +++ b/protocol/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlNetconfConstants.java @@ -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 } diff --git a/protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/NetconfDocumentedExceptionTest.java b/protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/NetconfDocumentedExceptionTest.java index f4261f0a7f..91ad34e50f 100644 --- a/protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/NetconfDocumentedExceptionTest.java +++ b/protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/NetconfDocumentedExceptionTest.java @@ -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; } }); } diff --git a/protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/XMLNetconfUtil.java b/protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/XMLNetconfUtil.java index a819edf458..381ddfd4b0 100644 --- a/protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/XMLNetconfUtil.java +++ b/protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/XMLNetconfUtil.java @@ -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 diff --git a/protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/NetconfServerSessionListener.java b/protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/NetconfServerSessionListener.java index f03d8d3914..9e7cc53e51 100644 --- a/protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/NetconfServerSessionListener.java +++ b/protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/NetconfServerSessionListener.java @@ -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 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)); -- 2.36.6