Merge "BUG-3095 Add EventTime attribute to DOMNotification from netconf"
authorTony Tkacik <ttkacik@cisco.com>
Thu, 7 May 2015 10:26:05 +0000 (10:26 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 7 May 2015 10:26:06 +0000 (10:26 +0000)
features/akka/pom.xml
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonNormalizedNodeBodyReader.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/xml/XmlUtil.java

index 743babf58981fb85044fb57c043b13d1142c371a..142e50bbc4242ebf21ffc58d42557c3461f0fb09 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
Necessary TODO: Put your copyright here.
Copyright (c) 2014, 2015 Cisco Systems, Inc. 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,
index 3be247a3bbdc71a911570d431dc679c86e1222d4..5d63c9c01162733a2b0734f17f5e0890a3346370 100644 (file)
@@ -36,6 +36,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStre
 import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
+import org.opendaylight.yangtools.yang.data.impl.schema.ResultAlreadySetException;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
@@ -106,6 +107,11 @@ public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPr
             return new NormalizedNodeContext(path,result);
         } catch (final RestconfDocumentedException e) {
             throw e;
+        } catch (final ResultAlreadySetException e) {
+            LOG.debug("Error parsing json input:", e);
+
+            throw new RestconfDocumentedException("Error parsing json input: Failed to create new parse result data. " +
+                    "Are you creating multiple resources/subresources in POST request?");
         } catch (final Exception e) {
             LOG.debug("Error parsing json input", e);
 
index 6408fce5d39b199c1105807619bf9e4e0198c4f6..65754e6b34cd55f5e11f7fc481115fbc0da39de4 100644 (file)
@@ -68,6 +68,22 @@ public final class XmlUtil {
         BUILDER_FACTORY = factory;
     }
 
+    private static final ThreadLocal<DocumentBuilder> DEFAULT_DOM_BUILDER = new ThreadLocal<DocumentBuilder>(){
+        @Override
+        protected DocumentBuilder initialValue() {
+            try {
+                return BUILDER_FACTORY.newDocumentBuilder();
+            } catch (ParserConfigurationException e) {
+                throw new IllegalStateException("Failed to create threadLocal dom builder", e);
+            }
+        }
+
+        @Override
+        public void set(DocumentBuilder value) {
+            throw new UnsupportedOperationException();
+        }
+    };
+
     private XmlUtil() {
         throw new UnsupportedOperationException("Utility class");
     }
@@ -90,13 +106,7 @@ public final class XmlUtil {
     // along with XmlElement
 
     public static Document readXmlToDocument(final InputStream xmlContent) throws SAXException, IOException {
-        DocumentBuilder dBuilder;
-        try {
-            dBuilder = BUILDER_FACTORY.newDocumentBuilder();
-        } catch (ParserConfigurationException e) {
-            throw new IllegalStateException("Failed to parse XML document", e);
-        }
-        Document doc = dBuilder.parse(xmlContent);
+        Document doc = DEFAULT_DOM_BUILDER.get().parse(xmlContent);
 
         doc.getDocumentElement().normalize();
         return doc;
@@ -107,12 +117,7 @@ public final class XmlUtil {
     }
 
     public static Document newDocument() {
-        try {
-            DocumentBuilder builder = BUILDER_FACTORY.newDocumentBuilder();
-            return builder.newDocument();
-        } catch (ParserConfigurationException e) {
-            throw new IllegalStateException("Failed to create document", e);
-        }
+        return DEFAULT_DOM_BUILDER.get().newDocument();
     }
 
     public static Element createElement(final Document document, final String qName, final Optional<String> namespaceURI) {