X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fimpl%2FSubtreeFilter.java;h=566dfde7c3f3117f7c01af10655f4cf4c18bc453;hb=fe50edfa00458bdd302388ad976ce48955edb2e1;hp=42a8bae4484b93a3ed4689223cbf34a9aacbd986;hpb=0292e8408f56129c15adb38bfe9f11278203b8de;p=netconf.git diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/SubtreeFilter.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/SubtreeFilter.java index 42a8bae448..566dfde7c3 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/SubtreeFilter.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/SubtreeFilter.java @@ -28,17 +28,9 @@ import org.xml.sax.SAXException; * See rfc6241 for details. */ public class SubtreeFilter { - private static final Logger logger = LoggerFactory.getLogger(SubtreeFilter.class); + private static final Logger LOG = LoggerFactory.getLogger(SubtreeFilter.class); static Document applySubtreeFilter(Document requestDocument, Document rpcReply) throws NetconfDocumentedException { - // FIXME: rpcReply document must be reread otherwise some nodes do not inherit namespaces. (services/service) - try { - rpcReply = XmlUtil.readXmlToDocument(XmlUtil.toString(rpcReply, true)); - } catch (SAXException | IOException e) { - logger.error("Cannot transform document", e); - throw new NetconfDocumentedException("Cannot transform document"); - } - OperationNameAndNamespace operationNameAndNamespace = new OperationNameAndNamespace(requestDocument); if (XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0.equals(operationNameAndNamespace.getNamespace()) && XmlNetconfConstants.GET.equals(operationNameAndNamespace.getOperationName()) || @@ -47,16 +39,26 @@ public class SubtreeFilter { // not implement filtering. Optional maybeFilter = operationNameAndNamespace.getOperationElement().getOnlyChildElementOptionally( XmlNetconfConstants.FILTER, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); - if (maybeFilter.isPresent() && ( - "subtree".equals(maybeFilter.get().getAttribute("type"))|| - "subtree".equals(maybeFilter.get().getAttribute("type", XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0)) - )) { + if (!maybeFilter.isPresent()) { + return rpcReply; + } + // FIXME: rpcReply document must be reread otherwise some nodes do not inherit namespaces. (services/service) + try { + rpcReply = XmlUtil.readXmlToDocument(XmlUtil.toString(rpcReply, true)); + } catch (SAXException | IOException e) { + LOG.error("Cannot transform document", e); + throw new NetconfDocumentedException("Cannot transform document" + e); + } + XmlElement filter = maybeFilter.get(); + if ("subtree".equals(filter.getAttribute("type"))|| + "subtree".equals(filter.getAttribute("type", XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0))) { // do return filtered(maybeFilter.get(), rpcReply); } } + return rpcReply; // return identical document } @@ -160,7 +162,7 @@ public class SubtreeFilter { if (result == null) { result = MatchingResult.NO_MATCH; } - logger.debug("Matching {} to {} resulted in {}", src, filter, result); + LOG.debug("Matching {} to {} resulted in {}", src, filter, result); return result; } @@ -178,10 +180,10 @@ public class SubtreeFilter { return false; } - final String unprefixedFilterContent = filter.getTextContent().substring(prefix.length()); - final String unprefixedSrcCOntnet = src.getTextContent().substring(prefix.length()); + final String unprefixedFilterContent = filter.getTextContent().substring(prefixToNamespaceOfFilter.getKey().length() + 1); + final String unprefixedSrcContnet = src.getTextContent().substring(prefixToNamespaceOfSrc.getKey().length() + 1); // Finally compare unprefixed content - return unprefixedFilterContent.equals(unprefixedSrcCOntnet); + return unprefixedFilterContent.equals(unprefixedSrcContnet); } enum MatchingResult {