Remove "/" sign in AbstractRestconfStreamRegistry
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / server / api / XmlOperationInputBody.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.restconf.server.api;
9
10 import java.io.IOException;
11 import java.io.InputStream;
12 import javax.xml.stream.XMLStreamException;
13 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
14 import org.opendaylight.restconf.server.api.DatabindPath.OperationPath;
15 import org.opendaylight.yangtools.util.xml.UntrustedXML;
16 import org.opendaylight.yangtools.yang.common.ErrorTag;
17 import org.opendaylight.yangtools.yang.common.ErrorType;
18 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
19 import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public final class XmlOperationInputBody extends OperationInputBody {
24     private static final Logger LOG = LoggerFactory.getLogger(XmlOperationInputBody.class);
25
26     public XmlOperationInputBody(final InputStream inputStream) {
27         super(inputStream);
28     }
29
30     @Override
31     void streamTo(final OperationPath path, final InputStream inputStream, final NormalizedNodeStreamWriter writer)
32             throws IOException {
33         final var stack = path.inference().toSchemaInferenceStack();
34         stack.enterDataTree(path.inputStatement().argument());
35
36         try {
37             XmlParserStream.create(writer, path.databind().xmlCodecs(), stack.toInference())
38                 .parse(UntrustedXML.createXMLStreamReader(inputStream));
39         } catch (XMLStreamException e) {
40             LOG.debug("Error parsing XML input", e);
41             throwIfYangError(e);
42             throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
43                     ErrorTag.MALFORMED_MESSAGE, e);
44         }
45     }
46 }