* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.mdsal.connector.ops;
import static java.nio.charset.StandardCharsets.UTF_8;
-import com.google.common.base.Optional;
import com.google.common.base.Strings;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.util.Base64;
+import java.util.Optional;
import org.opendaylight.netconf.api.DocumentedException;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
final Optional<XmlElement> configElement = parent.getOnlyChildElementOptionally(CONFIG_KEY);
if (configElement.isPresent()) {
return configElement.get();
- } else {
- final Optional<XmlElement> urlElement = parent.getOnlyChildElementOptionally(URL_KEY);
- if (!urlElement.isPresent()) {
- throw new DocumentedException("Invalid RPC, neither <config> not <url> element is present",
- DocumentedException.ErrorType.PROTOCOL,
- DocumentedException.ErrorTag.MISSING_ELEMENT,
- DocumentedException.ErrorSeverity.ERROR);
- }
+ }
- final Document document = getDocumentFromUrl(urlElement.get().getTextContent());
- return XmlElement.fromDomElementWithExpected(document.getDocumentElement(), CONFIG_KEY,
- XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+ final Optional<XmlElement> urlElement = parent.getOnlyChildElementOptionally(URL_KEY);
+ if (urlElement.isEmpty()) {
+ throw new DocumentedException("Invalid RPC, neither <config> not <url> element is present",
+ ErrorType.PROTOCOL, DocumentedException.ErrorTag.MISSING_ELEMENT, ErrorSeverity.ERROR);
}
+
+ final Document document = getDocumentFromUrl(urlElement.get().getTextContent());
+ return XmlElement.fromDomElementWithExpected(document.getDocumentElement(), CONFIG_KEY,
+ XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
}
/**
return XmlUtil.readXmlToDocument(input);
} catch (MalformedURLException e) {
throw new DocumentedException(url + " URL is invalid or unsupported", e,
- DocumentedException.ErrorType.APPLICATION,
- DocumentedException.ErrorTag.INVALID_VALUE,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
} catch (IOException e) {
- throw new DocumentedException("Could not open URL:" + url, e,
- DocumentedException.ErrorType.APPLICATION,
- DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR);
+ throw new DocumentedException("Could not open URL " + url, e,
+ ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
} catch (SAXException e) {
throw new DocumentedException("Could not parse XML at" + url, e,
- DocumentedException.ErrorType.APPLICATION,
- DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
}
}