<?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,
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;
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);
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");
}
// 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;
}
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) {