QPID-8259: [Broker-J] Fix handling of requests for unsupported category
authorAlex Rudyy <orudyy@apache.org>
Fri, 21 Dec 2018 14:50:13 +0000 (14:50 +0000)
committerAlex Rudyy <orudyy@apache.org>
Fri, 21 Dec 2018 15:13:02 +0000 (15:13 +0000)
broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/controller/latest/LatestManagementController.java
systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/OperationTest.java

index 18b457a..7a32153 100644 (file)
@@ -92,6 +92,7 @@ public class LatestManagementController extends AbstractManagementController
 
     private static final int DEFAULT_DEPTH = 0;
     private static final int DEFAULT_OVERSIZE = 120;
+    private static final Class<? extends ConfiguredObject>[] EMPTY_HIERARCHY = new Class[0];
 
 
     private final ConcurrentMap<ConfiguredObject<?>, ConfiguredObjectFinder> _configuredObjectFinders =
@@ -172,7 +173,7 @@ public class LatestManagementController extends AbstractManagementController
         final ConfiguredObjectFinder finder = getConfiguredObjectFinder(root);
         final String category = request.getCategory();
         final Class<? extends ConfiguredObject> configuredClass = getRequestCategoryClass(category, root.getModel());
-        final Class<? extends ConfiguredObject>[] hierarchy = finder.getHierarchy(configuredClass);
+        final Class<? extends ConfiguredObject>[] hierarchy = getHierarchy(finder, configuredClass);
         return getManagementRequestType(request.getMethod(), category, request.getPath(), hierarchy);
     }
 
@@ -239,7 +240,7 @@ public class LatestManagementController extends AbstractManagementController
             if (hierarchy.size() > 1)
             {
                 final ConfiguredObjectFinder finder = getConfiguredObjectFinder(root);
-                theParent = finder.findObjectParentsFromPath(path, finder.getHierarchy(categoryClass), categoryClass);
+                theParent = finder.findObjectParentsFromPath(path, getHierarchy(finder, categoryClass), categoryClass);
             }
 
             final boolean isFullObjectURL = path.size() == hierarchy.size();
@@ -628,7 +629,7 @@ public class LatestManagementController extends AbstractManagementController
         final ConfiguredObjectFinder finder = getConfiguredObjectFinder(root);
         final Class<? extends ConfiguredObject> configuredClass = getRequestCategoryClass(category, root.getModel());
         Collection<ConfiguredObject<?>> targetObjects =
-                finder.findObjectsFromPath(path, finder.getHierarchy(configuredClass), true);
+                finder.findObjectsFromPath(path, getHierarchy(finder, configuredClass), true);
 
         if (targetObjects == null)
         {
@@ -641,6 +642,17 @@ public class LatestManagementController extends AbstractManagementController
         return targetObjects;
     }
 
+    private Class<? extends ConfiguredObject>[] getHierarchy(final ConfiguredObjectFinder finder,
+                                                             final Class<? extends ConfiguredObject> configuredClass)
+    {
+        final Class<? extends ConfiguredObject>[] hierarchy = finder.getHierarchy(configuredClass);
+        if (hierarchy == null)
+        {
+            return EMPTY_HIERARCHY;
+        }
+        return hierarchy;
+    }
+
     private RequestType getManagementRequestType(final String method,
                                                  final String categoryName,
                                                  final List<String> parts,
@@ -829,7 +841,7 @@ public class LatestManagementController extends AbstractManagementController
         final Class<? extends ConfiguredObject> configuredClass = getRequestCategoryClass(category, root.getModel());
         final ConfiguredObject<?> target;
         final ConfiguredObjectFinder finder = getConfiguredObjectFinder(root);
-        final Class<? extends ConfiguredObject>[] hierarchy = finder.getHierarchy(configuredClass);
+        final Class<? extends ConfiguredObject>[] hierarchy = getHierarchy(finder, configuredClass);
         if (names.isEmpty() && hierarchy.length == 0)
         {
             target = root;
index ade744a..6a06855 100644 (file)
@@ -106,4 +106,25 @@ public class OperationTest extends HttpTestBase
                                                     SC_OK);
         assertThat(response, is(nullValue()));
     }
+
+    @Test
+    public void invokeOperationForUnknownCategory() throws Exception
+    {
+
+        try
+        {
+            getHelper().postJson("broker/performGC",
+                                 Collections.emptyMap(),
+                                 new TypeReference<Void>()
+                                 {
+                                 },
+                                 SC_NOT_FOUND);
+            fail("The request is executed against root object VirtualHost. Thus, any broker request should fail.");
+        }
+        catch (FileNotFoundException e)
+        {
+            //pass
+        }
+
+    }
 }