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.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;
20 public final class XmlOperationInputBody extends OperationInputBody {
21 private static final Logger LOG = LoggerFactory.getLogger(XmlOperationInputBody.class);
23 public XmlOperationInputBody(final InputStream inputStream) {
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());
33 final var databind = path.databind();
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);