Remove unnecessary check for canceled future
[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.server.api.DatabindPath.OperationPath;
14 import org.opendaylight.yangtools.util.xml.UntrustedXML;
15 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
16 import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public final class XmlOperationInputBody extends OperationInputBody {
21     private static final Logger LOG = LoggerFactory.getLogger(XmlOperationInputBody.class);
22
23     public XmlOperationInputBody(final InputStream inputStream) {
24         super(inputStream);
25     }
26
27     @Override
28     void streamTo(final OperationPath path, final InputStream inputStream, final NormalizedNodeStreamWriter writer)
29             throws ServerException {
30         final var stack = path.inference().toSchemaInferenceStack();
31         stack.enterDataTree(path.inputStatement().argument());
32
33         final var databind = path.databind();
34         try {
35             XmlParserStream.create(writer, databind.xmlCodecs(), stack.toInference())
36                 .parse(UntrustedXML.createXMLStreamReader(inputStream));
37         } catch (IllegalArgumentException | IOException | XMLStreamException e) {
38             LOG.debug("Error parsing XML input", e);
39             throw databind.newProtocolMalformedMessageServerException("Invalid XML", e);
40         }
41     }
42 }