use of org.opendaylight.netconf.api.xml.MissingNameSpaceException in project netconf by opendaylight.
the class NetconfMessageTransformer method toNotification.
@Override
public synchronized DOMNotification toNotification(final NetconfMessage message) {
final Entry<Instant, XmlElement> stripped = NetconfMessageTransformUtil.stripNotification(message);
final QName notificationNoRev;
try {
notificationNoRev = QName.create(stripped.getValue().getNamespace(), stripped.getValue().getName()).withoutRevision();
} catch (final MissingNameSpaceException e) {
throw new IllegalArgumentException("Unable to parse notification " + message + ", cannot find namespace", e);
}
Collection<? extends NotificationDefinition> notificationDefinitions = mappedNotifications.get(notificationNoRev);
Element element = stripped.getValue().getDomElement();
NestedNotificationInfo nestedNotificationInfo = null;
if (notificationDefinitions.isEmpty()) {
// check if notification is nested notification
Optional<NestedNotificationInfo> nestedNotificationOptional = findNestedNotification(message, element);
if (nestedNotificationOptional.isPresent()) {
nestedNotificationInfo = nestedNotificationOptional.get();
notificationDefinitions = Collections.singletonList(nestedNotificationInfo.notificationDefinition);
element = (Element) nestedNotificationInfo.notificationNode;
}
}
Preconditions.checkArgument(notificationDefinitions.size() > 0, "Unable to parse notification %s, unknown notification. Available notifications: %s", notificationDefinitions, mappedNotifications.keySet());
final NotificationDefinition mostRecentNotification = getMostRecentNotification(notificationDefinitions);
final ContainerNode content;
try {
final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
final XmlParserStream xmlParser = XmlParserStream.create(writer, mountContext, SchemaInferenceStack.ofInstantiatedPath(mountContext.getEffectiveModelContext(), mostRecentNotification.getPath()).toInference(), strictParsing);
xmlParser.traverse(new DOMSource(element));
content = (ContainerNode) resultHolder.getResult();
} catch (XMLStreamException | URISyntaxException | IOException | SAXException | UnsupportedOperationException e) {
throw new IllegalArgumentException(String.format("Failed to parse notification %s", element), e);
}
if (nestedNotificationInfo != null) {
return new NetconfDeviceTreeNotification(content, // FIXME: improve this to cache the path
mostRecentNotification.getPath().asAbsolute(), stripped.getKey(), nestedNotificationInfo.domDataTreeIdentifier);
}
return new NetconfDeviceNotification(content, stripped.getKey());
}
use of org.opendaylight.netconf.api.xml.MissingNameSpaceException in project netconf by opendaylight.
the class SchemalessMessageTransformer method toNotification.
@Override
public DOMNotification toNotification(final NetconfMessage message) {
final Map.Entry<Instant, XmlElement> stripped = NetconfMessageTransformUtil.stripNotification(message);
final QName notificationNoRev;
try {
notificationNoRev = QName.create(stripped.getValue().getNamespace(), stripped.getValue().getName()).withoutRevision();
} catch (final MissingNameSpaceException e) {
throw new IllegalArgumentException("Unable to parse notification " + message + ", cannot find namespace", e);
}
final DOMSourceAnyxmlNode notificationPayload = Builders.anyXmlBuilder().withNodeIdentifier(new NodeIdentifier(notificationNoRev)).withValue(new DOMSource(stripped.getValue().getDomElement())).build();
final ContainerNode notificationBody = Builders.containerBuilder().withNodeIdentifier(SCHEMALESS_NOTIFICATION_PAYLOAD).withChild(notificationPayload).build();
return new NetconfMessageTransformer.NetconfDeviceNotification(notificationBody, stripped.getKey());
}
use of org.opendaylight.netconf.api.xml.MissingNameSpaceException in project netconf by opendaylight.
the class FilterContentValidator method validateNode.
/**
* Recursively checks filter elements against the schema. Returns tree of nodes QNames as they appear in filter.
*
* @param element element to check
* @param parentNodeSchema parent node schema
* @param tree parent node tree
* @return tree
* @throws ValidationException if filter content is not valid
*/
private FilterTree validateNode(final XmlElement element, final DataSchemaNode parentNodeSchema, final FilterTree tree) throws ValidationException {
final List<XmlElement> childElements = element.getChildElements();
for (final XmlElement childElement : childElements) {
try {
final Deque<DataSchemaNode> path = findSchemaNodeByNameAndNamespace(parentNodeSchema, childElement.getName(), XMLNamespace.of(childElement.getNamespace()));
if (path.isEmpty()) {
throw new ValidationException(element, childElement);
}
FilterTree subtree = tree;
for (final DataSchemaNode dataSchemaNode : path) {
subtree = subtree.addChild(dataSchemaNode);
}
final DataSchemaNode childSchema = path.getLast();
validateNode(childElement, childSchema, subtree);
} catch (IllegalArgumentException | MissingNameSpaceException e) {
throw new RuntimeException("Wrong namespace in element + " + childElement.toString(), e);
}
}
return tree;
}
Aggregations