+ @Override
+ public DOMActionResult toActionResult(final Absolute action, final NetconfMessage message) {
+ final ActionDefinition actionDefinition = actions.get(action);
+ checkArgument(actionDefinition != null, "Action does not exist: %s", action);
+ final ContainerNode normalizedNode = parseResult(message, action, actionDefinition);
+
+ if (normalizedNode == null) {
+ return new SimpleDOMActionResult(List.of());
+ } else {
+ return new SimpleDOMActionResult(normalizedNode, List.of());
+ }
+ }
+
+ private ContainerNode parseResult(final NetconfMessage message, final Absolute operationPath,
+ final OperationDefinition operationDef) {
+ final Optional<XmlElement> okResponseElement = XmlElement.fromDomDocument(message.getDocument())
+ .getOnlyChildElementWithSameNamespaceOptionally("ok");
+ final var operOutput = operationDef.getOutput();
+ if (operOutput.getChildNodes().isEmpty()) {
+ checkArgument(okResponseElement.isPresent(), "Unexpected content in response of operation: %s, %s",
+ operationDef.getQName(), message);
+ return null;
+ }
+ if (okResponseElement.isPresent()) {
+ // FIXME: could be an action as well
+ LOG.debug("Received response <ok/> for RPC with defined Output");
+ return null;
+ }
+
+ final var operSteps = operationPath.getNodeIdentifiers();
+ final var outputPath = Absolute.of(ImmutableList.<QName>builderWithExpectedSize(operSteps.size() + 1)
+ .addAll(operSteps)
+ .add(operOutput.getQName())
+ .build());
+ // FIXME: we should have a cached inference here, or XMLParserStream should accept Absolute instead
+ final var inference = SchemaInferenceStack.of(mountContext.getEffectiveModelContext(), outputPath)
+ .toInference();
+
+ final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
+ final Element element = message.getDocument().getDocumentElement();
+ try {
+ final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
+ final XmlParserStream xmlParser = XmlParserStream.create(writer, mountContext, inference, strictParsing);
+ xmlParser.traverse(new DOMSource(element));
+ } catch (XMLStreamException | URISyntaxException | IOException | SAXException e) {
+ throw new IllegalArgumentException(String.format("Failed to parse RPC response %s", element), e);
+ }
+ return (ContainerNode) resultHolder.getResult();
+ }
+
+ @Beta
+ public static class NetconfDeviceNotification implements DOMNotification, DOMEvent {