Use UntrustedXML for interfacing with Documents 81/53181/4
authorRobert Varga <rovarga@cisco.com>
Sat, 11 Mar 2017 18:09:14 +0000 (19:09 +0100)
committerRobert Varga <rovarga@cisco.com>
Sat, 11 Mar 2017 22:22:07 +0000 (23:22 +0100)
Eliminate duplicated factory setup call sites in favor of using
centralized UntrustedXML.

Change-Id: If302e8551df80d3f5967fcd912be3737fac70616
Signed-off-by: Robert Varga <rovarga@cisco.com>
14 files changed:
netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java
netconf/netconf-notifications-api/src/test/java/org/opendaylight/netconf/notifications/NetconfNotificationTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfToNotificationTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfDeviceCommunicatorTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/NetconfRemoteSchemaYangSourceProviderTest.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlNormalizedNodeBodyReader.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlToPATCHBodyReader.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/AbstractNotificationsData.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/ListenersConstants.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/XmlNormalizedNodeBodyReader.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/XmlToPATCHBodyReader.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/md/sal/rest/common/TestRestconfUtils.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java

index c9afd6ead907f68ef92b4abfae01904c539e1158..cf340c60fe987764e67f2817d716cf661b40f469 100644 (file)
@@ -12,9 +12,6 @@ import com.google.common.base.Preconditions;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.dom.DOMSource;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener;
@@ -22,6 +19,7 @@ import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.even
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceStatus;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceStatusNotification;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceStatusNotificationBuilder;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
@@ -49,7 +47,8 @@ class ConnectionNotificationTopicRegistration extends NotificationTopicRegistrat
 
     private final DOMNotificationListener domNotificationListener;
 
-    public ConnectionNotificationTopicRegistration(String SourceName, DOMNotificationListener domNotificationListener) {
+    public ConnectionNotificationTopicRegistration(final String SourceName,
+            final DOMNotificationListener domNotificationListener) {
         super(NotificationSourceType.ConnectionStatusChange, SourceName,
             EVENT_SOURCE_STATUS_PATH.getLastComponent().getNamespace().toString());
         this.domNotificationListener = Preconditions.checkNotNull(domNotificationListener);
@@ -58,7 +57,8 @@ class ConnectionNotificationTopicRegistration extends NotificationTopicRegistrat
         setReplaySupported(false);
     }
 
-    @Override public void close() throws Exception {
+    @Override
+    public void close() {
         if (isActive()) {
             LOG.debug("Connection notification - publish Deactive");
             publishNotification(EventSourceStatus.Deactive);
@@ -67,22 +67,26 @@ class ConnectionNotificationTopicRegistration extends NotificationTopicRegistrat
         }
     }
 
-    @Override void activateNotificationSource() {
+    @Override
+    void activateNotificationSource() {
         LOG.debug("Connection notification - publish Active");
         publishNotification(EventSourceStatus.Active);
     }
 
-    @Override void deActivateNotificationSource() {
+    @Override
+    void deActivateNotificationSource() {
         LOG.debug("Connection notification - publish Inactive");
         publishNotification(EventSourceStatus.Inactive);
     }
 
-    @Override void reActivateNotificationSource() {
+    @Override
+    void reActivateNotificationSource() {
         LOG.debug("Connection notification - reactivate - publish active");
         publishNotification(EventSourceStatus.Active);
     }
 
-    @Override boolean registerNotificationTopic(SchemaPath notificationPath, TopicId topicId) {
+    @Override
+    boolean registerNotificationTopic(final SchemaPath notificationPath, final TopicId topicId) {
         if (!checkNotificationPath(notificationPath)) {
             LOG.debug("Bad SchemaPath for notification try to register");
             return false;
@@ -93,7 +97,8 @@ class ConnectionNotificationTopicRegistration extends NotificationTopicRegistrat
         return true;
     }
 
-    @Override synchronized void unRegisterNotificationTopic(TopicId topicId) {
+    @Override
+    synchronized void unRegisterNotificationTopic(final TopicId topicId) {
         List<SchemaPath> notificationPathToRemove = new ArrayList<>();
         for (SchemaPath notifKey : notificationTopicMap.keySet()) {
             Set<TopicId> topicList = notificationTopicMap.get(notifKey);
@@ -109,14 +114,14 @@ class ConnectionNotificationTopicRegistration extends NotificationTopicRegistrat
         }
     }
 
-    private void publishNotification(EventSourceStatus eventSourceStatus) {
+    private void publishNotification(final EventSourceStatus eventSourceStatus) {
 
         final EventSourceStatusNotification notification = new EventSourceStatusNotificationBuilder()
             .setStatus(eventSourceStatus).build();
         domNotificationListener.onNotification(createNotification(notification));
     }
 
-    private DOMNotification createNotification(EventSourceStatusNotification notification) {
+    private static DOMNotification createNotification(final EventSourceStatusNotification notification) {
         final ContainerNode cn = Builders.containerBuilder().withNodeIdentifier(EVENT_SOURCE_STATUS_ARG)
             .withChild(encapsulate(notification)).build();
         DOMNotification dn = new DOMNotification() {
@@ -132,18 +137,8 @@ class ConnectionNotificationTopicRegistration extends NotificationTopicRegistrat
         return dn;
     }
 
-    private AnyXmlNode encapsulate(EventSourceStatusNotification notification) {
-
-        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
-        DocumentBuilder docBuilder;
-
-        try {
-            docBuilder = docFactory.newDocumentBuilder();
-        } catch (ParserConfigurationException e) {
-            throw new IllegalStateException("Can not create XML DocumentBuilder");
-        }
-
-        Document doc = docBuilder.newDocument();
+    private static AnyXmlNode encapsulate(final EventSourceStatusNotification notification) {
+        Document doc = UntrustedXML.newDocumentBuilder().newDocument();
 
         final Optional<String> namespace = Optional.of(EVENT_SOURCE_STATUS_ARG.getNodeType().getNamespace().toString());
         final Element rootElement = createElement(doc, "EventSourceStatusNotification", namespace);
@@ -154,11 +149,11 @@ class ConnectionNotificationTopicRegistration extends NotificationTopicRegistrat
 
         return Builders.anyXmlBuilder().withNodeIdentifier(EVENT_SOURCE_STATUS_ARG)
             .withValue(new DOMSource(rootElement)).build();
-
     }
 
     // Helper to create root XML element with correct namespace and attribute
-    private Element createElement(final Document document, final String qName, final Optional<String> namespaceURI) {
+    private static Element createElement(final Document document, final String qName,
+            final Optional<String> namespaceURI) {
         if (namespaceURI.isPresent()) {
             final Element element = document.createElementNS(namespaceURI.get(), qName);
             String name = XMLNS_ATTRIBUTE_KEY;
index bc2f0a10876930342c819cea0c3308f607a26c26..ae89c372188a1de1d5a6ce0ef81a6c8fc8ef8abd 100644 (file)
@@ -12,9 +12,8 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 import java.util.Date;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import org.junit.Test;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
@@ -23,10 +22,7 @@ public class NetconfNotificationTest {
 
     @Test
     public void testWrapNotification() throws Exception {
-        final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
-        final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
-
-        final Document document = docBuilder.newDocument();
+        final Document document = UntrustedXML.newDocumentBuilder().newDocument();
 
         final Element rootElement = document.createElement("test-root");
         document.appendChild(rootElement);
index da1497b101adcec6112ad956e59243782d5f3ecb..f2c85eade3e25c522239f53d26f2a90cb1c3250e 100644 (file)
@@ -17,7 +17,6 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
-import javax.xml.parsers.DocumentBuilderFactory;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.config.util.xml.XmlUtil;
@@ -38,11 +37,8 @@ public class NetconfToNotificationTest {
 
     NetconfMessage userNotification;
 
-    @SuppressWarnings("deprecation")
     @Before
     public void setup() throws Exception {
-        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        factory.setNamespaceAware(true);
         InputStream notifyPayloadStream = getClass().getResourceAsStream("/notification-payload.xml");
         assertNotNull(notifyPayloadStream);
 
@@ -51,7 +47,7 @@ public class NetconfToNotificationTest {
         userNotification = new NetconfMessage(doc);
     }
 
-    static SchemaContext getNotificationSchemaContext(Class<?> loadClass, boolean getExceptionTest) throws Exception {
+    static SchemaContext getNotificationSchemaContext(final Class<?> loadClass, final boolean getExceptionTest) throws Exception {
         final List<InputStream> modelsToParse = new ArrayList<>();
 
         if (getExceptionTest) {
index 688194427948a05c66289b44b738a39fd6846690..d97320fbc4429cb5278524c636ccb2080753423a 100644 (file)
@@ -44,7 +44,6 @@ import java.util.Collections;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import org.junit.Before;
 import org.junit.Test;
@@ -64,8 +63,8 @@ import org.opendaylight.netconf.sal.connect.api.RemoteDevice;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.protocol.framework.ReconnectStrategy;
-import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
 import org.opendaylight.protocol.framework.TimedReconnectStrategy;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -102,7 +101,7 @@ public class NetconfDeviceCommunicatorTest {
 
     @SuppressWarnings("unchecked")
     private ListenableFuture<RpcResult<NetconfMessage>> sendRequest( final String messageID, final boolean doLastTest ) throws Exception {
-        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+        Document doc = UntrustedXML.newDocumentBuilder().newDocument();
         Element element = doc.createElement( "request" );
         element.setAttribute( "message-id", messageID );
         doc.appendChild( element );
@@ -204,8 +203,7 @@ public class NetconfDeviceCommunicatorTest {
     public void testSendRequest() throws Exception {
         setupSession();
 
-        NetconfMessage message = new NetconfMessage(
-                              DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument() );
+        NetconfMessage message = new NetconfMessage(UntrustedXML.newDocumentBuilder().newDocument());
         QName rpc = QName.create( "mock rpc" );
 
         ArgumentCaptor<GenericFutureListener> futureListener =
@@ -235,8 +233,7 @@ public class NetconfDeviceCommunicatorTest {
 
     @Test
     public void testSendRequestWithNoSession() throws Exception {
-        NetconfMessage message = new NetconfMessage(
-                              DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument() );
+        NetconfMessage message = new NetconfMessage(UntrustedXML.newDocumentBuilder().newDocument());
         QName rpc = QName.create( "mock rpc" );
 
         ListenableFuture<RpcResult<NetconfMessage>> resultFuture = communicator.sendRequest( message, rpc );
@@ -254,8 +251,7 @@ public class NetconfDeviceCommunicatorTest {
     public void testSendRequestWithWithSendFailure() throws Exception {
         setupSession();
 
-        NetconfMessage message = new NetconfMessage(
-                              DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument() );
+        NetconfMessage message = new NetconfMessage(UntrustedXML.newDocumentBuilder().newDocument());
         QName rpc = QName.create( "mock rpc" );
 
         ArgumentCaptor<GenericFutureListener> futureListener =
@@ -286,7 +282,7 @@ public class NetconfDeviceCommunicatorTest {
     }
 
     private static NetconfMessage createSuccessResponseMessage( final String messageID ) throws ParserConfigurationException {
-        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+        Document doc = UntrustedXML.newDocumentBuilder().newDocument();
         Element rpcReply = doc.createElementNS( URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlMappingConstants.RPC_REPLY_KEY);
         rpcReply.setAttribute( "message-id", messageID );
         Element element = doc.createElementNS( "ns", "data" );
@@ -388,12 +384,7 @@ public class NetconfDeviceCommunicatorTest {
             final NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create()
                     .withAddress(new InetSocketAddress("localhost", 65000))
                     .withReconnectStrategy(reconnectStrategy)
-                    .withConnectStrategyFactory(new ReconnectStrategyFactory() {
-                        @Override
-                        public ReconnectStrategy createReconnectStrategy() {
-                            return reconnectStrategy;
-                        }
-                    })
+                    .withConnectStrategyFactory(() -> reconnectStrategy)
                     .withAuthHandler(new LoginPassword("admin", "admin"))
                     .withConnectionTimeoutMillis(10000)
                     .withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH)
@@ -469,7 +460,7 @@ public class NetconfDeviceCommunicatorTest {
             "</rpc-reply>";
 
         ByteArrayInputStream bis = new ByteArrayInputStream( xmlStr.getBytes() );
-        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( bis );
+        Document doc = UntrustedXML.newDocumentBuilder().parse(bis);
         return new NetconfMessage( doc );
     }
 
index 6d65959a7d26d14bb670c7e43697634432be17bc..2b49b10b8f760c60bed8bfdb25ae54d54453502b 100644 (file)
@@ -16,7 +16,6 @@ import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import java.net.InetSocketAddress;
 import java.util.Collections;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.dom.DOMSource;
 import org.junit.Assert;
@@ -30,6 +29,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -81,7 +81,7 @@ public class NetconfRemoteSchemaYangSourceProviderTest {
         final YangInstanceIdentifier.NodeIdentifier childId = YangInstanceIdentifier.NodeIdentifier.create(
                 QName.create("urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring", "2010-10-04", "data")
         );
-        Document xmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+        Document xmlDoc = UntrustedXML.newDocumentBuilder().newDocument();
         Element root = xmlDoc.createElement("data");
         root.setTextContent("module test {}");
         final DOMSource v = new DOMSource(root);
index 8359ee0b1de4a3b4a08f8e8cbcef6f72ecc8b896..bc1eeeae508756bceea4c0637ea9f96fbe637f2f 100644 (file)
@@ -24,9 +24,6 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.Provider;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import org.opendaylight.netconf.sal.rest.api.Draft02;
 import org.opendaylight.netconf.sal.rest.api.RestconfService;
 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
@@ -35,6 +32,7 @@ import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
 import org.opendaylight.restconf.utils.RestconfConstants;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlUtils;
@@ -62,25 +60,6 @@ import org.xml.sax.SAXException;
 public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader<NormalizedNodeContext> {
 
     private final static Logger LOG = LoggerFactory.getLogger(XmlNormalizedNodeBodyReader.class);
-    private static final DocumentBuilderFactory BUILDERFACTORY;
-
-    static {
-        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        try {
-            factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
-            factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
-            factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
-            factory.setXIncludeAware(false);
-            factory.setExpandEntityReferences(false);
-        } catch (final ParserConfigurationException e) {
-            throw new ExceptionInInitializerError(e);
-        }
-        factory.setNamespaceAware(true);
-        factory.setCoalescing(true);
-        factory.setIgnoringElementContentWhitespace(true);
-        factory.setIgnoringComments(true);
-        BUILDERFACTORY = factory;
-    }
 
     @Override
     public boolean isReadable(final Class<?> type, final Type genericType, final Annotation[] annotations,
@@ -120,15 +99,8 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
             return new NormalizedNodeContext(path, null);
         }
 
-        final DocumentBuilder dBuilder;
-        try {
-            dBuilder = BUILDERFACTORY.newDocumentBuilder();
-        } catch (final ParserConfigurationException e) {
-            throw new RuntimeException("Failed to parse XML document", e);
-        }
-        final Document doc = dBuilder.parse(entityStream);
-
-        return parse(path,doc);
+        final Document doc = UntrustedXML.newDocumentBuilder().parse(entityStream);
+        return parse(path, doc);
     }
 
     private NormalizedNodeContext parse(final InstanceIdentifierContext<?> pathContext,final Document doc) {
index d203de59edda5f23f88742c4d82e32a6a58e295f..8ad5d0ddc46da8e0bf1088fff167ca2d04ad51d1 100644 (file)
@@ -25,9 +25,6 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.Provider;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import org.opendaylight.netconf.sal.rest.api.Draft02;
 import org.opendaylight.netconf.sal.rest.api.RestconfService;
 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
@@ -37,6 +34,7 @@ import org.opendaylight.netconf.sal.restconf.impl.PATCHEntity;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@@ -68,25 +66,6 @@ public class XmlToPATCHBodyReader extends AbstractIdentifierAwareJaxRsProvider i
         MessageBodyReader<PATCHContext> {
 
     private final static Logger LOG = LoggerFactory.getLogger(XmlToPATCHBodyReader.class);
-    private static final DocumentBuilderFactory BUILDERFACTORY;
-
-    static {
-        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        try {
-            factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
-            factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
-            factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
-            factory.setXIncludeAware(false);
-            factory.setExpandEntityReferences(false);
-        } catch (final ParserConfigurationException e) {
-            throw new ExceptionInInitializerError(e);
-        }
-        factory.setNamespaceAware(true);
-        factory.setCoalescing(true);
-        factory.setIgnoringElementContentWhitespace(true);
-        factory.setIgnoringComments(true);
-        BUILDERFACTORY = factory;
-    }
 
     @Override
     public boolean isReadable(final Class<?> type, final Type genericType,
@@ -108,14 +87,7 @@ public class XmlToPATCHBodyReader extends AbstractIdentifierAwareJaxRsProvider i
                 return new PATCHContext(path, null, null);
             }
 
-            final DocumentBuilder dBuilder;
-            try {
-                dBuilder = BUILDERFACTORY.newDocumentBuilder();
-            } catch (final ParserConfigurationException e) {
-                throw new IllegalStateException("Failed to parse XML document", e);
-            }
-            final Document doc = dBuilder.parse(entityStream);
-
+            final Document doc = UntrustedXML.newDocumentBuilder().parse(entityStream);
             return parse(path, doc);
         } catch (final RestconfDocumentedException e) {
             throw e;
index ad90eeedfa234227e896c4eff828e5d51b9cc83e..f9cefcd0de789d4a8d65486185ac9c11e17c71c2 100644 (file)
@@ -13,8 +13,6 @@ import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.StandardCharsets;
 import java.util.Date;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
@@ -30,6 +28,7 @@ import org.opendaylight.restconf.Rfc8040.MonitoringModule;
 import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.parser.IdentifierCodec;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
@@ -108,13 +107,7 @@ abstract class AbstractNotificationsData {
      * @return {@link Document} document.
      */
     protected static Document createDocument() {
-        final DocumentBuilder bob;
-        try {
-            bob = ListenersConstants.DBF.newDocumentBuilder();
-        } catch (final ParserConfigurationException e) {
-            return null;
-        }
-        return bob.newDocument();
+        return UntrustedXML.newDocumentBuilder().newDocument();
     }
 
     /**
index a92c3a27e0e6ff1e16fa795f7cabd46cf4faaad0..9d44d0e7aad002be197bec4299a40e4179154bcd 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.netconf.sal.streams.listeners;
 
 import java.text.SimpleDateFormat;
 import java.util.regex.Pattern;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.TransformerFactory;
 
 /**
@@ -17,7 +16,6 @@ import javax.xml.transform.TransformerFactory;
  */
 class ListenersConstants {
 
-    static final DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance();
     static final TransformerFactory FACTORY = TransformerFactory.newInstance();
     static final Pattern RFC3339_PATTERN = Pattern.compile("(\\d\\d)(\\d\\d)$");
 
index 71359dd7790ebcc9ee5f70c4982c8b74cc609dd4..507f4f362ace875a89e7dfd72814e6481661d72a 100644 (file)
@@ -26,9 +26,6 @@ import javax.ws.rs.core.Request;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.Provider;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
@@ -36,6 +33,7 @@ import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
 import org.opendaylight.restconf.Rfc8040;
 import org.opendaylight.restconf.utils.RestconfConstants;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlUtils;
@@ -61,25 +59,6 @@ import org.w3c.dom.Element;
 public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader<NormalizedNodeContext> {
 
     private final static Logger LOG = LoggerFactory.getLogger(XmlNormalizedNodeBodyReader.class);
-    private static final DocumentBuilderFactory BUILDERFACTORY;
-
-    static {
-        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        try {
-            factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
-            factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
-            factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
-            factory.setXIncludeAware(false);
-            factory.setExpandEntityReferences(false);
-        } catch (final ParserConfigurationException e) {
-            throw new ExceptionInInitializerError(e);
-        }
-        factory.setNamespaceAware(true);
-        factory.setCoalescing(true);
-        factory.setIgnoringElementContentWhitespace(true);
-        factory.setIgnoringComments(true);
-        BUILDERFACTORY = factory;
-    }
 
     @Override
     public boolean isReadable(final Class<?> type, final Type genericType, final Annotation[] annotations,
@@ -100,14 +79,7 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
                 return new NormalizedNodeContext(path, null);
             }
 
-            final DocumentBuilder dBuilder;
-            try {
-                dBuilder = BUILDERFACTORY.newDocumentBuilder();
-            } catch (final ParserConfigurationException e) {
-                throw new RuntimeException("Failed to parse XML document", e);
-            }
-            final Document doc = dBuilder.parse(entityStream);
-
+            final Document doc = UntrustedXML.newDocumentBuilder().parse(entityStream);
             return parse(path,doc);
         } catch (final RestconfDocumentedException e){
             throw e;
@@ -141,7 +113,8 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
 
 
         final DomToNormalizedNodeParserFactory parserFactory =
-                DomToNormalizedNodeParserFactory.getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER, pathContext.getSchemaContext());
+                DomToNormalizedNodeParserFactory.getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER,
+                    pathContext.getSchemaContext());
 
         if (isPost() && !isRpc) {
             final Deque<Object> foundSchemaNodes = findPathToSchemaNodeByName(schemaNode, docRootElm, docRootNamespace);
@@ -164,7 +137,8 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
         NormalizedNode<?, ?> parsed = null;
 
         if (schemaNode instanceof ContainerSchemaNode) {
-            parsed = parserFactory.getContainerNodeParser().parse(Collections.singletonList(doc.getDocumentElement()), (ContainerSchemaNode) schemaNode);
+            parsed = parserFactory.getContainerNodeParser().parse(Collections.singletonList(doc.getDocumentElement()),
+                (ContainerSchemaNode) schemaNode);
         } else if(schemaNode instanceof ListSchemaNode) {
             final ListSchemaNode casted = (ListSchemaNode) schemaNode;
             parsed = parserFactory.getMapEntryNodeParser().parse(elements, casted);
@@ -176,7 +150,8 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
         final YangInstanceIdentifier fullIIToData = YangInstanceIdentifier.create(Iterables.concat(
                 pathContext.getInstanceIdentifier().getPathArguments(), iiToDataList));
 
-        outIIContext = new InstanceIdentifierContext<>(fullIIToData, pathContext.getSchemaNode(), pathContext.getMountPoint(),
+        outIIContext = new InstanceIdentifierContext<>(fullIIToData, pathContext.getSchemaNode(),
+                pathContext.getMountPoint(),
                 pathContext.getSchemaContext());
 
         return new NormalizedNodeContext(outIIContext, parsed);
index b4e0523b0af59e54a917e818f41bb15e515242b7..a9ded6bb1ad1e4ba3af0040d424b4917c9c2d662 100644 (file)
@@ -25,9 +25,6 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.Provider;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
 import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
 import org.opendaylight.netconf.sal.restconf.impl.PATCHEditOperation;
@@ -37,6 +34,7 @@ import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
 import org.opendaylight.restconf.Rfc8040;
 import org.opendaylight.restconf.utils.RestconfConstants;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@@ -63,26 +61,6 @@ public class XmlToPATCHBodyReader extends AbstractIdentifierAwareJaxRsProvider i
         MessageBodyReader<PATCHContext> {
 
     private final static Logger LOG = LoggerFactory.getLogger(XmlToPATCHBodyReader.class);
-    private static final DocumentBuilderFactory BUILDERFACTORY;
-
-    static {
-        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        try {
-            factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
-            factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
-            factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
-            factory.setXIncludeAware(false);
-            factory.setExpandEntityReferences(false);
-        } catch (final ParserConfigurationException e) {
-            throw new ExceptionInInitializerError(e);
-        }
-        factory.setNamespaceAware(true);
-        factory.setCoalescing(true);
-        factory.setIgnoringElementContentWhitespace(true);
-        factory.setIgnoringComments(true);
-        BUILDERFACTORY = factory;
-    }
-
     @Override
     public boolean isReadable(final Class<?> type, final Type genericType,
                               final Annotation[] annotations, final MediaType mediaType) {
@@ -103,14 +81,7 @@ public class XmlToPATCHBodyReader extends AbstractIdentifierAwareJaxRsProvider i
                 return new PATCHContext(path, null, null);
             }
 
-            final DocumentBuilder dBuilder;
-            try {
-                dBuilder = BUILDERFACTORY.newDocumentBuilder();
-            } catch (final ParserConfigurationException e) {
-                throw new IllegalStateException("Failed to parse XML document", e);
-            }
-            final Document doc = dBuilder.parse(entityStream);
-
+            final Document doc = UntrustedXML.newDocumentBuilder().parse(entityStream);
             return parse(path, doc);
         } catch (final RestconfDocumentedException e) {
             throw e;
@@ -245,7 +216,7 @@ public class XmlToPATCHBodyReader extends AbstractIdentifierAwareJaxRsProvider i
      */
     private String prepareNonCondXpath(@Nonnull final DataSchemaNode schemaNode, @Nonnull final String target,
                                        @Nonnull final Element value, @Nonnull final String namespace,
-                                       @Nonnull String revision) {
+                                       @Nonnull final String revision) {
         final Iterator<String> args = Splitter.on("/").split(target.substring(target.indexOf(':') + 1)).iterator();
 
         final StringBuilder nonCondXpath = new StringBuilder();
index 1ba0f3f89395a98e216f79b9563608a49a8235d8..82a772c80a6e70d95a4c66815ee967a7afedf563 100644 (file)
@@ -16,13 +16,11 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import org.opendaylight.controller.sal.rest.impl.test.providers.TestJsonBodyWriter;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlUtils;
 import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser.DomToNormalizedNodeParserFactory;
@@ -52,26 +50,6 @@ public class TestRestconfUtils {
 
     private static final Logger LOG = LoggerFactory.getLogger(TestRestconfUtils.class);
 
-    private static final DocumentBuilderFactory BUILDERFACTORY;
-
-    static {
-        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        try {
-            factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
-            factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
-            factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
-            factory.setXIncludeAware(false);
-            factory.setExpandEntityReferences(false);
-        } catch (final ParserConfigurationException e) {
-            throw new ExceptionInInitializerError(e);
-        }
-        factory.setNamespaceAware(true);
-        factory.setCoalescing(true);
-        factory.setIgnoringElementContentWhitespace(true);
-        factory.setIgnoringComments(true);
-        BUILDERFACTORY = factory;
-    }
-
     private TestRestconfUtils() {
         throw new UnsupportedOperationException("Test utility class");
     }
@@ -100,8 +78,7 @@ public class TestRestconfUtils {
         final InstanceIdentifierContext<?> iiContext = ControllerContext.getInstance().toInstanceIdentifier(uri);
         final InputStream inputStream = TestJsonBodyWriter.class.getResourceAsStream(pathToInputFile);
         try {
-            final DocumentBuilder dBuilder = BUILDERFACTORY.newDocumentBuilder();
-            final Document doc = dBuilder.parse(inputStream);
+            final Document doc = UntrustedXML.newDocumentBuilder().parse(inputStream);
             final NormalizedNode<?, ?> nn = parse(iiContext, doc);
             return new NormalizedNodeContext(iiContext, nn);
         } catch (final Exception e) {
@@ -158,12 +135,11 @@ public class TestRestconfUtils {
         final String path = TestRestconfUtils.class.getResource(resourceDirectory).getPath();
         final File testDir = new File(path);
         final String[] fileList = testDir.list();
-        final List<File> testFiles = new ArrayList<File>();
+        final List<File> testFiles = new ArrayList<>();
         if (fileList == null) {
             throw new FileNotFoundException(resourceDirectory);
         }
-        for (int i = 0; i < fileList.length; i++) {
-            final String fileName = fileList[i];
+        for (final String fileName : fileList) {
             if (new File(testDir, fileName).isDirectory() == false) {
                 testFiles.add(new File(testDir, fileName));
             }
index 9281c9d20b8f24786b81a8ced9bad25c99a450f9..a443ad6e3792a7e975827e09922dfb61fd5016af 100644 (file)
@@ -43,7 +43,6 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.UriInfo;
 import javax.xml.namespace.NamespaceContext;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpression;
@@ -67,9 +66,13 @@ import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
 
 /**
  * Unit tests for RestconfDocumentedExceptionMapper.
@@ -108,6 +111,7 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         }
     }
 
+    private static final Logger LOG = LoggerFactory.getLogger(RestconfDocumentedExceptionMapperTest.class);
     static RestconfService mockRestConf = mock(RestconfService.class);
 
     static XPath XPATH = XPathFactory.newInstance().newXPath();
@@ -767,25 +771,13 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
                 errorInfoVerifier);
     }
 
-    private Document parseXMLDocument(final InputStream stream) throws IOException {
-        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        factory.setNamespaceAware(true);
-        factory.setCoalescing(true);
-        factory.setIgnoringElementContentWhitespace(true);
-        factory.setIgnoringComments(true);
-
+    private static Document parseXMLDocument(final InputStream stream) throws IOException, SAXException {
         final ByteArrayOutputStream bos = new ByteArrayOutputStream();
         ByteStreams.copy(stream, bos);
 
-        System.out.println("XML: " + bos.toString());
+        LOG.debug("XML: " + bos.toString());
 
-        Document doc = null;
-        try {
-            doc = factory.newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray()));
-        } catch (final Exception e) {
-            throw new IllegalArgumentException("Invalid XML response:\n" + bos.toString(), e);
-        }
-        return doc;
+        return UntrustedXML.newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray()));
     }
 
     void verifyXMLErrorNode(final Node errorNode, final ErrorType expErrorType, final ErrorTag expErrorTag,
index e25f2531906e0c9748a4f273719e88dac5ded17f..bf9da153fdafd91607bdaf6aab32e7a59725416c 100644 (file)
@@ -30,17 +30,16 @@ import java.util.Map;
 import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
@@ -64,8 +63,7 @@ public final class TestUtils {
     public static SchemaContext loadSchemaContext(final String... yangPath)
             throws FileNotFoundException, ReactorException {
         final List<InputStream> files = new ArrayList<>();
-        for (int i = 0; i < yangPath.length; i++) {
-            final String path = yangPath[i];
+        for (final String path : yangPath) {
             final String pathToFile = TestUtils.class.getResource(path).getPath();
             final File testDir = new File(pathToFile);
             final String[] fileList = testDir.list();
@@ -73,8 +71,7 @@ public final class TestUtils {
                 throw new FileNotFoundException(pathToFile);
             }
 
-            for (int j = 0; j < fileList.length; j++) {
-                final String fileName = fileList[j];
+            for (final String fileName : fileList) {
                 final File file = new File(testDir, fileName);
                 if (file.isDirectory() == false) {
                     files.add(new NamedFileInputStream(file, file.getPath()));
@@ -95,10 +92,8 @@ public final class TestUtils {
 
     public static Document loadDocumentFrom(final InputStream inputStream) {
         try {
-            final DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
-            final DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
-            return docBuilder.parse(inputStream);
-        } catch (SAXException | IOException | ParserConfigurationException e) {
+            return UntrustedXML.newDocumentBuilder().parse(inputStream);
+        } catch (SAXException | IOException e) {
             LOG.error("Error during loading Document from XML", e);
             return null;
         }
@@ -213,28 +208,25 @@ public final class TestUtils {
         return matcher.matches();
     }
 
-    public static YangInstanceIdentifier.NodeIdentifier getNodeIdentifier(final String localName, final String namespace,
+    public static NodeIdentifier getNodeIdentifier(final String localName, final String namespace,
             final String revision) throws ParseException {
-        return new YangInstanceIdentifier.NodeIdentifier(QName.create(namespace, revision, localName));
+        return new NodeIdentifier(QName.create(namespace, revision, localName));
     }
 
-    public static YangInstanceIdentifier.NodeIdentifierWithPredicates getNodeIdentifierPredicate(final String localName,
+    public static NodeIdentifierWithPredicates getNodeIdentifierPredicate(final String localName,
             final String namespace, final String revision, final Map<String, Object> keys) throws ParseException {
         final Map<QName, Object> predicate = new HashMap<>();
         for (final String key : keys.keySet()) {
             predicate.put(QName.create(namespace, revision, key), keys.get(key));
         }
 
-        return new YangInstanceIdentifier.NodeIdentifierWithPredicates(
-
-        QName.create(namespace, revision, localName), predicate);
+        return new NodeIdentifierWithPredicates(QName.create(namespace, revision, localName), predicate);
     }
 
-    public static YangInstanceIdentifier.NodeIdentifierWithPredicates getNodeIdentifierPredicate(final String localName,
+    public static NodeIdentifierWithPredicates getNodeIdentifierPredicate(final String localName,
             final String namespace, final String revision, final String... keysAndValues) throws ParseException {
-        if ((keysAndValues.length % 2) != 0) {
-            new IllegalArgumentException("number of keys argument have to be divisible by 2 (map)");
-        }
+        Preconditions.checkArgument((keysAndValues.length % 2) == 0,
+                "number of keys argument have to be divisible by 2 (map)");
         final Map<QName, Object> predicate = new HashMap<>();
 
         int i = 0;
@@ -242,14 +234,14 @@ public final class TestUtils {
             predicate.put(QName.create(namespace, revision, keysAndValues[i++]), keysAndValues[i++]);
         }
 
-        return new YangInstanceIdentifier.NodeIdentifierWithPredicates(QName.create(namespace, revision, localName),
-                predicate);
+        return new NodeIdentifierWithPredicates(QName.create(namespace, revision, localName), predicate);
     }
 
     static NormalizedNode<?,?> prepareNormalizedNodeWithIetfInterfacesInterfacesData() throws ParseException {
         final String ietfInterfacesDate = "2013-07-04";
         final String namespace = "urn:ietf:params:xml:ns:yang:ietf-interfaces";
-        final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> mapEntryNode = ImmutableMapEntryNodeBuilder.create();
+        final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryNode =
+                ImmutableMapEntryNodeBuilder.create();
 
         final Map<String, Object> predicates = new HashMap<>();
         predicates.put("name", "eth0");