From f0aae2485a06c1819798434376d307fed60e145a Mon Sep 17 00:00:00 2001 From: Yaroslav Lastivka Date: Fri, 5 Apr 2024 09:31:28 +0300 Subject: [PATCH] Remove "/" sign in AbstractRestconfStreamRegistry 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 Signed-off-by: Robert Varga --- .../org/opendaylight/restconf/server/api/RestconfServer.java | 3 ++- .../restconf/server/spi/AbstractRestconfStreamRegistry.java | 4 ++-- .../mdsal/streams/dtcl/CreateNotificationStreamRpcTest.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/RestconfServer.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/RestconfServer.java index 0385dd611c..1d3f3a4115 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/RestconfServer.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/RestconfServer.java @@ -150,7 +150,8 @@ public interface RestconfServer { * RFC8040 Operation Resource. * * @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 } path, really an {@link ApiPath} to an {@code rpc} * @param body RPC operation * @return A {@link RestconfFuture} completing with {@link InvokeResult} diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/AbstractRestconfStreamRegistry.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/AbstractRestconfStreamRegistry.java index 71b0f40386..2f2e445594 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/AbstractRestconfStreamRegistry.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/AbstractRestconfStreamRegistry.java @@ -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); diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateNotificationStreamRpcTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateNotificationStreamRpcTest.java index 37e6cc43c6..95784dfe39 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateNotificationStreamRpcTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/server/mdsal/streams/dtcl/CreateNotificationStreamRpcTest.java @@ -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")); -- 2.36.6