X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frest%2Fimpl%2FXmlToCompositeNodeProvider.java;h=13d617031ad5717367ee50778c692ccfbda3fb16;hb=c61d22e4dc73fdaba09aa8c0b189ea7459679e03;hp=09733f5e907faa533167be5211b39cf2839b6345;hpb=b5daa3678322a764f9b0e2483f82781f4d39d263;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlToCompositeNodeProvider.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlToCompositeNodeProvider.java index 09733f5e90..13d617031a 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlToCompositeNodeProvider.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlToCompositeNodeProvider.java @@ -1,7 +1,12 @@ +/* + * Copyright (c) 2014 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, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.sal.rest.impl; -import static org.opendaylight.controller.sal.restconf.impl.MediaTypes.API; - import java.io.IOException; import java.io.InputStream; import java.lang.annotation.Annotation; @@ -16,20 +21,16 @@ import javax.ws.rs.ext.MessageBodyReader; import javax.ws.rs.ext.Provider; import javax.xml.stream.XMLStreamException; +import org.opendaylight.controller.sal.rest.api.Draft02; import org.opendaylight.controller.sal.rest.api.RestconfService; +import org.opendaylight.controller.sal.restconf.impl.ResponseException; 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({ Draft02.MediaTypes.DATA + RestconfService.XML, Draft02.MediaTypes.OPERATION + RestconfService.XML, + MediaType.APPLICATION_XML, MediaType.TEXT_XML }) public enum XmlToCompositeNodeProvider implements MessageBodyReader { INSTANCE; - - private final static Logger logger = LoggerFactory.getLogger(XmlToCompositeNodeProvider.class); @Override public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { @@ -40,18 +41,11 @@ public enum XmlToCompositeNodeProvider implements MessageBodyReader type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap 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 ResponseException(Response.Status.BAD_REQUEST, e.getMessage()); } }