use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.
the class SchemalessRpcStructureTransformer method selectFromDataStructure.
/**
* Selects elements in anyxml data node, which matches path arguments QNames. Since class in not context aware,
* method searches for all elements as they are named in path.
* @param data data, must be of type {@link DOMSourceAnyxmlNode}
* @param path path to select
* @return selected data
*/
@Override
public Optional<NormalizedNode> selectFromDataStructure(final DataContainerChild data, final YangInstanceIdentifier path) {
Preconditions.checkArgument(data instanceof DOMSourceAnyxmlNode);
final List<XmlElement> xmlElements = selectMatchingNodes(getSourceElement(((DOMSourceAnyxmlNode) data).body()), path);
final Document result = XmlUtil.newDocument();
final Element dataElement = result.createElementNS(NETCONF_DATA_QNAME.getNamespace().toString(), NETCONF_DATA_QNAME.getLocalName());
result.appendChild(dataElement);
for (XmlElement xmlElement : xmlElements) {
dataElement.appendChild(result.importNode(xmlElement.getDomElement(), true));
}
final DOMSourceAnyxmlNode resultAnyxml = Builders.anyXmlBuilder().withNodeIdentifier(NETCONF_DATA_NODEID).withValue(new DOMSource(result)).build();
return Optional.of(resultAnyxml);
}
use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.
the class DefaultCloseSessionTest method testDefaultCloseSession2.
@Test
public void testDefaultCloseSession2() throws Exception {
final NetconfDocumentedException expectedCause = new NetconfDocumentedException("testMessage");
final AutoCloseable res = mock(AutoCloseable.class);
doThrow(expectedCause).when(res).close();
final DefaultCloseSession session = new DefaultCloseSession("testSession", res);
XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
final DocumentedException ex = assertThrows(DocumentedException.class, () -> session.handleWithNoSubsequentOperations(XmlUtil.newDocument(), elem));
assertEquals("Unable to properly close session testSession", ex.getMessage());
assertSame(expectedCause, ex.getCause());
}
use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.
the class DefaultStopExi method handleWithNoSubsequentOperations.
@Override
protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement) {
LOG.debug("Received stop-exi message {} ", XmlUtil.toString(operationElement));
netconfSession.stopExiCommunication();
Element getSchemaResult = document.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlNetconfConstants.OK);
LOG.trace("{} operation successful", STOP_EXI);
return getSchemaResult;
}
use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.
the class SchemalessRpcStructureTransformerTest method testSelectFromDataStructure.
@Test
public void testSelectFromDataStructure() throws Exception {
DOMSourceAnyxmlNode data = Builders.anyXmlBuilder().withNodeIdentifier(createNodeId(path.getLastPathArgument().getNodeType().getLocalName())).withValue(new DOMSource(XmlUtil.readXmlToDocument(getConfigData).getDocumentElement())).build();
final DOMSourceAnyxmlNode dataStructure = (DOMSourceAnyxmlNode) adapter.selectFromDataStructure(data, path).get();
final XmlElement s = XmlElement.fromDomDocument((Document) dataStructure.body().getNode());
final String dataFromReply = XmlUtil.toString(s.getOnlyChildElement().getDomElement());
final String expectedData = XmlUtil.toString((Element) source.getNode());
Diff diff = new Diff(expectedData, dataFromReply);
assertTrue(String.format("Input %s: %s", testDataset, diff.toString()), diff.similar());
}
use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.
the class SettableRpc method handle.
@Override
public Document handle(final Document requestMessage, final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
final XmlElement rpcElement = requestElement.getOnlyChildElement();
final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
final Optional<Document> response = mapping.getResponse(rpcElement);
if (response.isPresent()) {
final Document document = response.get();
checkForError(document);
document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);
return document;
} else if (subsequentOperation.isExecutionTermination()) {
throw new DocumentedException("Mapping not found " + XmlUtil.toString(requestMessage), ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
} else {
return subsequentOperation.execute(requestMessage);
}
}
Aggregations