Report data-missing when an invalid stream is requested 43/97143/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 11 Aug 2021 13:41:54 +0000 (15:41 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 11 Aug 2021 13:49:21 +0000 (15:49 +0200)
We should not be throwing a random IAE, but rather use a
RestconfDocumentedException to report the correct status.

JIRA: NETCONF-802
Change-Id: I4ac0a24f0acb059f08d14ab0abd4021e91b0d07b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 587da7df15b8d971bb434a5e96023cb982b09939)

restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java

index 3da9f2669a2949f522685bc0c879c68db51eb345..5ca9f6d6dd323ca0bf56dc4d5dc44c3d7f01d53f 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
 
-import static com.google.common.base.Preconditions.checkArgument;
-
 import com.google.common.base.Strings;
 import java.net.URI;
 import java.util.HashMap;
@@ -196,16 +194,17 @@ abstract class SubscribeToStreamUtil {
         }
 
         final String streamName = ListenersBroker.createStreamNameFromUri(identifier);
-        final Optional<ListenerAdapter> listener = ListenersBroker.getInstance().getDataChangeListenerFor(streamName);
-        checkArgument(listener.isPresent(), "Listener does not exist : %s", streamName);
+        final ListenerAdapter listener = ListenersBroker.getInstance().getDataChangeListenerFor(streamName)
+            .orElseThrow(() -> new RestconfDocumentedException("No listener found for stream " + streamName,
+                ErrorType.PROTOCOL.APPLICATION, ErrorTag.DATA_MISSING));
 
-        listener.get().setQueryParams(
+        listener.setQueryParams(
                 notificationQueryParams.getStart(),
                 notificationQueryParams.getStop().orElse(null),
                 notificationQueryParams.getFilter().orElse(null),
                 false, notificationQueryParams.isSkipNotificationData());
-        listener.get().setCloseVars(handlersHolder.getTransactionChainHandler(), handlersHolder.getSchemaHandler());
-        registration(datastoreType, listener.get(), handlersHolder.getDomDataBrokerHandler().get());
+        listener.setCloseVars(handlersHolder.getTransactionChainHandler(), handlersHolder.getSchemaHandler());
+        registration(datastoreType, listener, handlersHolder.getDomDataBrokerHandler().get());
 
         final URI uri = prepareUriByStreamName(uriInfo, streamName);
         final DOMTransactionChain transactionChain = handlersHolder.getTransactionChainHandler().get();
@@ -213,9 +212,9 @@ abstract class SubscribeToStreamUtil {
         final EffectiveModelContext schemaContext = handlersHolder.getSchemaHandler().get();
 
         final MapEntryNode mapToStreams =
-            RestconfMappingNodeUtil.mapDataChangeNotificationStreamByIetfRestconfMonitoring(listener.get().getPath(),
-                notificationQueryParams.getStart(), listener.get().getOutputType(), uri, schemaContext,
-                IdentifierCodec.serialize(listener.get().getPath(), schemaContext));
+            RestconfMappingNodeUtil.mapDataChangeNotificationStreamByIetfRestconfMonitoring(listener.getPath(),
+                notificationQueryParams.getStart(), listener.getOutputType(), uri, schemaContext,
+                IdentifierCodec.serialize(listener.getPath(), schemaContext));
         writeDataToDS(writeTransaction, mapToStreams);
         submitData(writeTransaction);
         transactionChain.close();