Remove "/" sign in AbstractRestconfStreamRegistry 72/111272/5
authorYaroslav Lastivka <yaroslav.lastivka@pantheon.tech>
Fri, 5 Apr 2024 06:31:28 +0000 (09:31 +0300)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 16 Apr 2024 08:46:32 +0000 (10:46 +0200)
In AbstractRestconfStreamRegistry#baseStreamLocation, the method generated
incorrect paths containing a double slash after `rests` in the device
notification stream URL. This error occurred because URI.getPath()
always includes a trailing slash. Additionally, the UriInfo.getBaseUri()
method, used within JaxRsRestconf, also consistently appends a slash
at the end.

Document this fact in RestconfServer and do not append it in
AbstractRestconfStreamRegistry.

JIRA: NETCONF-1274
Change-Id: Ib5074dc150d27a8482c7e49f89549973ab707270
Signed-off-by: Yaroslav Lastivka <yaroslav.lastivka@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/RestconfServer.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/AbstractRestconfStreamRegistry.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateNotificationStreamRpcTest.java

index 0385dd611c2a51a45036394e65a7a6143e510e32..1d3f3a4115d151eb1694266424ef93c595a5ad2f 100644 (file)
@@ -150,7 +150,8 @@ public interface RestconfServer {
      * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-3.6">RFC8040 Operation Resource</a>.
      *
      * @param request {@link ServerRequest} for this request
-     * @param restconfURI Base URI of the request
+     * @param restconfURI Base URI of the request, the absolute equivalent to {@code {+restconf}} URI with a trailing
+     *                    slash
      * @param operation {@code <operation>} path, really an {@link ApiPath} to an {@code rpc}
      * @param body RPC operation
      * @return A {@link RestconfFuture} completing with {@link InvokeResult}
index 71b0f40386fb3c37f6d8e32bd88135d278ed75d4..2f2e44559478261f5ab3d092c98a648fe93463d9 100644 (file)
@@ -143,7 +143,7 @@ public abstract class AbstractRestconfStreamRegistry implements RestconfStream.R
     /**
      * Return the base location URL of the streams service based on request URI.
      *
-     * @param restconfURI request base URI
+     * @param restconfURI request base URI, with trailing slash
      * @throws IllegalArgumentException if the result would have been malformed
      */
     protected final @NonNull String baseStreamLocation(final URI restconfURI) {
@@ -159,7 +159,7 @@ public abstract class AbstractRestconfStreamRegistry implements RestconfStream.R
 
         try {
             return new URI(scheme, restconfURI.getRawUserInfo(), restconfURI.getHost(), restconfURI.getPort(),
-                restconfURI.getPath() + '/' + URLConstants.STREAMS_SUBPATH, null, null)
+                restconfURI.getPath() + URLConstants.STREAMS_SUBPATH, null, null)
                 .toString();
         } catch (URISyntaxException e) {
             throw new IllegalArgumentException("Cannot derive streams location", e);
index 37e6cc43c6dfd7f720abc88d1961b36b0adb3bf9..95784dfe39130503295473998751a2118c322f43 100644 (file)
@@ -62,7 +62,7 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 @ExtendWith(MockitoExtension.class)
 class CreateNotificationStreamRpcTest {
     private static final EffectiveModelContext SCHEMA_CTX = YangParserTestUtils.parseYangResourceDirectory("/streams");
-    private static final URI RESTCONF_URI = URI.create("/rests");
+    private static final URI RESTCONF_URI = URI.create("/rests/");
     private static final YangInstanceIdentifier TOASTER = YangInstanceIdentifier.of(
         QName.create("http://netconfcentral.org/ns/toaster", "2009-11-20", "toaster"));