+ Preconditions.checkArgument(isHelloMessage(doc),
+ "Hello message invalid format, should contain %s tag from namespace %s, but is: %s", HELLO_TAG,
+ XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlUtil.toString(doc));
+ }
+
+ public static NetconfHelloMessage createClientHello(Iterable<String> capabilities,
+ Optional<NetconfHelloMessageAdditionalHeader> additionalHeaderOptional) throws NetconfDocumentedException {
+ Document doc = createHelloMessageDoc(capabilities);
+ return additionalHeaderOptional.isPresent() ? new NetconfHelloMessage(doc, additionalHeaderOptional.get())
+ : new NetconfHelloMessage(doc);
+ }
+
+ private static Document createHelloMessageDoc(Iterable<String> capabilities) {
+ Document doc = XmlUtil.newDocument();
+ Element helloElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
+ HELLO_TAG);
+ Element capabilitiesElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
+ XmlNetconfConstants.CAPABILITIES);
+
+ for (String capability : Sets.newHashSet(capabilities)) {
+ Element capElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
+ XmlNetconfConstants.CAPABILITY);
+ capElement.setTextContent(capability);
+ capabilitiesElement.appendChild(capElement);
+ }