Fix NPE when trying to download restconf provided yang files
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / restconf / impl / RestconfProviderImpl.java
index 614133bdd686ca38185c8aa2259743e3c0e8f23e..4afc5f8a6810716343653963f666648d5ded60e2 100644 (file)
@@ -15,6 +15,8 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.sal.rest.api.RestConnector;
 import org.opendaylight.netconf.sal.restconf.impl.jmx.Config;
 import org.opendaylight.netconf.sal.restconf.impl.jmx.Delete;
@@ -40,12 +42,13 @@ public class RestconfProviderImpl extends AbstractMXBean
     private final IpAddress websocketAddress;
     private final PortNumber websocketPort;
     private final StatisticsRestconfServiceWrapper stats = StatisticsRestconfServiceWrapper.getInstance();
+    private final DOMSchemaService domSchemaService;
     private ListenerRegistration<SchemaContextListener> listenerRegistration;
     private Thread webSocketServerThread;
 
     public RestconfProviderImpl(DOMDataBroker domDataBroker, SchemaService schemaService, DOMRpcService rpcService,
             DOMNotificationService notificationService, DOMMountPointService mountPointService,
-            IpAddress websocketAddress, PortNumber websocketPort) {
+            DOMSchemaService domSchemaService, IpAddress websocketAddress, PortNumber websocketPort) {
         super("Draft02ProviderStatistics", "restconf-connector", null);
         this.domDataBroker = Preconditions.checkNotNull(domDataBroker);
         this.schemaService = Preconditions.checkNotNull(schemaService);
@@ -54,6 +57,7 @@ public class RestconfProviderImpl extends AbstractMXBean
         this.mountPointService = Preconditions.checkNotNull(mountPointService);
         this.websocketAddress = Preconditions.checkNotNull(websocketAddress);
         this.websocketPort = Preconditions.checkNotNull(websocketPort);
+        this.domSchemaService = Preconditions.checkNotNull(domSchemaService);
     }
 
     public void start() {
@@ -65,6 +69,10 @@ public class RestconfProviderImpl extends AbstractMXBean
 
         ControllerContext.getInstance().setSchemas(schemaService.getGlobalContext());
         ControllerContext.getInstance().setMountService(mountPointService);
+        final DOMYangTextSourceProvider domSchemaServiceExtension =
+                (DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions()
+                        .get(DOMYangTextSourceProvider.class);
+        ControllerContext.getInstance().setYangTextSourceProvider(domSchemaServiceExtension);
 
         this.webSocketServerThread = new Thread(WebSocketServer.createInstance(
                 new String(websocketAddress.getValue()), websocketPort.getValue()));