2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.rest.impl;
10 import java.io.IOException;
11 import java.io.InputStream;
12 import java.lang.annotation.Annotation;
13 import java.lang.reflect.Type;
15 import javax.ws.rs.Consumes;
16 import javax.ws.rs.WebApplicationException;
17 import javax.ws.rs.core.MediaType;
18 import javax.ws.rs.core.MultivaluedMap;
19 import javax.ws.rs.core.Response;
20 import javax.ws.rs.ext.MessageBodyReader;
21 import javax.ws.rs.ext.Provider;
22 import javax.xml.stream.XMLStreamException;
24 import org.opendaylight.controller.sal.rest.api.Draft01;
25 import org.opendaylight.controller.sal.rest.api.Draft02;
26 import org.opendaylight.controller.sal.rest.api.RestconfService;
27 import org.opendaylight.controller.sal.restconf.impl.ResponseException;
28 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
31 @Consumes({ Draft01.MediaTypes.DATA + RestconfService.XML, Draft02.MediaTypes.DATA + RestconfService.XML,
32 MediaType.APPLICATION_XML, MediaType.TEXT_XML })
33 public enum XmlToCompositeNodeProvider implements MessageBodyReader<CompositeNode> {
37 public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
42 public CompositeNode readFrom(Class<CompositeNode> type, Type genericType, Annotation[] annotations,
43 MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
44 throws IOException, WebApplicationException {
45 XmlReader xmlReader = new XmlReader();
47 return xmlReader.read(entityStream);
48 } catch (XMLStreamException | UnsupportedFormatException e) {
49 throw new ResponseException(Response.Status.BAD_REQUEST, e.getMessage());