Make stream subpath flexible 14/112614/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 17 Jul 2024 20:26:33 +0000 (22:26 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 17 Jul 2024 20:37:03 +0000 (22:37 +0200)
AbstractRestconfStreamRegistry has no opinions on location, except it
needs to be non-null. Push the knowledge out of server.spi.

JIRA: NETCONF-773
Change-Id: I40597fd04e818df529ee95e52ea8b01156498d58
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/MdsalRestconfStreamRegistry.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/AbstractRestconfStreamRegistry.java

index 5e5e57697d4e9354d23ef85b770b87f2bce4716b..38ffe3369462a4d946fd05064c7fa6930645ef60 100644 (file)
@@ -14,6 +14,7 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.restconf.nb.rfc8040.URLConstants;
 import org.opendaylight.restconf.server.spi.AbstractRestconfStreamRegistry;
 import org.opendaylight.restconf.server.spi.RestconfStream;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.RestconfState;
@@ -43,6 +44,7 @@ public final class MdsalRestconfStreamRegistry extends AbstractRestconfStreamReg
     @Inject
     @Activate
     public MdsalRestconfStreamRegistry(@Reference final DOMDataBroker dataBroker) {
+        super(URLConstants.STREAMS_SUBPATH);
         this.dataBroker = requireNonNull(dataBroker);
     }
 
index 0bdcc41dd8f6c3083ba7b59fedcb758575b9ab20..f965a8665c40498feb597b41514097cf03e96bb5 100644 (file)
@@ -22,7 +22,6 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.restconf.nb.rfc8040.URLConstants;
 import org.opendaylight.restconf.server.api.ServerException;
 import org.opendaylight.restconf.server.api.ServerRequest;
 import org.opendaylight.restconf.server.spi.RestconfStream.EncodingName;
@@ -53,6 +52,14 @@ public abstract class AbstractRestconfStreamRegistry implements RestconfStream.R
     public static final QName LOCATION_QNAME =  QName.create(Stream.QNAME, "location").intern();
 
     private final ConcurrentMap<String, RestconfStream<?>> streams = new ConcurrentHashMap<>();
+    private final @NonNull String subpath;
+
+    protected AbstractRestconfStreamRegistry(final String subpath) {
+        if (subpath.isEmpty()) {
+            throw new IllegalArgumentException("empty subpath");
+        }
+        this.subpath = subpath;
+    }
 
     @Override
     public final @Nullable RestconfStream<?> lookupStream(final String name) {
@@ -138,12 +145,12 @@ public abstract class AbstractRestconfStreamRegistry implements RestconfStream.R
      * @param restconfURI request base URI, with trailing slash
      * @throws IllegalArgumentException if the result would have been malformed
      */
-    protected static final @NonNull String baseStreamLocation(final URI restconfURI) {
+    protected final @NonNull String baseStreamLocation(final URI restconfURI) {
         var scheme = restconfURI.getScheme();
 
         try {
             return new URI(scheme, restconfURI.getRawUserInfo(), restconfURI.getHost(), restconfURI.getPort(),
-                restconfURI.getPath() + URLConstants.STREAMS_SUBPATH, null, null)
+                restconfURI.getPath() + subpath, null, null)
                 .toString();
         } catch (URISyntaxException e) {
             throw new IllegalArgumentException("Cannot derive streams location", e);