2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.restconf.server.api;
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;
23 public final class XmlOperationInputBody extends OperationInputBody {
24 private static final Logger LOG = LoggerFactory.getLogger(XmlOperationInputBody.class);
26 public XmlOperationInputBody(final InputStream inputStream) {
31 void streamTo(final OperationPath path, final InputStream inputStream, final NormalizedNodeStreamWriter writer)
33 final var stack = path.inference().toSchemaInferenceStack();
34 stack.enterDataTree(path.inputStatement().argument());
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);
42 throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
43 ErrorTag.MALFORMED_MESSAGE, e);