Rename and move RestconfConstants 19/107119/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 27 Jul 2023 14:06:13 +0000 (16:06 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 27 Jul 2023 14:32:46 +0000 (16:32 +0200)
Document RestconfConstants and move them to the base package. The new
name is URLConstants.

Change-Id: If3698e2e89c21e79c08a8920b4b911134e80329b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/JaxRsNorthbound.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/URLConstants.java [new file with mode: 0644]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenersBroker.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/RestconfConstants.java [deleted file]
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java

index f5a10462ab31b91b84a643f92fdd493fedfa3053..6f5e2fead8fc53d21685eede4295661e86253fdf 100644 (file)
@@ -7,10 +7,10 @@
  */
 package org.opendaylight.restconf.nb.rfc8040;
 
+import static org.opendaylight.restconf.nb.rfc8040.URLConstants.BASE_PATH;
+import static org.opendaylight.restconf.nb.rfc8040.URLConstants.SSE_SUBPATH;
 import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.DATA_SUBSCRIPTION;
 import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.NOTIFICATION_STREAM;
-import static org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants.BASE_URI_PATTERN;
-import static org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants.NOTIF;
 
 import com.google.common.annotations.Beta;
 import javax.servlet.ServletException;
@@ -100,17 +100,17 @@ public final class JaxRsNorthbound implements AutoCloseable {
 
         final var restconfBuilder = WebContext.builder()
             .name("RFC8040 RESTCONF")
-            .contextPath("/" + BASE_URI_PATTERN)
+            .contextPath("/" + BASE_PATH)
             .supportsSessions(false)
             .addServlet(ServletDetails.builder()
                 .addUrlPattern("/*")
                 .servlet(servletSupport.createHttpServletBuilder(
                     new RestconfApplication(databindProvider, mountPointService, dataBroker, rpcService, actionService,
-                        notificationService,schemaService, streamsConfiguration)).build())
+                        notificationService, schemaService, streamsConfiguration)).build())
                 .asyncSupported(true)
                 .build())
             .addServlet(ServletDetails.builder()
-                .addUrlPattern("/" + NOTIF + "/*")
+                .addUrlPattern("/" + SSE_SUBPATH + "/*")
                 .servlet(servletSupport.createHttpServletBuilder(
                     new DataStreamApplication(databindProvider, mountPointService,
                         new RestconfDataStreamServiceImpl(scheduledThreadPool, streamsConfiguration))).build())
@@ -140,7 +140,7 @@ public final class JaxRsNorthbound implements AutoCloseable {
             .supportsSessions(false)
             .addServlet(ServletDetails.builder()
                 .addUrlPattern("/*")
-                .servlet(servletSupport.createHttpServletBuilder(new RootFoundApplication(BASE_URI_PATTERN)).build())
+                .servlet(servletSupport.createHttpServletBuilder(new RootFoundApplication(BASE_PATH)).build())
                 .name("Rootfound")
                 .build());
 
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/URLConstants.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/URLConstants.java
new file mode 100644 (file)
index 0000000..e7fca64
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.nb.rfc8040;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * Various constants related to the layout of URLs on which the implementation resides.
+ */
+@NonNullByDefault
+public final class URLConstants {
+    /**
+     * The first element URL path element for RESTCONF implementation, i.e. {@code https://localhost/BASE_PATH}.
+     */
+    public static final String BASE_PATH = "rests";
+    /**
+     * The second element for Server Sent Events support, i.e. {@code https://localhost/BASE_PATH/NOTIF}.
+     */
+    public static final String SSE_SUBPATH = "notif";
+
+    private URLConstants() {
+        // Hidden on purpose
+    }
+}
\ No newline at end of file
index 3c2de9aa41e62b7436ed700807d75614aede6edd..8b98bc4786b093951ecf7c968b3d5fcbbd3955fc 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteOperations;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams;
+import org.opendaylight.restconf.nb.rfc8040.URLConstants;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.monitoring.RestconfStateStreams;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfStreamsSubscriptionServiceImpl.HandlersHolder;
@@ -30,7 +31,6 @@ import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenerAdapter;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenersBroker;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.NotificationListenerAdapter;
-import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
@@ -51,9 +51,9 @@ abstract class SubscribeToStreamUtil {
 
         @Override
         public URI prepareUriByStreamName(final UriInfo uriInfo, final String streamName) {
-            final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
-            return uriBuilder.replacePath(RestconfConstants.BASE_URI_PATTERN + '/'
-                    + RestconfConstants.NOTIF + '/' + streamName).build();
+            return uriInfo.getBaseUriBuilder()
+                .replacePath(URLConstants.BASE_PATH + '/' + URLConstants.SSE_SUBPATH + '/' + streamName)
+                .build();
         }
     }
 
@@ -77,7 +77,7 @@ abstract class SubscribeToStreamUtil {
                     // Unsecured HTTP and others go to unsecured WebSockets
                     uriBuilder.scheme("ws");
             }
-            return uriBuilder.replacePath(RestconfConstants.BASE_URI_PATTERN + '/' + streamName).build();
+            return uriBuilder.replacePath(URLConstants.BASE_PATH + '/' + streamName).build();
         }
     }
 
index 3334083e1960a827e29fd9f3100c64ce2465b3c9..a5a771adfd6d214f174387bcd138158114f96244 100644 (file)
@@ -18,8 +18,8 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.locks.StampedLock;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.restconf.nb.rfc8040.URLConstants;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
-import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
@@ -381,7 +381,7 @@ public final class ListenersBroker {
 
     /**
      * Creates string representation of stream name from URI. Removes slash from URI in start and end positions,
-     * and optionally {@link RestconfConstants#BASE_URI_PATTERN} prefix.
+     * and optionally {@link URLConstants#BASE_PATH} prefix.
      *
      * @param uri URI for creation of stream name.
      * @return String representation of stream name.
@@ -389,8 +389,8 @@ public final class ListenersBroker {
     public static String createStreamNameFromUri(final String uri) {
         String result = requireNonNull(uri);
         while (true) {
-            if (result.startsWith(RestconfConstants.BASE_URI_PATTERN)) {
-                result = result.substring(RestconfConstants.BASE_URI_PATTERN.length());
+            if (result.startsWith(URLConstants.BASE_PATH)) {
+                result = result.substring(URLConstants.BASE_PATH.length());
             } else if (result.startsWith("/")) {
                 result = result.substring(1);
             } else {
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/RestconfConstants.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/RestconfConstants.java
deleted file mode 100644 (file)
index 3c7e4db..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.nb.rfc8040.utils;
-
-/**
- * Util class for Restconf constants.
- */
-public final class RestconfConstants {
-    public static final String BASE_URI_PATTERN = "rests";
-    public static final String NOTIF = "notif";
-
-    private RestconfConstants() {
-        // Hidden on purpose
-    }
-}
\ No newline at end of file
index 6a6aae3dcabf654563fa31a2b7df4a094312238a..ea3df69c6461953775d79d802b5d62418265cc1d 100644 (file)
@@ -33,13 +33,13 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.nb.rfc8040.URLConstants;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.streams.StreamsConfiguration;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenerAdapter;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenersBroker;
-import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
@@ -122,10 +122,9 @@ public class RestconfStreamsSubscriptionServiceImplTest {
                         configurationSse);
         final NormalizedNodePayload response = streamsSubscriptionService.subscribeToStream(
             "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE", uriInfo);
-        assertEquals("http://localhost:8181/" + RestconfConstants.BASE_URI_PATTERN
-                + "/" + RestconfConstants.NOTIF
-                + "/data-change-event-subscription/toaster:toaster/toasterStatus/"
-                + "datastore=OPERATIONAL/scope=ONE", response.getNewHeaders().get("Location").toString());
+        assertEquals("http://localhost:8181/" + URLConstants.BASE_PATH + "/" + URLConstants.SSE_SUBPATH
+            + "/data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
+            response.getNewHeaders().get("Location").toString());
     }
 
     @Test
@@ -139,9 +138,9 @@ public class RestconfStreamsSubscriptionServiceImplTest {
                         configurationWs);
         final NormalizedNodePayload response = streamsSubscriptionService.subscribeToStream(
             "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE", uriInfo);
-        assertEquals("ws://localhost:8181/" + RestconfConstants.BASE_URI_PATTERN
-                + "/data-change-event-subscription/toaster:toaster/toasterStatus/"
-                + "datastore=OPERATIONAL/scope=ONE", response.getNewHeaders().get("Location").toString());
+        assertEquals("ws://localhost:8181/" + URLConstants.BASE_PATH
+            + "/data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
+            response.getNewHeaders().get("Location").toString());
     }
 
     @Test