test of namespace suplement (from xml)
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / rest / impl / XmlToCompositeNodeProvider.java
index 09733f5e907faa533167be5211b39cf2839b6345..19720107d3b2e12a63e10cedec8ec173b7ea52e8 100644 (file)
@@ -18,18 +18,11 @@ import javax.xml.stream.XMLStreamException;
 
 import org.opendaylight.controller.sal.rest.api.RestconfService;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.data.impl.XmlTreeBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 @Provider
-@Consumes({API+RestconfService.XML})
+@Consumes({ API + RestconfService.XML })
 public enum XmlToCompositeNodeProvider implements MessageBodyReader<CompositeNode> {
     INSTANCE;
-    
-    private final static Logger logger = LoggerFactory.getLogger(XmlToCompositeNodeProvider.class);
 
     @Override
     public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
@@ -40,18 +33,12 @@ public enum XmlToCompositeNodeProvider implements MessageBodyReader<CompositeNod
     public CompositeNode readFrom(Class<CompositeNode> type, Type genericType, Annotation[] annotations,
             MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
             throws IOException, WebApplicationException {
+        XmlReader xmlReader = new XmlReader();
         try {
-            Node<?> node = XmlTreeBuilder.buildDataTree(entityStream);
-            if (node instanceof SimpleNode) {
-                logger.info("Node is SimpleNode");
-                throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
-                        .entity("XML should start with XML element that contains 1..N XML child elements.").build());
-            }
-            return (CompositeNode) node;
-        } catch (XMLStreamException e) {
-            logger.info("Error during translation of InputStream to Node\n" + e.getMessage());
-            throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
-                    .entity(e.getMessage()).build());
+            return xmlReader.read(entityStream);
+        } catch (XMLStreamException | UnsupportedFormatException e) {
+            throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage())
+                    .build());
         }
     }