public static boolean isOKMessage(Document document) throws NetconfDocumentedException { return isOKMessage(XmlElement.fromDomDocument(document)); }
public static boolean isErrorMessage(Document document) throws NetconfDocumentedException { return isErrorMessage(XmlElement.fromDomDocument(document)); }
public static Document checkIsMessageOk(Document response) throws DocumentedException { XmlElement element = XmlElement.fromDomDocument(response); Preconditions.checkState(element.getName().equals(XmlMappingConstants.RPC_REPLY_KEY)); element = element.getOnlyChildElement(); if (element.getName().equals(XmlNetconfConstants.OK)) { return response; } LOG.warn("Can not load last configuration. Operation failed."); throw new IllegalStateException("Can not load last configuration. Operation failed: " + XmlUtil.toString(response)); }
public static Collection<String> extractCapabilitiesFromHello(Document doc) throws NetconfDocumentedException { XmlElement responseElement = XmlElement.fromDomDocument(doc); // Extract child element <capabilities> from <hello> with or without(fallback) the same namespace Optional<XmlElement> capabilitiesElement = responseElement .getOnlyChildElementWithSameNamespaceOptionally(XmlNetconfConstants.CAPABILITIES) .or(responseElement .getOnlyChildElementOptionally(XmlNetconfConstants.CAPABILITIES)); List<XmlElement> caps = capabilitiesElement.get().getChildElements(XmlNetconfConstants.CAPABILITY); return Collections2.transform(caps, new Function<XmlElement, String>() { @Override public String apply(@Nonnull XmlElement input) { // Trim possible leading/tailing whitespace try { return input.getTextContent().trim(); } catch (DocumentedException e) { LOG.trace("Error fetching input text content",e); return null; } } }); } }
private static Document filteredNotification(XmlElement filter, Document originalNotification) throws DocumentedException { Document result = XmlUtil.newDocument(); XmlElement dataSrc = XmlElement.fromDomDocument(originalNotification); Element dataDst = (Element) result.importNode(dataSrc.getDomElement(), false); for (XmlElement filterChild : filter.getChildElements()) { addSubtree2(filterChild, dataSrc.getOnlyChildElement(), XmlElement.fromDomElement(dataDst)); } if(dataDst.getFirstChild() != null) { result.appendChild(dataDst.getFirstChild()); return result; } else { return null; } }
@Override public final void startExiCommunication(final NetconfMessage startExiMessage) { final EXIParameters exiParams; try { exiParams = EXIParameters.fromXmlElement(XmlElement.fromDomDocument(startExiMessage.getDocument())); } catch (final EXIOptionsException e) { LOG.warn("Unable to parse EXI parameters from {} on session {}", startExiMessage, this, e); throw new IllegalArgumentException("Cannot parse options", e); } final NetconfEXICodec exiCodec = new NetconfEXICodec(exiParams.getOptions()); final NetconfMessageToEXIEncoder exiEncoder; try { exiEncoder = NetconfMessageToEXIEncoder.create(exiCodec); } catch (EXIOptionsException | TransmogrifierException e) { LOG.warn("Failed to instantiate EXI encoder for {} on session {}", exiCodec, this, e); throw new IllegalStateException("Cannot instantiate encoder for options", e); } final NetconfEXIToMessageDecoder exiDecoder; try { exiDecoder = NetconfEXIToMessageDecoder.create(exiCodec); } catch (EXIOptionsException e) { LOG.warn("Failed to instantiate EXI decodeer for {} on session {}", exiCodec, this, e); throw new IllegalStateException("Cannot instantiate encoder for options", e); } addExiHandlers(exiDecoder, exiEncoder); LOG.debug("Session {} EXI handlers added to pipeline", this); }