Merge "Removing { } from NormalizedNodeJsonBodyWriter"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / rest / impl / XmlToCompositeNodeProvider.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.rest.impl;
9
10 import java.io.IOException;
11 import java.io.InputStream;
12 import java.lang.annotation.Annotation;
13 import java.lang.reflect.Type;
14 import javax.ws.rs.Consumes;
15 import javax.ws.rs.WebApplicationException;
16 import javax.ws.rs.core.MediaType;
17 import javax.ws.rs.core.MultivaluedMap;
18 import javax.ws.rs.ext.MessageBodyReader;
19 import javax.ws.rs.ext.Provider;
20 import javax.xml.stream.XMLStreamException;
21 import org.opendaylight.controller.sal.rest.api.Draft02;
22 import org.opendaylight.controller.sal.rest.api.RestconfService;
23 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
24 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
25 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
26 import org.opendaylight.yangtools.yang.data.api.Node;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * @deprecated class will be removed in Lithium release
32  */
33 @Provider
34 @Consumes({ Draft02.MediaTypes.DATA + RestconfService.XML, Draft02.MediaTypes.OPERATION + RestconfService.XML,
35         MediaType.APPLICATION_XML, MediaType.TEXT_XML })
36 public enum XmlToCompositeNodeProvider implements MessageBodyReader<Node<?>> {
37     INSTANCE;
38     private final static Logger LOG = LoggerFactory.getLogger(XmlToCompositeNodeProvider.class);
39
40     @Override
41     public boolean isReadable(final Class<?> type, final Type genericType, final Annotation[] annotations,
42             final MediaType mediaType) {
43         return true;
44     }
45
46     @Override
47     public Node<?> readFrom(final Class<Node<?>> type, final Type genericType, final Annotation[] annotations,
48             final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream)
49             throws IOException, WebApplicationException {
50         final XmlToCompositeNodeReader xmlReader = new XmlToCompositeNodeReader();
51         try {
52             return xmlReader.read(entityStream);
53         } catch (XMLStreamException | UnsupportedFormatException e) {
54             LOG.debug("Error parsing json input", e);
55             throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
56                     ErrorTag.MALFORMED_MESSAGE);
57         }
58     }
59
60 }