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=d56648cdf059c4620b14625d9206cd34467d0484;hb=41a04c117375a7d81b85b4a59198c3b7b633c12f;hp=2e7accad45e8950b7be2c3fb11a0a1ad1e74b93d;hpb=ee0877c07ff700157dd9fc2e445df095c88f79bc;p=controller.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 2e7accad45..d56648cdf0 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 @@ -31,14 +31,6 @@ public class SubtreeFilter { 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) { - LOG.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 } @@ -165,16 +167,23 @@ public class SubtreeFilter { } private static boolean prefixedContentMatches(final XmlElement filter, final XmlElement src) throws NetconfDocumentedException { - final Map.Entry prefixToNamespaceOfFilter = filter.findNamespaceOfTextContent(); - final Map.Entry prefixToNamespaceOfSrc = src.findNamespaceOfTextContent(); + final Map.Entry prefixToNamespaceOfFilter; + final Map.Entry prefixToNamespaceOfSrc; + try { + prefixToNamespaceOfFilter = filter.findNamespaceOfTextContent(); + prefixToNamespaceOfSrc = src.findNamespaceOfTextContent(); + } catch (IllegalArgumentException e) { + //if we can't find namespace of prefix - it's not a prefix, so it doesn't match + return false; + } final String prefix = prefixToNamespaceOfFilter.getKey(); // If this is not a prefixed content, we do not need to continue since content do not match - if(prefix.equals(XmlElement.DEFAULT_NAMESPACE_PREFIX)) { + if (prefix.equals(XmlElement.DEFAULT_NAMESPACE_PREFIX)) { return false; } // Namespace mismatch - if(!prefixToNamespaceOfFilter.getValue().equals(prefixToNamespaceOfSrc.getValue())) { + if (!prefixToNamespaceOfFilter.getValue().equals(prefixToNamespaceOfSrc.getValue())) { return false; }