Manual cherrypicks from oxygen 67/66267/1
authorJakub Toth <jakub.toth@pantheon.tech>
Wed, 6 Dec 2017 10:12:45 +0000 (11:12 +0100)
committerJakub Toth <jakub.toth@pantheon.tech>
Wed, 6 Dec 2017 10:12:53 +0000 (11:12 +0100)
  * Fix hardcoded port
    * https://git.opendaylight.org/gerrit/#/c/65872/2
  * Add update method of handlers for rest services
    * https://git.opendaylight.org/gerrit/#/c/65458/
  * NPE when try get schema as yang
    * https://git.opendaylight.org/gerrit/#/c/65804/

Change-Id: Ifc7fe98b4abcbf29e00bdddf2072045acc3222ca
Signed-off-by: Jakub Toth <jakub.toth@pantheon.tech>
38 files changed:
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaExportContentYangBodyWriter.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaExportContext.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaRetrievalServiceImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/SimpleUriInfo.java [new file with mode: 0644]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/RestConnectorProvider.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/base/services/api/RestconfOperationsService.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/base/services/api/RestconfSchemaService.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/base/services/api/RestconfService.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/base/services/api/UpdateHandlers.java [new file with mode: 0644]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/base/services/impl/RestconfImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/base/services/impl/RestconfOperationsServiceImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/base/services/impl/RestconfSchemaServiceImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/common/wrapper/services/ServicesWrapperImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/AbstractIdentifierAwareJaxRsProvider.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfDataService.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfInvokeOperationsService.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/api/RestconfStreamsSubscriptionService.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/impl/RestconfInvokeOperationsServiceImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/impl/RestconfStreamsSubscriptionServiceImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/utils/SubscribeToStreamUtil.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/utils/parser/ParserIdentifier.java
restconf/sal-rest-connector/src/main/resources/org/opendaylight/blueprint/restconf-config.xml
restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/JSONRestconfServiceDraft18Test.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfSchemaServiceTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/AbstractBodyReaderTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonBodyReaderTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonPatchBodyReaderMountPointTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonPatchBodyReaderTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/XmlBodyReaderMountPointTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/XmlBodyReaderTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/XmlPatchBodyReaderMountPointTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/XmlPatchBodyReaderTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfStreamsSubscriptionServiceImplTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/parser/ParserIdentifierTest.java

index 5c03733a7898027b7b697ea751588b7e81c0301b..7409c070f1d7583ec37402777694d9d1a89c38ba 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.netconf.md.sal.rest.schema;
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.PrintWriter;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import javax.ws.rs.Produces;
@@ -19,6 +18,9 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
 import org.opendaylight.restconf.Rfc8040;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 
 @Provider
 @Produces({ SchemaRetrievalService.YANG_MEDIA_TYPE, Rfc8040.MediaTypes.YANG })
@@ -41,8 +43,14 @@ public class SchemaExportContentYangBodyWriter implements MessageBodyWriter<Sche
             final Annotation[] annotations, final MediaType mediaType,
             final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException,
             WebApplicationException {
-        final PrintWriter writer = new PrintWriter(entityStream);
-        writer.write(context.getModule().getSource());
-
+        final RevisionSourceIdentifier sourceId = RevisionSourceIdentifier.create(context.getModule().getName(),
+                context.getModule().getQNameModule().getFormattedRevision());
+        final YangTextSchemaSource yangTextSchemaSource;
+        try {
+            yangTextSchemaSource = context.getSourceProvider().getSource(sourceId).checkedGet();
+        } catch (final SchemaSourceException e) {
+            throw new WebApplicationException("Unable to retrieve source from SourceProvider.", e);
+        }
+        yangTextSchemaSource.copyTo(entityStream);
     }
 }
index a947af9d912ff4ab3ed75691bf9dcdb61543cd33..8e17a2806182be61529a8b39afed684bddc1951e 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netconf.md.sal.rest.schema;
 
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
@@ -14,10 +15,13 @@ public class SchemaExportContext {
 
     private final SchemaContext schemaContext;
     private final Module module;
+    private final DOMYangTextSourceProvider sourceProvider;
 
-    public SchemaExportContext(final SchemaContext ctx, final Module module) {
+    public SchemaExportContext(final SchemaContext ctx, final Module module,
+            final DOMYangTextSourceProvider sourceProvider) {
         schemaContext = ctx;
         this.module = module;
+        this.sourceProvider = sourceProvider;
     }
 
     public SchemaContext getSchemaContext() {
@@ -28,4 +32,7 @@ public class SchemaExportContext {
         return module;
     }
 
+    public DOMYangTextSourceProvider getSourceProvider() {
+        return sourceProvider;
+    }
 }
index 46f2398c85fbd1c6f0ce766006dc60b03db138bc..0a837d15e73527267278f6847e9fd3f9dea8c5e1 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.collect.Iterables;
 import java.text.ParseException;
 import java.util.Date;
 import java.util.Iterator;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.md.sal.rest.common.RestconfValidationUtils;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
@@ -66,16 +67,18 @@ public class SchemaRetrievalServiceImpl implements SchemaRetrievalService {
         RestconfValidationUtils.checkDocumentedError(componentIter.hasNext(),
                 ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE, "Revision date must be supplied.");
         final String revisionString = componentIter.next();
-        return getExportUsingNameAndRevision(schemaContext, moduleName, revisionString);
+        return getExportUsingNameAndRevision(schemaContext, moduleName, revisionString,
+                salContext.getYangTextSourceProvider());
     }
 
     private static SchemaExportContext getExportUsingNameAndRevision(final SchemaContext schemaContext,
-            final String moduleName, final String revisionStr) {
+            final String moduleName, final String revisionStr, final DOMYangTextSourceProvider yangTextSourceProvide) {
         try {
             final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse(revisionStr);
             final Module module = schemaContext.findModuleByName(moduleName, revision);
             return new SchemaExportContext(
-                    schemaContext, RestconfValidationUtils.checkNotNullDocumented(module, moduleName));
+                    schemaContext, RestconfValidationUtils.checkNotNullDocumented(module, moduleName),
+                    yangTextSourceProvide);
         } catch (final ParseException e) {
             throw new RestconfDocumentedException("Supplied revision is not in expected date format YYYY-mm-dd", e);
         }
index 7ebb0dcd4b57c0009e0c34e010dc974328635aab..fea1eb6b30942ddb06f6fcd3bb80ca0350e46c37 100644 (file)
@@ -35,6 +35,7 @@ import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizat
 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule;
 import org.opendaylight.netconf.sal.rest.impl.RestUtil;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
@@ -92,6 +93,7 @@ public class ControllerContext implements SchemaContextListener {
     // FIXME; these three should be final
     private volatile SchemaContext globalSchema;
     private volatile DOMMountPointService mountService;
+    private volatile DOMYangTextSourceProvider yangTextSourceProvider;
     private DataNormalizer dataNormalizer;
 
 
@@ -104,6 +106,14 @@ public class ControllerContext implements SchemaContextListener {
         this.mountService = mountService;
     }
 
+    public DOMYangTextSourceProvider getYangTextSourceProvider() {
+        return yangTextSourceProvider;
+    }
+
+    public void setYangTextSourceProvider(final DOMYangTextSourceProvider yangTextSourceProvider) {
+        this.yangTextSourceProvider = yangTextSourceProvider;
+    }
+
     private ControllerContext() {
     }
 
index 2f9d3e49cfd35a82b2fc3308e1f8895bc86206b8..4cea428d276967582661fd03ce23a9cd09f1af2a 100644 (file)
@@ -14,16 +14,9 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
-import java.net.URI;
 import java.nio.charset.StandardCharsets;
-import java.util.Collections;
 import java.util.List;
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedHashMap;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.PathSegment;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
@@ -234,113 +227,4 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab
             }
         }
     }
-
-    private static class SimpleUriInfo implements UriInfo {
-        private final String path;
-        private final MultivaluedMap<String, String> queryParams;
-
-        SimpleUriInfo(String path) {
-            this(path, new MultivaluedHashMap<>());
-        }
-
-        SimpleUriInfo(String path, MultivaluedMap<String, String> queryParams) {
-            this.path = path;
-            this.queryParams = queryParams;
-        }
-
-        @Override
-        public String getPath() {
-            return path;
-        }
-
-        @Override
-        public String getPath(boolean decode) {
-            return path;
-        }
-
-        @Override
-        public List<PathSegment> getPathSegments() {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public List<PathSegment> getPathSegments(boolean decode) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public URI getRequestUri() {
-            return URI.create(path);
-        }
-
-        @Override
-        public UriBuilder getRequestUriBuilder() {
-            return UriBuilder.fromUri(getRequestUri());
-        }
-
-        @Override
-        public URI getAbsolutePath() {
-            return getRequestUri();
-        }
-
-        @Override
-        public UriBuilder getAbsolutePathBuilder() {
-            return UriBuilder.fromUri(getAbsolutePath());
-        }
-
-        @Override
-        public URI getBaseUri() {
-            return URI.create("");
-        }
-
-        @Override
-        public UriBuilder getBaseUriBuilder() {
-            return UriBuilder.fromUri(getBaseUri());
-        }
-
-        @Override
-        public MultivaluedMap<String, String> getPathParameters() {
-            return new MultivaluedHashMap<>();
-        }
-
-        @Override
-        public MultivaluedMap<String, String> getPathParameters(boolean decode) {
-            return getPathParameters();
-        }
-
-        @Override
-        public MultivaluedMap<String, String> getQueryParameters() {
-            return queryParams;
-        }
-
-        @Override
-        public MultivaluedMap<String, String> getQueryParameters(boolean decode) {
-            return getQueryParameters();
-        }
-
-        @Override
-        public List<String> getMatchedURIs() {
-            return Collections.emptyList();
-        }
-
-        @Override
-        public List<String> getMatchedURIs(boolean decode) {
-            return getMatchedURIs();
-        }
-
-        @Override
-        public List<Object> getMatchedResources() {
-            return Collections.emptyList();
-        }
-
-        @Override
-        public URI resolve(URI uri) {
-            return uri;
-        }
-
-        @Override
-        public URI relativize(URI uri) {
-            return uri;
-        }
-    }
 }
index 614133bdd686ca38185c8aa2259743e3c0e8f23e..22162ea51f657b5c636fe24de25a82143714541f 100644 (file)
@@ -14,7 +14,8 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 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;
@@ -33,7 +34,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 public class RestconfProviderImpl extends AbstractMXBean
         implements AutoCloseable, RestConnector, RestConnectorRuntimeMXBean {
     private final DOMDataBroker domDataBroker;
-    private final SchemaService schemaService;
+    private final DOMSchemaService schemaService;
     private final DOMRpcService rpcService;
     private final DOMNotificationService notificationService;
     private final DOMMountPointService mountPointService;
@@ -43,12 +44,13 @@ public class RestconfProviderImpl extends AbstractMXBean
     private ListenerRegistration<SchemaContextListener> listenerRegistration;
     private Thread webSocketServerThread;
 
-    public RestconfProviderImpl(DOMDataBroker domDataBroker, SchemaService schemaService, DOMRpcService rpcService,
-            DOMNotificationService notificationService, DOMMountPointService mountPointService,
-            IpAddress websocketAddress, PortNumber websocketPort) {
+    public RestconfProviderImpl(final DOMDataBroker domDataBroker, final DOMSchemaService domSchemaService,
+            final DOMRpcService rpcService,
+            final DOMNotificationService notificationService, final DOMMountPointService mountPointService,
+            final IpAddress websocketAddress, final PortNumber websocketPort) {
         super("Draft02ProviderStatistics", "restconf-connector", null);
         this.domDataBroker = Preconditions.checkNotNull(domDataBroker);
-        this.schemaService = Preconditions.checkNotNull(schemaService);
+        this.schemaService = Preconditions.checkNotNull(domSchemaService);
         this.rpcService = Preconditions.checkNotNull(rpcService);
         this.notificationService = Preconditions.checkNotNull(notificationService);
         this.mountPointService = Preconditions.checkNotNull(mountPointService);
@@ -66,6 +68,10 @@ public class RestconfProviderImpl extends AbstractMXBean
         ControllerContext.getInstance().setSchemas(schemaService.getGlobalContext());
         ControllerContext.getInstance().setMountService(mountPointService);
 
+        final DOMYangTextSourceProvider domSchemaServiceExtension = (DOMYangTextSourceProvider) schemaService
+                .getSupportedExtensions().get(DOMYangTextSourceProvider.class);
+        ControllerContext.getInstance().setYangTextSourceProvider(domSchemaServiceExtension);
+
         this.webSocketServerThread = new Thread(WebSocketServer.createInstance(
                 new String(websocketAddress.getValue()), websocketPort.getValue()));
         this.webSocketServerThread.setName("Web socket server on port " + websocketPort);
diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/SimpleUriInfo.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/SimpleUriInfo.java
new file mode 100644 (file)
index 0000000..a1ede08
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.sal.restconf.impl;
+
+import java.net.URI;
+import java.util.Collections;
+import java.util.List;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+
+public class SimpleUriInfo implements UriInfo {
+    private final String path;
+    private final MultivaluedMap<String, String> queryParams;
+
+    public SimpleUriInfo(final String path) {
+        this(path, new MultivaluedHashMap<>());
+    }
+
+    public SimpleUriInfo(final String path, final MultivaluedMap<String, String> queryParams) {
+        this.path = path;
+        this.queryParams = queryParams;
+    }
+
+    @Override
+    public String getPath() {
+        return path;
+    }
+
+    @Override
+    public String getPath(final boolean decode) {
+        return path;
+    }
+
+    @Override
+    public List<PathSegment> getPathSegments() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<PathSegment> getPathSegments(final boolean decode) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public URI getRequestUri() {
+        return URI.create(path);
+    }
+
+    @Override
+    public UriBuilder getRequestUriBuilder() {
+        return UriBuilder.fromUri(getRequestUri());
+    }
+
+    @Override
+    public URI getAbsolutePath() {
+        return getRequestUri();
+    }
+
+    @Override
+    public UriBuilder getAbsolutePathBuilder() {
+        return UriBuilder.fromUri(getAbsolutePath());
+    }
+
+    @Override
+    public URI getBaseUri() {
+        return URI.create("");
+    }
+
+    @Override
+    public UriBuilder getBaseUriBuilder() {
+        return UriBuilder.fromUri(getBaseUri());
+    }
+
+    @Override
+    public MultivaluedMap<String, String> getPathParameters() {
+        return new MultivaluedHashMap<>();
+    }
+
+    @Override
+    public MultivaluedMap<String, String> getPathParameters(final boolean decode) {
+        return getPathParameters();
+    }
+
+    @Override
+    public MultivaluedMap<String, String> getQueryParameters() {
+        return queryParams;
+    }
+
+    @Override
+    public MultivaluedMap<String, String> getQueryParameters(final boolean decode) {
+        return getQueryParameters();
+    }
+
+    @Override
+    public List<String> getMatchedURIs() {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public List<String> getMatchedURIs(final boolean decode) {
+        return getMatchedURIs();
+    }
+
+    @Override
+    public List<Object> getMatchedResources() {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public URI resolve(final URI uri) {
+        return uri;
+    }
+
+    @Override
+    public URI relativize(final URI uri) {
+        return uri;
+    }
+}
\ No newline at end of file
index 2aab6df3a243926742c4ca9499bfb30b6c7d878a..66e99cb427c879bd389c7ea336317c8b3a0e25f7 100644 (file)
@@ -8,7 +8,11 @@
 
 package org.opendaylight.restconf;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
+import java.util.Set;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
@@ -16,7 +20,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 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.netconf.sal.rest.api.RestConnector;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.restconf.common.wrapper.services.ServicesWrapperImpl;
@@ -27,6 +31,7 @@ import org.opendaylight.restconf.handlers.RpcServiceHandler;
 import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.handlers.TransactionChainHandler;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -57,17 +62,20 @@ public class RestConnectorProvider implements RestConnector, AutoCloseable {
     private static TransactionChainHandler transactionChainHandler;
     private static DOMDataBroker dataBroker;
     private static DOMMountPointServiceHandler mountPointServiceHandler;
+    private static SchemaContextHandler schemaCtxHandler;
 
-    private final SchemaService schemaService;
+    private final DOMSchemaService schemaService;
     private final DOMRpcService rpcService;
     private final DOMNotificationService notificationService;
     private final DOMMountPointService mountPointService;
-    private ListenerRegistration<SchemaContextListener> listenerRegistration;
+    private final Builder<Object> servicesProperties;
 
-    private SchemaContextHandler schemaCtxHandler;
+    private ListenerRegistration<SchemaContextListener> listenerRegistration;
 
-    public RestConnectorProvider(DOMDataBroker domDataBroker, SchemaService schemaService, DOMRpcService rpcService,
-            DOMNotificationService notificationService, DOMMountPointService mountPointService) {
+    public RestConnectorProvider(final DOMDataBroker domDataBroker, final DOMSchemaService schemaService,
+            final DOMRpcService rpcService, final DOMNotificationService notificationService,
+            final DOMMountPointService mountPointService) {
+        this.servicesProperties = ImmutableSet.<Object>builder();
         this.schemaService = Preconditions.checkNotNull(schemaService);
         this.rpcService = Preconditions.checkNotNull(rpcService);
         this.notificationService = Preconditions.checkNotNull(notificationService);
@@ -80,29 +88,44 @@ public class RestConnectorProvider implements RestConnector, AutoCloseable {
         final ServicesWrapperImpl wrapperServices = ServicesWrapperImpl.getInstance();
 
         mountPointServiceHandler = new DOMMountPointServiceHandler(mountPointService);
+        servicesProperties.add(mountPointServiceHandler);
 
         final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
+        servicesProperties.add(brokerHandler);
 
         RestConnectorProvider.transactionChainHandler = new TransactionChainHandler(dataBroker
                 .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER));
+        servicesProperties.add(transactionChainHandler);
+
+        schemaCtxHandler = new SchemaContextHandler(transactionChainHandler);
+        servicesProperties.add(schemaCtxHandler);
 
-        this.schemaCtxHandler = new SchemaContextHandler(transactionChainHandler);
-        this.listenerRegistration = schemaService.registerSchemaContextListener(this.schemaCtxHandler);
+        this.listenerRegistration = schemaService.registerSchemaContextListener(schemaCtxHandler);
 
         final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
+        servicesProperties.add(rpcServiceHandler);
 
         final NotificationServiceHandler notificationServiceHandler =
                 new NotificationServiceHandler(notificationService);
+        servicesProperties.add(notificationServiceHandler);
 
-        wrapperServices.setHandlers(this.schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
+        wrapperServices.setHandlers(schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
                 RestConnectorProvider.transactionChainHandler, brokerHandler, rpcServiceHandler,
-                notificationServiceHandler);
+                notificationServiceHandler, schemaService);
+    }
+
+    public final synchronized Set<Object> getServicesProperties() {
+        return servicesProperties.build();
     }
 
     public DOMMountPointServiceHandler getMountPointServiceHandler() {
         return mountPointServiceHandler;
     }
 
+    public static SchemaContext getActualSchemaContext() {
+        return schemaCtxHandler.get();
+    }
+
     /**
      * After {@link TransactionChain} failed, this updates {@link TransactionChainHandler} with new transaction chain.
      *
@@ -142,4 +165,9 @@ public class RestConnectorProvider implements RestConnector, AutoCloseable {
         mountPointServiceHandler = null;
         dataBroker = null;
     }
+
+    @VisibleForTesting
+    public static void setSchemaContextHandler(final SchemaContextHandler schemaContextHandler) {
+        schemaCtxHandler = schemaContextHandler;
+    }
 }
index 7f30ede61d50b3dba9db1b220b5c33a9c9e6af3a..390ac6f566691770c8f0a7ee6e041aca223d9201 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.restconf.utils.RestconfConstants;
  * supported by the server.
  *
  */
-public interface RestconfOperationsService {
+public interface RestconfOperationsService extends UpdateHandlers {
 
     /**
      * List of rpc or action operations supported by the server.
index 25fecde324b47481211a0073a130a92377242dd7..9410e56688abca8df52f9b6c412e180407253027 100644 (file)
@@ -20,7 +20,7 @@ import org.opendaylight.restconf.utils.RestconfConstants;
  *
  */
 @Path("/")
-public interface RestconfSchemaService {
+public interface RestconfSchemaService extends UpdateHandlers {
 
     /**
      * Get schema of specific module.
index 6e0640105ec50f88ab3ccdb5fb75714bae26fd12..f73dad4568e68bff6511c2e3b97ae899637d92ec 100644 (file)
@@ -19,7 +19,7 @@ import org.opendaylight.restconf.utils.RestconfConstants;
  * Service for getting yang library version.
  *
  */
-public interface RestconfService {
+public interface RestconfService extends UpdateHandlers {
 
     /**
      * Get yang library version.
diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/base/services/api/UpdateHandlers.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/base/services/api/UpdateHandlers.java
new file mode 100644 (file)
index 0000000..23f2df7
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2017 Pantheon technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.restconf.base.services.api;
+
+/**
+ * Allow update of handlers in web application services, if needed.
+ */
+public interface UpdateHandlers {
+
+    /**
+     * Update method for handlers in specific service (resource) of web application. Has to be implemented as
+     * synchronized to avoid conflict of update variables in multithreaded application.
+     *
+     * @param handlers
+     *            array of handlers
+     */
+    default void updateHandlers(final Object... handlers) {
+        throw new UnsupportedOperationException("This method it's not allowed for this service by default.");
+    }
+}
\ No newline at end of file
index ea87bc484e374f3fbda7b31b69dc82058d25cedd..88dc6cc1936a97e16e25527d5687096b5444c4c6 100644 (file)
@@ -25,12 +25,21 @@ import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 
 public class RestconfImpl implements RestconfService {
 
-    private final SchemaContextHandler schemaContextHandler;
+    private SchemaContextHandler schemaContextHandler;
 
     public RestconfImpl(final SchemaContextHandler schemaContextHandler) {
         this.schemaContextHandler = schemaContextHandler;
     }
 
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof SchemaContextHandler) {
+                schemaContextHandler = (SchemaContextHandler) object;
+            }
+        }
+    }
+
     @Override
     public NormalizedNodeContext getLibraryVersion() {
         final SchemaContext context = this.schemaContextHandler.get();
index 5053db01ad90d60707d655ecf2d75d7a42d39331..b4ed565e09dd33e7973d4038c58de540c49eb55c 100644 (file)
@@ -47,8 +47,8 @@ public class RestconfOperationsServiceImpl implements RestconfOperationsService
 
     private static final Logger LOG = LoggerFactory.getLogger(RestconfOperationsServiceImpl.class);
 
-    private final SchemaContextHandler schemaContextHandler;
-    private final DOMMountPointServiceHandler domMountPointServiceHandler;
+    private SchemaContextHandler schemaContextHandler;
+    private DOMMountPointServiceHandler domMountPointServiceHandler;
 
     /**
      * Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}.
@@ -64,6 +64,17 @@ public class RestconfOperationsServiceImpl implements RestconfOperationsService
         this.domMountPointServiceHandler = domMountPointServiceHandler;
     }
 
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof SchemaContextHandler) {
+                schemaContextHandler = (SchemaContextHandler) object;
+            } else if (object instanceof DOMMountPointServiceHandler) {
+                domMountPointServiceHandler = (DOMMountPointServiceHandler) object;
+            }
+        }
+    }
+
     @Override
     public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
         final SchemaContextRef ref = new SchemaContextRef(this.schemaContextHandler.get());
index cdb1b1e00ca4605d784d8fbb45793da5b57ad8bd..8f7b2e64654ae781c1a7349c85a74314dfdea417 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.restconf.base.services.impl;
 
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
 import org.opendaylight.restconf.base.services.api.RestconfSchemaService;
 import org.opendaylight.restconf.common.references.SchemaContextRef;
@@ -21,8 +22,9 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
  */
 public class RestconfSchemaServiceImpl implements RestconfSchemaService {
 
-    private final SchemaContextHandler schemaContextHandler;
-    private final DOMMountPointServiceHandler domMountPointServiceHandler;
+    private SchemaContextHandler schemaContextHandler;
+    private DOMMountPointServiceHandler domMountPointServiceHandler;
+    private DOMYangTextSourceProvider sourceProvider;
 
     /**
      * Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}
@@ -34,15 +36,30 @@ public class RestconfSchemaServiceImpl implements RestconfSchemaService {
      *             handling dom mount point service
      */
     public RestconfSchemaServiceImpl(final SchemaContextHandler schemaContextHandler,
-            final DOMMountPointServiceHandler domMountPointServiceHandler) {
+            final DOMMountPointServiceHandler domMountPointServiceHandler,
+            final DOMYangTextSourceProvider sourceProvider) {
         this.schemaContextHandler = schemaContextHandler;
         this.domMountPointServiceHandler = domMountPointServiceHandler;
+        this.sourceProvider = sourceProvider;
+    }
+
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof SchemaContextHandler) {
+                schemaContextHandler = (SchemaContextHandler) object;
+            } else if (object instanceof DOMMountPointServiceHandler) {
+                domMountPointServiceHandler = (DOMMountPointServiceHandler) object;
+            } else if (object instanceof DOMYangTextSourceProvider) {
+                sourceProvider = (DOMYangTextSourceProvider) object;
+            }
+        }
     }
 
     @Override
     public SchemaExportContext getSchema(final String identifier) {
         final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
         return ParserIdentifier.toSchemaExportContextFromIdentifier(schemaContextRef.get(), identifier,
-                this.domMountPointServiceHandler.get());
+                this.domMountPointServiceHandler.get(), sourceProvider);
     }
 }
index 8b87f81e1fcfe525d07609f4145624d4d525269e..cf6810d9abe6275156ef5008d0dfa602aaca5f7b 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.restconf.common.wrapper.services;
 import javax.ws.rs.Path;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
@@ -138,9 +140,14 @@ public class ServicesWrapperImpl implements BaseServicesWrapper, TransactionServ
     public void setHandlers(final SchemaContextHandler schemaCtxHandler,
             final DOMMountPointServiceHandler domMountPointServiceHandler,
             final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
-            final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler) {
+            final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler,
+            final DOMSchemaService domSchemaService) {
         this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
-        this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+
+        final DOMYangTextSourceProvider yangTextSourceProvider = (DOMYangTextSourceProvider) domSchemaService
+                .getSupportedExtensions().get(DOMYangTextSourceProvider.class);
+        this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler,
+                yangTextSourceProvider);
         this.delegRestconfSubscrService = new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler,
                 notificationServiceHandler, schemaCtxHandler, transactionChainHandler);
         this.delegRestconfDataService =
index 583ea44ef24b8c0f2cb859cc04bce4ba2aa45160..b0802f1f03039fe981d2bb6393b8dbd136b65b77 100644 (file)
@@ -23,7 +23,6 @@ import javax.ws.rs.core.Request;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.MessageBodyReader;
 import org.opendaylight.netconf.sal.rest.api.RestconfConstants;
-import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
 import org.opendaylight.restconf.RestConnectorProvider;
 import org.opendaylight.restconf.utils.parser.ParserIdentifier;
@@ -51,7 +50,7 @@ public abstract class AbstractIdentifierAwareJaxRsProvider<T> implements Message
 
         final PushbackInputStream pushbackInputStream = new PushbackInputStream(entityStream);
 
-        int firstByte = pushbackInputStream.read();
+        final int firstByte = pushbackInputStream.read();
         if (firstByte == -1) {
             return emptyBody(path);
         } else {
@@ -80,7 +79,7 @@ public abstract class AbstractIdentifierAwareJaxRsProvider<T> implements Message
     private InstanceIdentifierContext<?> getInstanceIdentifierContext() {
         return ParserIdentifier.toInstanceIdentifier(
                 getIdentifier(),
-                ControllerContext.getInstance().getGlobalSchema(),
+                RestConnectorProvider.getActualSchemaContext(),
                 Optional.of(RestConnectorProvider.getMountPointService()));
     }
 
index a10271335b30fd33a6b4c7ea731cc8b8fd857b1c..700a0206fea0a311f92c98f6fcc2b769027ad3a7 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
 import org.opendaylight.netconf.sal.restconf.impl.PatchStatusContext;
 import org.opendaylight.restconf.Rfc8040;
+import org.opendaylight.restconf.base.services.api.UpdateHandlers;
 import org.opendaylight.restconf.utils.RestconfConstants;
 
 /**
@@ -32,7 +33,7 @@ import org.opendaylight.restconf.utils.RestconfConstants;
  * is a collection of configuration data and state data nodes.
  *
  */
-public interface RestconfDataService {
+public interface RestconfDataService extends UpdateHandlers {
 
     /**
      * Get target data resource.
index 7405e1decd3e596f7a988dcd1764cd1a993413c7..d469b32fc61d0ff373d2a050323dd01bb903a3a2 100644 (file)
@@ -18,6 +18,7 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.restconf.Rfc8040;
+import org.opendaylight.restconf.base.services.api.UpdateHandlers;
 import org.opendaylight.restconf.utils.RestconfConstants;
 
 /**
@@ -25,7 +26,7 @@ import org.opendaylight.restconf.utils.RestconfConstants;
  * "rpc" statement. It is invoked using a POST method on the operation resource.
  *
  */
-public interface RestconfInvokeOperationsService {
+public interface RestconfInvokeOperationsService extends UpdateHandlers {
 
     /**
      * Invoke RPC operation.
index fd2e9d33cc3f8473967dccfdff40043fda6a04e9..6e171877bf9edc029f6569b26ccd9c3554bb8e0f 100644 (file)
@@ -14,12 +14,13 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.restconf.base.services.api.UpdateHandlers;
 
 /**
  * Subscribing to streams.
  *
  */
-public interface RestconfStreamsSubscriptionService {
+public interface RestconfStreamsSubscriptionService extends UpdateHandlers {
 
     /**
      * Subscribing to receive notification from stream support.
index 84fd6c16c227991b3d3e55f8fc379ae1f0bb5878..ffec58a5ae4986a110aaa74cc3d0deba6187de93 100644 (file)
@@ -61,9 +61,9 @@ public class RestconfDataServiceImpl implements RestconfDataService {
     private static final Logger LOG = LoggerFactory.getLogger(RestconfDataServiceImpl.class);
     private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm:ss");
 
-    private final SchemaContextHandler schemaContextHandler;
-    private final TransactionChainHandler transactionChainHandler;
-    private final DOMMountPointServiceHandler mountPointServiceHandler;
+    private SchemaContextHandler schemaContextHandler;
+    private TransactionChainHandler transactionChainHandler;
+    private DOMMountPointServiceHandler mountPointServiceHandler;
 
     private final RestconfStreamsSubscriptionService delegRestconfSubscrService;
 
@@ -77,6 +77,19 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         this.delegRestconfSubscrService = delegRestconfSubscrService;
     }
 
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof SchemaContextHandler) {
+                schemaContextHandler = (SchemaContextHandler) object;
+            } else if (object instanceof DOMMountPointServiceHandler) {
+                mountPointServiceHandler = (DOMMountPointServiceHandler) object;
+            } else if (object instanceof TransactionChainHandler) {
+                transactionChainHandler = (TransactionChainHandler) object;
+            }
+        }
+    }
+
     @Override
     public Response readData(final UriInfo uriInfo) {
         return readData(null, uriInfo);
index c9c8fe1aa87f031dfb5d99bfff84c3d0102e6f00..70f817bbd9b4cbfa7a0f8d13551546bfa5e223f9 100644 (file)
@@ -33,8 +33,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
  */
 public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperationsService {
 
-    private final RpcServiceHandler rpcServiceHandler;
-    private final SchemaContextHandler schemaContextHandler;
+    private RpcServiceHandler rpcServiceHandler;
+    private SchemaContextHandler schemaContextHandler;
 
     public RestconfInvokeOperationsServiceImpl(final RpcServiceHandler rpcServiceHandler,
             final SchemaContextHandler schemaContextHandler) {
@@ -42,6 +42,17 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat
         this.schemaContextHandler = schemaContextHandler;
     }
 
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof SchemaContextHandler) {
+                schemaContextHandler = (SchemaContextHandler) object;
+            } else if (object instanceof RpcServiceHandler) {
+                rpcServiceHandler = (RpcServiceHandler) object;
+            }
+        }
+    }
+
     @Override
     public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
                                            final UriInfo uriInfo) {
index 36873a18932fed25518f78b4ed29fb3b15569cde..2d677305e3319baf0f9ae52822c66c902e76cd3b 100644 (file)
@@ -46,7 +46,7 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
 
     private static final Logger LOG = LoggerFactory.getLogger(RestconfStreamsSubscriptionServiceImpl.class);
 
-    private final HandlersHolder handlersHolder;
+    private HandlersHolder handlersHolder;
 
     /**
      * Initialize holder of handlers with holders as parameters.
@@ -67,6 +67,15 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
                 transactionChainHandler, schemaHandler);
     }
 
+    @Override
+    public synchronized void updateHandlers(final Object... handlers) {
+        for (final Object object : handlers) {
+            if (object instanceof HandlersHolder) {
+                handlersHolder = (HandlersHolder) object;
+            }
+        }
+    }
+
     @Override
     public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
         final NotificationQueryParams notificationQueryParams = NotificationQueryParams.fromUriInfo(uriInfo);
index 7b5155f14718b7f095dc2f83edec78eac258c176..87201bacd6b2a93398c143b48a7c4c3f087508ff 100644 (file)
@@ -261,7 +261,7 @@ public final class SubscribeToStreamUtil {
         final TemporalAccessor p;
         try {
             p = FORMATTER.parse(value);
-        } catch (DateTimeParseException e) {
+        } catch (final DateTimeParseException e) {
             throw new RestconfDocumentedException("Cannot parse of value in date: " + value, e);
         }
         return Instant.from(p);
@@ -309,13 +309,11 @@ public final class SubscribeToStreamUtil {
     }
 
     static URI prepareUriByStreamName(final UriInfo uriInfo, final String streamName) {
-        final int port = SubscribeToStreamUtil.prepareNotificationPort();
+        final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
 
-        final UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
-        final UriBuilder uriToWebSocketServer =
-                uriBuilder.port(port).scheme(RestconfStreamsConstants.SCHEMA_SUBSCIBRE_URI);
-        final URI uri = uriToWebSocketServer.replacePath(streamName).build();
-        return uri;
+        prepareNotificationPort(uriInfo.getBaseUri().getPort());
+        uriBuilder.scheme(RestconfStreamsConstants.SCHEMA_SUBSCIBRE_URI);
+        return uriBuilder.replacePath(streamName).build();
     }
 
     /**
@@ -339,12 +337,12 @@ public final class SubscribeToStreamUtil {
         }
 
         final YangInstanceIdentifier path = listener.getPath();
-        DOMDataTreeChangeService changeService = (DOMDataTreeChangeService)
+        final DOMDataTreeChangeService changeService = (DOMDataTreeChangeService)
                         domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
         if (changeService == null) {
             throw new UnsupportedOperationException("DOMDataTreeChangeService not supported by DOMDataBroker");
         }
-        DOMDataTreeIdentifier loc = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, path);
+        final DOMDataTreeIdentifier loc = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, path);
         listener.setRegistration(changeService.registerDataTreeChangeListener(loc, listener));
 
     }
@@ -354,9 +352,9 @@ public final class SubscribeToStreamUtil {
      *
      * @return port
      */
-    private static int prepareNotificationPort() {
+    private static int prepareNotificationPort(final int port) {
         final WebSocketServer webSocketServer =
-                WebSocketServer.getInstance(RestconfStreamsConstants.NOTIFICATION_PORT);
+                WebSocketServer.getInstance(port);
         return webSocketServer.getPort();
     }
 
index 59e5a009442285aa9b78d85811752657863056f4..da107ec39dd9efa6dc3401342934a87357d68dd2 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Iterator;
 import java.util.List;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
@@ -192,27 +193,29 @@ public final class ParserIdentifier {
     }
 
     /**
-     * Parsing {@link Module} module by {@link String} module name and
-     * {@link Date} revision and from the parsed module create
-     * {@link SchemaExportContext}.
+     * Parsing {@link Module} module by {@link String} module name and {@link Date} revision and from the parsed module
+     * create {@link SchemaExportContext}.
      *
      * @param schemaContext
-     *             {@link SchemaContext}
+     *            {@link SchemaContext}
      * @param identifier
-     *             path parameter
+     *            path parameter
      * @param domMountPointService
-     *             {@link DOMMountPointService}
+     *            {@link DOMMountPointService}
+     * @param sourceProvider
+     *            - source provider
      * @return {@link SchemaExportContext}
      */
     public static SchemaExportContext toSchemaExportContextFromIdentifier(final SchemaContext schemaContext,
-            final String identifier, final DOMMountPointService domMountPointService) {
+            final String identifier, final DOMMountPointService domMountPointService,
+            final DOMYangTextSourceProvider sourceProvider) {
         final Iterable<String> pathComponents = RestconfConstants.SLASH_SPLITTER.split(identifier);
         final Iterator<String> componentIter = pathComponents.iterator();
         if (!Iterables.contains(pathComponents, RestconfConstants.MOUNT)) {
             final String moduleName = RestconfValidation.validateAndGetModulName(componentIter);
             final Date revision = RestconfValidation.validateAndGetRevision(componentIter);
             final Module module = schemaContext.findModuleByName(moduleName, revision);
-            return new SchemaExportContext(schemaContext, module);
+            return new SchemaExportContext(schemaContext, module, sourceProvider);
         } else {
             final StringBuilder pathBuilder = new StringBuilder();
             while (componentIter.hasNext()) {
@@ -235,7 +238,7 @@ public final class ParserIdentifier {
             final String moduleName = RestconfValidation.validateAndGetModulName(componentIter);
             final Date revision = RestconfValidation.validateAndGetRevision(componentIter);
             final Module module = point.getMountPoint().getSchemaContext().findModuleByName(moduleName, revision);
-            return new SchemaExportContext(point.getMountPoint().getSchemaContext(), module);
+            return new SchemaExportContext(point.getMountPoint().getSchemaContext(), module, sourceProvider);
         }
     }
 }
index bd54466e52cf5d67ac8d194eae5f47210c6415e9..80ef78aa6724f3d54fe4745cb13feaacfff08bb2 100644 (file)
   <!-- We need the AAAService available even though we don't use it -->
   <reference interface="org.opendaylight.aaa.api.AAAService"/>
 
-  <reference id="schemaService" interface="org.opendaylight.controller.sal.core.api.model.SchemaService"/>
   <reference id="domRpcService" interface="org.opendaylight.controller.md.sal.dom.api.DOMRpcService"/>
   <reference id="domMountPointService" interface="org.opendaylight.controller.md.sal.dom.api.DOMMountPointService"/>
   <reference id="domNotificationService" interface="org.opendaylight.controller.md.sal.dom.api.DOMNotificationService"/>
   <reference id="domDataBroker" interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
           ext:filter="(type=@{databroker-service-type})"/>
+  <reference id="domSchemaService" interface="org.opendaylight.mdsal.dom.api.DOMSchemaService"/>
 
   <bean id="webSocketPort" class="org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber">
     <argument value="${websocket-port}"/>
@@ -55,7 +55,7 @@
   <bean id="restconfProviderDraft02" class="org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl"
           init-method="start" destroy-method="close">
     <argument ref="domDataBroker"/>
-    <argument ref="schemaService"/>
+    <argument ref="domSchemaService"/>
     <argument ref="domRpcService"/>
     <argument ref="domNotificationService"/>
     <argument ref="domMountPointService"/>
@@ -66,7 +66,7 @@
   <bean id="restconfProviderDraft18" class="org.opendaylight.restconf.RestConnectorProvider"
           init-method="start" destroy-method="close">
     <argument ref="domDataBroker"/>
-    <argument ref="schemaService"/>
+    <argument ref="domSchemaService"/>
     <argument ref="domRpcService"/>
     <argument ref="domNotificationService"/>
     <argument ref="domMountPointService"/>
index 04e23de1b6e45eeedfbed943f892530dd5673481..1c464c613635112b85d9bb1e916d938cddc271d5 100644 (file)
@@ -50,6 +50,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.netconf.sal.restconf.impl.JSONRestconfServiceDraft18;
 import org.opendaylight.restconf.common.wrapper.services.ServicesWrapperImpl;
@@ -130,6 +131,9 @@ public class JSONRestconfServiceDraft18Test {
     @Mock
     private SchemaContextHandler mockSchemaContextHandler;
 
+    @Mock
+    private DOMSchemaService domSchemaService;
+
     @Mock
     private DOMDataBroker mockDOMDataBroker;
 
@@ -174,7 +178,7 @@ public class JSONRestconfServiceDraft18Test {
 
         doReturn(schemaContext).when(mockSchemaContextHandler).get();
 
-        TransactionChainHandler txChainHandler = new TransactionChainHandler(mockTxChain);
+        final TransactionChainHandler txChainHandler = new TransactionChainHandler(mockTxChain);
 
         final DOMMountPointServiceHandler mountPointServiceHandler =
                 new DOMMountPointServiceHandler(mockMountPointService);
@@ -182,7 +186,7 @@ public class JSONRestconfServiceDraft18Test {
         ServicesWrapperImpl.getInstance().setHandlers(mockSchemaContextHandler, mountPointServiceHandler,
                 txChainHandler, new DOMDataBrokerHandler(mockDOMDataBroker),
                 new RpcServiceHandler(mockRpcService),
-                new NotificationServiceHandler(mock(DOMNotificationService.class)));
+                new NotificationServiceHandler(mock(DOMNotificationService.class)), domSchemaService);
 
         service = new JSONRestconfServiceDraft18(ServicesWrapperImpl.getInstance(), mountPointServiceHandler);
     }
index 5c3222a30308a95decc239b7355645656f3fd22b..77c556cdafb78205e3812ab95b8999f7060dfd63 100644 (file)
@@ -27,6 +27,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.dom.broker.impl.mount.DOMMountPointServiceImpl;
 import org.opendaylight.controller.md.sal.dom.broker.spi.mount.SimpleDOMMountPoint;
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
@@ -63,6 +64,8 @@ public class RestconfSchemaServiceTest {
     private SchemaContextHandler mockContextHandler;
     @Mock
     private DOMMountPointServiceHandler mockMountPointHandler;
+    @Mock
+    private DOMYangTextSourceProvider sourceProvider;
 
     // schema context with modules
     private SchemaContext schemaContext;
@@ -106,7 +109,8 @@ public class RestconfSchemaServiceTest {
         ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPointWithNullSchemaContext);
         when(this.mockMountPointHandler.get()).thenReturn(this.mountPointService);
 
-        this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler, this.mockMountPointHandler);
+        this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler, this.mockMountPointHandler,
+                this.sourceProvider);
     }
 
     /**
index d0d2ceba011ff916c621b20266c990ab1f7e4afe..e7c32d82f6cd7d8ef087a98065f4ee913116fa6c 100644 (file)
@@ -21,7 +21,6 @@ import javax.ws.rs.core.Request;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.rest.api.RestconfConstants;
-import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
 import org.opendaylight.restconf.RestConnectorProvider;
@@ -30,7 +29,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 abstract class AbstractBodyReaderTest {
 
-    protected static final ControllerContext CONTROLLER_CONTEXT = ControllerContext.getInstance();
     protected static final DOMMountPointServiceHandler MOUNT_POINT_SERVICE_HANDLER =
             mock(DOMMountPointServiceHandler.class);
 
index 9aa4407b2884bcac79c877e99c1977697b645b51..6998c40ba6f6ae59bd17ca3262a79d58b78fb7e6 100644 (file)
@@ -27,6 +27,8 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.controller.sal.rest.impl.test.providers.TestXmlBodyReader;
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
@@ -72,7 +74,10 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest {
         final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
         testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
         schemaContext = YangParserTestUtils.parseYangSources(testFiles);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+        when(schemaContextHandler.get()).thenReturn(schemaContext);
+        RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
+        when(RestConnectorProvider.getActualSchemaContext()).thenReturn(schemaContext);
         when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
     }
 
index bb5baf87e36b15a2c98e28bc88393e8e73984744..47bf84c4a9b674a3eb6a427b40854194d77b447d 100644 (file)
@@ -25,6 +25,8 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.sal.rest.impl.test.providers.TestJsonBodyReader;
 import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
@@ -55,7 +57,9 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
         when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
 
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+        when(schemaContextHandler.get()).thenReturn(schemaContext);
+        RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
     }
 
     @Test
index a866313229d7ace2b504a3143311f921b7b5907e..669b17695a35ff85957a5b85211a3ac5e69fe242 100644 (file)
@@ -22,6 +22,8 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.sal.rest.impl.test.providers.TestJsonBodyReader;
 import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
@@ -43,7 +45,9 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
     public static void initialization() {
         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
         when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+        when(schemaContextHandler.get()).thenReturn(schemaContext);
+        RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
     }
 
     @Test
index e4e687b37d27231703665e5a691a9ad08873af38..a6a3473881ae03e428d501822b1ee1614f916539 100644 (file)
@@ -32,6 +32,8 @@ import org.opendaylight.controller.sal.rest.impl.test.providers.TestXmlBodyReade
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
@@ -83,7 +85,9 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
         when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
         when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
 
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+        when(schemaContextHandler.get()).thenReturn(schemaContext);
+        RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
     }
 
     @Test
index 0f9c4dca0ee9ebad258e54a0a8a2c2916df0663d..0101b379659333706114097f8ad417248ada7829 100644 (file)
@@ -31,6 +31,8 @@ import org.opendaylight.controller.sal.rest.impl.test.providers.TestXmlBodyReade
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
@@ -76,7 +78,9 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
         testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
         testFiles.addAll(TestRestconfUtils.loadFiles("/foo-xml-test/yang"));
         schemaContext = YangParserTestUtils.parseYangSources(testFiles);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+        when(schemaContextHandler.get()).thenReturn(schemaContext);
+        RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
         when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
     }
 
index 4a229d392f849387964691445720332baa2d818f..6359fb47326dc82a789c8a21c6e118470ff1c466 100644 (file)
@@ -24,6 +24,8 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.sal.rest.impl.test.providers.TestXmlBodyReader;
 import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
@@ -54,7 +56,9 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
         when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
         when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
 
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+        when(schemaContextHandler.get()).thenReturn(schemaContext);
+        RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
     }
 
     @Test
index c382f3badbc269248dd860f53b690a09011a97ad..49ce7f384f1f5f2ea9b3b44713039036eed8d5dd 100644 (file)
@@ -21,6 +21,8 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.sal.rest.impl.test.providers.TestXmlBodyReader;
 import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
@@ -42,7 +44,9 @@ public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
     public static void initialization() {
         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
         when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        final SchemaContextHandler schemaContextHandler = mock(SchemaContextHandler.class);
+        when(schemaContextHandler.get()).thenReturn(schemaContext);
+        RestConnectorProvider.setSchemaContextHandler(schemaContextHandler);
     }
 
     @Test
index 7c0ad9a01f035712d2a3200e1038143c1289736d..d85cc5f141b2d6b07d9b6c1b89c62668611fa9fd 100644 (file)
@@ -16,6 +16,7 @@ import static org.mockito.Mockito.mock;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import java.lang.reflect.Field;
+import java.net.URI;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -44,6 +45,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.netconf.sal.restconf.impl.SimpleUriInfo;
 import org.opendaylight.netconf.sal.streams.listeners.ListenerAdapter;
 import org.opendaylight.netconf.sal.streams.listeners.Notificator;
 import org.opendaylight.restconf.handlers.DOMDataBrokerHandler;
@@ -98,20 +100,35 @@ public class RestconfStreamsSubscriptionServiceImplTest {
         final ListenerRegistration<DOMDataChangeListener> listener = mock(ListenerRegistration.class);
         doReturn(dataBroker).when(this.dataBrokerHandler).get();
         doReturn(listener).when(dataBroker).registerDataChangeListener(any(), any(), any(), any());
-        DOMDataTreeChangeService changeService = Mockito.mock(DOMDataTreeChangeService.class);
+        final DOMDataTreeChangeService changeService = Mockito.mock(DOMDataTreeChangeService.class);
         Mockito.when(changeService.registerDataTreeChangeListener(any(), any()))
                                                             .thenReturn(Mockito.mock(ListenerRegistration.class));
-        HashMap extensions = new HashMap();
+        final HashMap extensions = new HashMap();
         extensions.put(DOMDataTreeChangeService.class, Mockito.mock(DOMDataTreeChangeService.class));
         Mockito.when(dataBroker.getSupportedExtensions()).thenReturn(extensions);
         final MultivaluedMap<String, String> map = Mockito.mock(MultivaluedMap.class);
         final Set<Entry<String, List<String>>> set = new HashSet<>();
         Mockito.when(map.entrySet()).thenReturn(set);
         Mockito.when(this.uriInfo.getQueryParameters()).thenReturn(map);
+        final UriBuilder baseUriBuilder = new LocalUriInfo().getBaseUriBuilder();
+        Mockito.when(uriInfo.getBaseUri()).thenReturn(baseUriBuilder.build());
+        Mockito.when(uriInfo.getBaseUriBuilder()).thenReturn(baseUriBuilder);
         this.schemaHandler.onGlobalContextUpdated(
                 YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/notifications")));
     }
 
+    private static class LocalUriInfo extends SimpleUriInfo {
+
+        LocalUriInfo() {
+            super("/");
+        }
+
+        @Override
+        public URI getBaseUri() {
+            return UriBuilder.fromUri("http://localhost:8181").build();
+        }
+    }
+
     @BeforeClass
     public static void setUpBeforeTest() throws Exception {
         final Map<String, ListenerAdapter> listenersByStreamNameSetter = new HashMap<>();
@@ -148,7 +165,8 @@ public class RestconfStreamsSubscriptionServiceImplTest {
                         "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                         this.uriInfo);
         assertEquals(
-            "ws://:8181/data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
+                "ws://localhost:8181/data-change-event-subscription/toaster:toaster/toasterStatus/"
+                        + "datastore=OPERATIONAL/scope=ONE",
             response.getNewHeaders().get("Location").toString());
     }
 
index 7ea8eea56b38e526837ee184e473187310e01b3f..011622e5d39e7aa49c05439a20ec22c26c788ed4 100644 (file)
@@ -28,6 +28,8 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.dom.broker.impl.mount.DOMMountPointServiceImpl;
 import org.opendaylight.controller.md.sal.dom.broker.spi.mount.SimpleDOMMountPoint;
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
@@ -98,6 +100,10 @@ public class ParserIdentifierTest {
     private DOMMountPoint mockMountPoint;
     @Mock
     private DOMMountPointService mockMountPointService;
+    @Mock
+    private DOMSchemaService domSchemaService;
+    @Mock
+    private DOMYangTextSourceProvider sourceProvider;
 
     @Rule
     public final ExpectedException thrown = ExpectedException.none();
@@ -462,7 +468,7 @@ public class ParserIdentifierTest {
     @Test
     public void toSchemaExportContextFromIdentifierTest() {
         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
-                this.schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null);
+                this.schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null, sourceProvider);
 
         assertNotNull("Export context should be parsed", exportContext);
 
@@ -486,7 +492,7 @@ public class ParserIdentifierTest {
         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
                 this.schemaContext,
                 "not-existing-module" + "/" + "2016-01-01",
-                null);
+                null, sourceProvider);
 
         assertNotNull("Export context should be parsed", exportContext);
         assertNull("Not-existing module should be null", exportContext.getModule());
@@ -501,7 +507,7 @@ public class ParserIdentifierTest {
     public void toSchemaExportContextFromIdentifierInvalidIdentifierNegativeTest() {
         try {
             ParserIdentifier.toSchemaExportContextFromIdentifier(
-                    this.schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null);
+                    this.schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null, sourceProvider);
             fail("Test should fail due to invalid identifier supplied");
         } catch (final RestconfDocumentedException e) {
             assertEquals("Not expected error type",
@@ -522,7 +528,7 @@ public class ParserIdentifierTest {
         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
                 this.schemaContext,
                 MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
-                this.mountPointService);
+                this.mountPointService, sourceProvider);
 
         final Module module = exportContext.getModule();
         assertNotNull("Export context should contains test module", module);
@@ -544,7 +550,7 @@ public class ParserIdentifierTest {
         final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
                 this.schemaContext,
                 MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01",
-                this.mountPointService);
+                this.mountPointService, sourceProvider);
 
         assertNotNull("Export context should be parsed", exportContext);
         assertNull("Not-existing module should be null", exportContext.getModule());
@@ -561,7 +567,7 @@ public class ParserIdentifierTest {
             ParserIdentifier.toSchemaExportContextFromIdentifier(
                     this.schemaContext,
                     MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME,
-                    this.mountPointService);
+                    this.mountPointService, sourceProvider);
 
             fail("Test should fail due to invalid identifier supplied");
         } catch (final RestconfDocumentedException e) {
@@ -581,7 +587,7 @@ public class ParserIdentifierTest {
     @Test
     public void toSchemaExportContextFromIdentifierNullIdentifierNegativeTest() {
         this.thrown.expect(NullPointerException.class);
-        ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null);
+        ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null, sourceProvider);
     }
 
     /**
@@ -591,7 +597,8 @@ public class ParserIdentifierTest {
     @Test
     public void toSchemaExportContextFromIdentifierNullSchemaContextNegativeTest() {
         this.thrown.expect(NullPointerException.class);
-        ParserIdentifier.toSchemaExportContextFromIdentifier(null, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null);
+        ParserIdentifier.toSchemaExportContextFromIdentifier(null, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null,
+                sourceProvider);
     }
 
     /**
@@ -609,7 +616,7 @@ public class ParserIdentifierTest {
                 + TEST_MODULE_NAME
                 + "/"
                 + TEST_MODULE_REVISION,
-                this.mountPointService);
+                this.mountPointService, sourceProvider);
     }
 
     /**
@@ -627,7 +634,7 @@ public class ParserIdentifierTest {
                 + TEST_MODULE_NAME
                 + "/"
                 + TEST_MODULE_REVISION,
-                null);
+                null, sourceProvider);
     }
 
     /**
@@ -645,7 +652,7 @@ public class ParserIdentifierTest {
                 + TEST_MODULE_NAME
                 + "/"
                 + TEST_MODULE_REVISION,
-                this.mockMountPointService);
+                this.mockMountPointService, sourceProvider);
     }
 
     /**