\r
package org.commscope.tr069adapter.netconf.rpc;\r
\r
+import java.io.StringReader;\r
+\r
+import javax.xml.parsers.DocumentBuilder;\r
+import javax.xml.parsers.DocumentBuilderFactory;\r
+\r
+import org.commscope.tr069adapter.mapper.model.ErrorCodeDetails;\r
+import org.commscope.tr069adapter.mapper.model.NetConfResponse;\r
import org.commscope.tr069adapter.netconf.boot.NetConfServiceBooter;\r
import org.commscope.tr069adapter.netconf.config.NetConfServerProperties;\r
import org.opendaylight.netconf.api.DocumentedException;\r
+import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;\r
+import org.opendaylight.netconf.api.DocumentedException.ErrorTag;\r
+import org.opendaylight.netconf.api.DocumentedException.ErrorType;\r
import org.opendaylight.netconf.api.xml.XmlElement;\r
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;\r
import org.opendaylight.netconf.mapping.api.HandlingPriority;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
import org.w3c.dom.Document;\r
+import org.xml.sax.InputSource;\r
\r
public class SoftwareDownloadOperation implements NetconfOperation {\r
private static final Logger logger = LoggerFactory.getLogger(SoftwareDownloadOperation.class);\r
public Document handle(Document requestMessage,\r
NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {\r
\r
- logger.debug("sw-download rpc recevied in netconf server");\r
+ logger.debug("soft-ware download rpc is received in netconfserver");\r
+\r
final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);\r
+ final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);\r
\r
String requestXml = XmlUtility.convertDocumentToString(requestElement);\r
- logger.debug("sw-download rpc recevied requestXml = {}", requestXml);\r
+ logger.debug("soft-ware download rpc requestXml=" + requestXml);\r
+\r
NetConfServerProperties config =\r
NetConfServiceBooter.getApplicationContext().getBean(NetConfServerProperties.class);\r
\r
final String baseUrl = config.getMapperPath() + "/softwareDowload";\r
- XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID);\r
+ NetConfResponse restResponse = XmlUtility.invokeMapperCall(baseUrl, requestXml, deviceID);\r
+\r
+ Document document = null;\r
+\r
+ ErrorCodeDetails errorCode = restResponse.getErrorCode();\r
+ if (errorCode != null && errorCode.getFaultCode() != null\r
+ && !errorCode.getFaultCode().equalsIgnoreCase("0")) {\r
+ logger.error("Error recevied : " + errorCode);\r
+ throw new DocumentedException(errorCode.getErrorMessage(),\r
+ ErrorType.from(errorCode.getErrorType()), ErrorTag.from(errorCode.getErrorTag()),\r
+ ErrorSeverity.from(errorCode.getErrorSeverity()));\r
+ } else if (restResponse != null && restResponse.getNetconfResponseXml() != null) {\r
+ logger.debug("soft-ware download rpc response received from mapper "\r
+ + restResponse.getNetconfResponseXml());\r
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\r
+ DocumentBuilder builder;\r
+ try {\r
+ builder = factory.newDocumentBuilder();\r
+ document =\r
+ builder.parse(new InputSource(new StringReader(restResponse.getNetconfResponseXml())));\r
+ document.getDocumentElement().setAttribute("xmlns:ns1", getOperationNamespace());\r
+ document.getDocumentElement().setAttribute("xmlns",\r
+ XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);\r
+ document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);\r
+ } catch (Exception e) {\r
+ logger.error("while contruscting the response; ", e.toString());\r
+ }\r
+ }\r
\r
- return null;\r
+ return document;\r
}\r
\r
protected HandlingPriority canHandle(final String operationName,\r
return XmlElement.fromDomElementWithExpected(message.getDocumentElement(),\r
XmlNetconfConstants.RPC_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);\r
}\r
+\r
+ protected String getOperationNamespace() {\r
+ return "urn:o-ran:software-management:1.0";\r
+ }\r
+\r
+ protected String getOperationName() {\r
+ return "software-download";\r
+ }\r
}\r