qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgodf...@apache.org
Subject svn commit: r1772491 [2/2] - in /qpid/java/trunk: broker-core/src/main/java/org/apache/qpid/server/model/ broker-core/src/main/java/org/apache/qpid/server/model/port/ broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin...
Date Sat, 03 Dec 2016 22:11:17 GMT
Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java?rev=1772491&r1=1772490&r2=1772491&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java Sat Dec  3 22:11:17 2016
@@ -36,8 +36,9 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -54,13 +55,13 @@ import org.apache.qpid.server.configurat
 import org.apache.qpid.server.management.plugin.HttpManagement;
 import org.apache.qpid.server.management.plugin.HttpManagementUtil;
 import org.apache.qpid.server.model.AbstractConfiguredObject;
-import org.apache.qpid.server.model.Broker;
 import org.apache.qpid.server.model.ConfiguredObject;
 import org.apache.qpid.server.model.ConfiguredObjectFinder;
 import org.apache.qpid.server.model.ConfiguredObjectOperation;
 import org.apache.qpid.server.model.Content;
 import org.apache.qpid.server.model.IllegalStateTransitionException;
 import org.apache.qpid.server.model.IntegrityViolationException;
+import org.apache.qpid.server.model.Model;
 import org.apache.qpid.server.model.OperationTimeoutException;
 import org.apache.qpid.server.model.preferences.UserPreferences;
 import org.apache.qpid.server.util.ServerScopedRuntimeException;
@@ -72,10 +73,6 @@ public class RestServlet extends Abstrac
     private static final long serialVersionUID = 1L;
 
     private static final Logger LOGGER = LoggerFactory.getLogger(RestServlet.class);
-    /**
-     * An initialization parameter to specify hierarchy
-     */
-    private static final String HIERARCHY_INIT_PARAMETER = "hierarchy";
 
     public static final String DEPTH_PARAM = "depth";
     public static final String OVERSIZE_PARAM = "oversize";
@@ -104,38 +101,20 @@ public class RestServlet extends Abstrac
     public static final int DEFAULT_DEPTH = 1;
     public static final int DEFAULT_OVERSIZE = 120;
 
-    private Class<? extends ConfiguredObject>[] _hierarchy;
-
-    private final ConfiguredObjectToMapConverter _objectConverter = new ConfiguredObjectToMapConverter();
-    private final boolean _hierarchyInitializationRequired;
-    private volatile RequestInfoParser _requestInfoParser;
-    private RestUserPreferenceHandler _userPreferenceHandler;
-    private ConfiguredObjectFinder _objectFinder;
+    private transient final ConfiguredObjectToMapConverter _objectConverter = new ConfiguredObjectToMapConverter();
+    private transient RestUserPreferenceHandler _userPreferenceHandler;
 
     @SuppressWarnings("unused")
     public RestServlet()
     {
         super();
-        _hierarchyInitializationRequired = true;
-    }
-
-    public RestServlet(Class<? extends ConfiguredObject>... hierarchy)
-    {
-        super();
-        _hierarchy = hierarchy;
-        _hierarchyInitializationRequired = false;
     }
 
     @Override
     public void init() throws ServletException
     {
         super.init();
-        if (_hierarchyInitializationRequired)
-        {
-            doInitialization();
-        }
-        _objectFinder = new ConfiguredObjectFinder(getBroker());
-        _requestInfoParser = new RequestInfoParser(_hierarchy);
+
         Handler.register();
         Long preferenceOperationTimeout = getManagementConfiguration().getContextValue(Long.class, PREFERENCE_OPERTAION_TIMEOUT_CONTEXT_NAME);
         _userPreferenceHandler = new RestUserPreferenceHandler(preferenceOperationTimeout == null
@@ -143,55 +122,15 @@ public class RestServlet extends Abstrac
                                                                        : preferenceOperationTimeout);
     }
 
-    @SuppressWarnings("unchecked")
-    private void doInitialization() throws ServletException
-    {
-        ServletConfig config = getServletConfig();
-        String hierarchy = config.getInitParameter(HIERARCHY_INIT_PARAMETER);
-        if (hierarchy != null && !"".equals(hierarchy))
-        {
-            List<Class<? extends ConfiguredObject>> classes = new ArrayList<Class<? extends ConfiguredObject>>();
-            String[] hierarchyItems = hierarchy.split(",");
-            for (String item : hierarchyItems)
-            {
-                Class<?> itemClass;
-                try
-                {
-                    itemClass = Class.forName(item);
-                }
-                catch (ClassNotFoundException e)
-                {
-                    try
-                    {
-                        itemClass = Class.forName("org.apache.qpid.server.model." + item);
-                    }
-                    catch (ClassNotFoundException e1)
-                    {
-                        throw new ServletException("Unknown configured object class '" + item
-                                + "' is specified in hierarchy for " + config.getServletName());
-                    }
-                }
-                Class<? extends ConfiguredObject> clazz = (Class<? extends ConfiguredObject>)itemClass;
-                classes.add(clazz);
-            }
-            Class<? extends ConfiguredObject>[] hierarchyClasses = (Class<? extends ConfiguredObject>[])new Class[classes.size()];
-            _hierarchy = classes.toArray(hierarchyClasses);
-        }
-        else
-        {
-            _hierarchy = (Class<? extends ConfiguredObject>[])new Class[0];
-        }
-    }
-
 
-    private Collection<ConfiguredObject<?>> getTargetObjects(RequestInfo requestInfo,
+    private Collection<ConfiguredObject<?>> getTargetObjects(final Class<? extends ConfiguredObject> configuredClass,
+                                                             final ConfiguredObjectFinder finder,
+                                                             RequestInfo requestInfo,
                                                              List<Predicate<ConfiguredObject<?>>> filterPredicateList)
     {
         List<String> names = requestInfo.getModelParts();
-        ConfiguredObject<?> root = getBroker();
-        Class<? extends ConfiguredObject>[] hierarchy = _hierarchy;
 
-        Collection<ConfiguredObject<?>> parents = _objectFinder.findObjectsFromPath(names, hierarchy, true);
+        Collection<ConfiguredObject<?>> parents = finder.findObjectsFromPath(names, finder.getHierarchy(configuredClass), true);
 
         if (!(parents == null || filterPredicateList.isEmpty()))
         {
@@ -238,15 +177,33 @@ public class RestServlet extends Abstrac
     }
 
     @Override
-    protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response)
+    protected void doGetWithSubjectAndActor(HttpServletRequest request,
+                                            HttpServletResponse response,
+                                            final ConfiguredObject<?> managedObject)
             throws ServletException, IOException
     {
-        RequestInfo requestInfo = _requestInfoParser.parse(request);
+        ConfiguredObjectFinder finder = getConfiguredObjectFinder(managedObject);
+        Class<? extends ConfiguredObject> configuredClass = getConfiguredClass(request, managedObject);
+        if(configuredClass == null)
+        {
+            sendError(response, HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+        final Class<? extends ConfiguredObject>[] hierarchy = finder.getHierarchy(configuredClass);
+        if(hierarchy == null)
+        {
+            sendError(response, HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+
+        RequestInfoParser requestInfoParser = new RequestInfoParser(hierarchy);
+
+        RequestInfo requestInfo = requestInfoParser.parse(request);
         switch (requestInfo.getType())
         {
             case OPERATION:
             {
-                doOperation(requestInfo, request, response);
+                doOperation(requestInfo, managedObject, configuredClass, finder, request, response);
                 break;
             }
             case MODEL_OBJECT:
@@ -260,9 +217,9 @@ public class RestServlet extends Abstrac
                 }
 
                 Collection<ConfiguredObject<?>> allObjects =
-                        getTargetObjects(requestInfo, buildFilterPredicates(request));
+                        getTargetObjects(configuredClass, finder, requestInfo, buildFilterPredicates(request));
 
-                if (allObjects == null || (allObjects.isEmpty() && isSingleObjectRequest(requestInfo)))
+                if (allObjects == null || (allObjects.isEmpty() && isSingleObjectRequest(requestInfo, finder.getHierarchy(configuredClass))))
                 {
                     sendJsonErrorResponse(request, response, HttpServletResponse.SC_NOT_FOUND, "Not Found");
                     return;
@@ -343,7 +300,7 @@ public class RestServlet extends Abstrac
                 for (ConfiguredObject configuredObject : allObjects)
                 {
 
-                    output.add(_objectConverter.convertObjectToMap(configuredObject, getConfiguredClass(),
+                    output.add(_objectConverter.convertObjectToMap(configuredObject, configuredClass,
                                                                    new ConfiguredObjectToMapConverter.ConverterOptions(
                                                                            depth,
                                                                            actuals,
@@ -363,7 +320,7 @@ public class RestServlet extends Abstrac
             case VISIBLE_PREFERENCES:
             case USER_PREFERENCES:
             {
-                doGetUserPreferences(requestInfo, request, response);
+                doGetUserPreferences(managedObject, configuredClass, finder, requestInfo, request, response);
                 break;
             }
 
@@ -377,12 +334,13 @@ public class RestServlet extends Abstrac
     }
 
 
-    private boolean isSingleObjectRequest(final RequestInfo requestInfo)
+    private boolean isSingleObjectRequest(final RequestInfo requestInfo,
+                                          final Class<? extends ConfiguredObject>[] hierarchy)
     {
-        if (_hierarchy.length > 0)
+        if (hierarchy.length > 0)
         {
             List<String> pathInfoElements = requestInfo.getModelParts();
-            return pathInfoElements.size() == _hierarchy.length;
+            return pathInfoElements.size() == hierarchy.length;
         }
 
         return false;
@@ -405,16 +363,28 @@ public class RestServlet extends Abstrac
         }
     }
 
-    private Class<? extends ConfiguredObject> getConfiguredClass()
+    private Class<? extends ConfiguredObject> getConfiguredClass(HttpServletRequest request, ConfiguredObject<?> managedObject)
     {
-        return _hierarchy.length == 0 ? Broker.class : _hierarchy[_hierarchy.length-1];
+        final String[] servletPathElements = request.getServletPath().split("/");
+        String categoryName = servletPathElements[servletPathElements.length-1];
+        Model model = managedObject.getModel();
+        for(Class<? extends ConfiguredObject> category : model.getSupportedCategories())
+        {
+            if(category.getSimpleName().toLowerCase().equals(categoryName))
+            {
+                return category;
+            }
+        }
+        return null;
     }
 
     @Override
-    protected void doPutWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response)
+    protected void doPutWithSubjectAndActor(HttpServletRequest request,
+                                            HttpServletResponse response,
+                                            final ConfiguredObject<?> managedObject)
             throws ServletException, IOException
     {
-        performCreateOrUpdate(request, response);
+        performCreateOrUpdate(request, response, managedObject);
     }
 
     @Override
@@ -433,34 +403,42 @@ public class RestServlet extends Abstrac
         }
     }
 
-    private void performCreateOrUpdate(HttpServletRequest request, HttpServletResponse response)
+    private void performCreateOrUpdate(HttpServletRequest request,
+                                       HttpServletResponse response,
+                                       final ConfiguredObject<?> managedObject)
             throws IOException, ServletException
     {
+
+        ConfiguredObjectFinder finder = getConfiguredObjectFinder(managedObject);
+        final Class<? extends ConfiguredObject> configuredClass = getConfiguredClass(request, managedObject);
+        final Class<? extends ConfiguredObject>[] hierarchy = finder.getHierarchy(configuredClass);
+        RequestInfoParser requestInfoParser = new RequestInfoParser(hierarchy);
+
         response.setContentType("application/json");
 
-        RequestInfo requestInfo = _requestInfoParser.parse(request);
+        RequestInfo requestInfo = requestInfoParser.parse(request);
         switch (requestInfo.getType())
         {
             case MODEL_OBJECT:
             {
                 List<String> names = requestInfo.getModelParts();
-                boolean isFullObjectURL = names.size() == _hierarchy.length;
+                boolean isFullObjectURL = names.size() == hierarchy.length;
                 Map<String, Object> providedObject = getRequestProvidedObject(request, requestInfo);
-                if (names.isEmpty() && _hierarchy.length == 0)
+                if (names.isEmpty() && hierarchy.length == 0)
                 {
-                    getBroker().setAttributes(providedObject);
+                    managedObject.setAttributes(providedObject);
                     response.setStatus(HttpServletResponse.SC_OK);
                     return;
                 }
 
-                ConfiguredObject theParent = getBroker();
+                ConfiguredObject theParent = managedObject;
                 ConfiguredObject[] otherParents = null;
-                Class<? extends ConfiguredObject> objClass = getConfiguredClass();
-                if (_hierarchy.length > 1)
+                Class<? extends ConfiguredObject> objClass = configuredClass;
+                if (hierarchy.length > 1)
                 {
 
                     List<ConfiguredObject> parents =
-                            _objectFinder.findObjectParentsFromPath(names, _hierarchy, getConfiguredClass());
+                            finder.findObjectParentsFromPath(names, hierarchy, configuredClass);
                     theParent = parents.remove(0);
                     otherParents = parents.toArray(new ConfiguredObject[parents.size()]);
                 }
@@ -499,12 +477,12 @@ public class RestServlet extends Abstrac
             }
             case OPERATION:
             {
-                doOperation(requestInfo, request, response);
+                doOperation(requestInfo, managedObject, configuredClass, finder, request, response);
                 break;
             }
             case USER_PREFERENCES:
             {
-                doPostOrPutUserPreference(requestInfo, request, response);
+                doPostOrPutUserPreference(requestInfo, managedObject, configuredClass, finder, request, response);
                 break;
             }
             default:
@@ -516,14 +494,19 @@ public class RestServlet extends Abstrac
         }
     }
 
-    private void doGetUserPreferences(final RequestInfo requestInfo,
+    private void doGetUserPreferences(final ConfiguredObject<?> managedObject,
+                                      final Class<? extends ConfiguredObject> configuredClass,
+                                      final ConfiguredObjectFinder finder, final RequestInfo requestInfo,
                                       final HttpServletRequest request,
                                       final HttpServletResponse response) throws IOException, ServletException
     {
-        Collection<ConfiguredObject<?>> allObjects = getTargetObjects(requestInfo,
+        Collection<ConfiguredObject<?>> allObjects = getTargetObjects(
+                configuredClass,
+                                                                      finder,
+                                                                      requestInfo,
                                                                       Collections.<Predicate<ConfiguredObject<?>>>emptyList());
 
-        if (allObjects == null || (allObjects.isEmpty() && isSingleObjectRequest(requestInfo)))
+        if (allObjects == null || (allObjects.isEmpty() && isSingleObjectRequest(requestInfo, finder.getHierarchy(configuredClass))))
         {
             sendJsonErrorResponse(request, response, HttpServletResponse.SC_NOT_FOUND, "Not Found");
             return;
@@ -565,10 +548,13 @@ public class RestServlet extends Abstrac
     }
 
     private void doPostOrPutUserPreference(final RequestInfo requestInfo,
+                                           final ConfiguredObject<?> managedObject,
+                                           final Class<? extends ConfiguredObject> configuredClass,
+                                           final ConfiguredObjectFinder finder,
                                            final HttpServletRequest request,
                                            final HttpServletResponse response) throws IOException, ServletException
     {
-        ConfiguredObject<?> target = getTarget(requestInfo);
+        ConfiguredObject<?> target = getTarget(requestInfo, managedObject, configuredClass, finder);
 
         final Object providedObject = getRequestProvidedObject(request, requestInfo, Object.class);
         if ("POST".equals(request.getMethod()))
@@ -588,17 +574,21 @@ public class RestServlet extends Abstrac
         }
     }
 
-    private void doOperation(final RequestInfo requestInfo, final HttpServletRequest request,
+    private void doOperation(final RequestInfo requestInfo,
+                             final ConfiguredObject<?> managedObject,
+                             final Class<? extends ConfiguredObject> configuredClass,
+                             final ConfiguredObjectFinder finder,
+                             final HttpServletRequest request,
                              final HttpServletResponse response) throws IOException, ServletException
     {
-        ConfiguredObject<?> target = getTarget(requestInfo);
+        ConfiguredObject<?> target = getTarget(requestInfo, managedObject, configuredClass, finder);
         if (target == null)
         {
             return;
         }
         String operationName = requestInfo.getOperationName();
         final Map<String, ConfiguredObjectOperation<?>> availableOperations =
-                getBroker().getModel().getTypeRegistry().getOperations(target.getClass());
+                managedObject.getModel().getTypeRegistry().getOperations(target.getClass());
         ConfiguredObjectOperation operation = availableOperations.get(operationName);
         Map<String, Object> operationArguments;
 
@@ -713,28 +703,31 @@ public class RestServlet extends Abstrac
         }
     }
 
-    private ConfiguredObject<?> getTarget(final RequestInfo requestInfo) throws IOException
+    private ConfiguredObject<?> getTarget(final RequestInfo requestInfo,
+                                          final ConfiguredObject<?> managedObject,
+                                          final Class<? extends ConfiguredObject> configuredClass,
+                                          final ConfiguredObjectFinder finder) throws IOException
     {
         final ConfiguredObject<?> target;
         final List<String> names = requestInfo.getModelParts();
-
-        if (names.isEmpty() && _hierarchy.length == 0)
+        final Class<? extends ConfiguredObject>[] hierarchy = finder.getHierarchy(configuredClass);
+        if (names.isEmpty() && hierarchy.length == 0)
         {
-            target = getBroker();
+            target = managedObject;
         }
         else
         {
-            ConfiguredObject theParent = getBroker();
+            ConfiguredObject theParent = managedObject;
             ConfiguredObject[] otherParents = null;
-            if (_hierarchy.length > 1)
+            if (hierarchy.length > 1)
             {
 
                 List<ConfiguredObject> parents =
-                        _objectFinder.findObjectParentsFromPath(names, _hierarchy, getConfiguredClass());
+                        finder.findObjectParentsFromPath(names, hierarchy, configuredClass);
                 theParent = parents.remove(0);
                 otherParents = parents.toArray(new ConfiguredObject[parents.size()]);
             }
-            Class<? extends ConfiguredObject> objClass = getConfiguredClass();
+            Class<? extends ConfiguredObject> objClass = configuredClass;
             Map<String, Object> objectName =
                     Collections.<String, Object>singletonMap("name", names.get(names.size() - 1));
             target = findObjectToUpdateInParent(objClass, objectName, theParent, otherParents);
@@ -742,7 +735,7 @@ public class RestServlet extends Abstrac
             {
 
                 final String errorMessage = String.format("%s '%s' not found",
-                                                          getConfiguredClass().getSimpleName(),
+                                                          configuredClass.getSimpleName(),
                                                           Joiner.on("/").join(names));
                 throw new NotFoundException(errorMessage);
             }
@@ -1010,10 +1003,18 @@ public class RestServlet extends Abstrac
     }
 
     @Override
-    protected void doDeleteWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
-    {
-        RequestInfo requestInfo = _requestInfoParser.parse(request);
-        Collection<ConfiguredObject<?>> allObjects = getTargetObjects(requestInfo, buildFilterPredicates(request));
+    protected void doDeleteWithSubjectAndActor(HttpServletRequest request,
+                                               HttpServletResponse response,
+                                               final ConfiguredObject<?> managedObject) throws ServletException, IOException
+    {
+        ConfiguredObjectFinder finder = getConfiguredObjectFinder(managedObject);
+        Class<? extends ConfiguredObject> configuredClass = getConfiguredClass(request, managedObject);
+        final Class<? extends ConfiguredObject>[] hierarchy = finder.getHierarchy(configuredClass);
+        RequestInfoParser requestInfoParser = new RequestInfoParser(hierarchy);
+
+        RequestInfo requestInfo = requestInfoParser.parse(request);
+
+        Collection<ConfiguredObject<?>> allObjects = getTargetObjects(configuredClass, finder, requestInfo, buildFilterPredicates(request));
         if (allObjects == null)
         {
             throw new NotFoundException("Not Found");
@@ -1058,9 +1059,11 @@ public class RestServlet extends Abstrac
     }
 
     @Override
-    protected void doPostWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+    protected void doPostWithSubjectAndActor(HttpServletRequest request,
+                                             HttpServletResponse response,
+                                             final ConfiguredObject<?> managedObject) throws ServletException, IOException
     {
-        performCreateOrUpdate(request, response);
+        performCreateOrUpdate(request, response, managedObject);
     }
 
 

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java?rev=1772491&r1=1772490&r2=1772491&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java Sat Dec  3 22:11:17 2016
@@ -41,6 +41,7 @@ import org.slf4j.LoggerFactory;
 import org.apache.qpid.server.management.plugin.HttpManagementConfiguration;
 import org.apache.qpid.server.management.plugin.HttpManagementUtil;
 import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
 import org.apache.qpid.server.security.SubjectCreator;
 import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
 import org.apache.qpid.server.security.auth.AuthenticationResult;
@@ -68,7 +69,9 @@ public class SaslServlet extends Abstrac
         super();
     }
 
-    protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws
+    protected void doGetWithSubjectAndActor(HttpServletRequest request,
+                                            HttpServletResponse response,
+                                            final ConfiguredObject<?> managedObject) throws
                                                                                    ServletException,
                                                                                    IOException
     {
@@ -114,7 +117,9 @@ public class SaslServlet extends Abstrac
 
 
     @Override
-    protected void doPostWithSubjectAndActor(final HttpServletRequest request, final HttpServletResponse response) throws IOException
+    protected void doPostWithSubjectAndActor(final HttpServletRequest request,
+                                             final HttpServletResponse response,
+                                             final ConfiguredObject<?> managedObject) throws IOException
     {
         checkSaslAuthEnabled(request);
 

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java?rev=1772491&r1=1772490&r2=1772491&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java Sat Dec  3 22:11:17 2016
@@ -27,8 +27,8 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.qpid.server.model.Broker;
 import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.ConfiguredObjectFinder;
 
 public class StructureServlet extends AbstractServlet
 {
@@ -40,23 +40,26 @@ public class StructureServlet extends Ab
     }
 
     @Override
-    protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+    protected void doGetWithSubjectAndActor(HttpServletRequest request,
+                                            HttpServletResponse response,
+                                            final ConfiguredObject<?> managedObject) throws IOException, ServletException
     {
 
         // TODO filtering??? request.getParameter("filter"); // filter=1,2,3   /groups/*/*
 
-        Map<String,Object> structure = generateStructure(getBroker(), Broker.class);
+        Map<String,Object> structure = generateStructure(managedObject, managedObject.getCategoryClass(), true);
 
         sendJsonResponse(structure, request, response);
 
     }
 
-    private Map<String, Object> generateStructure(ConfiguredObject object, Class<? extends ConfiguredObject> clazz)
+    private Map<String, Object> generateStructure(ConfiguredObject object,
+                                                  Class<? extends ConfiguredObject> clazz,
+                                                  final boolean includeAssociated)
     {
         Map<String, Object> structure = new LinkedHashMap<String, Object>();
         structure.put("id", object.getId());
         structure.put("name", object.getName());
-
         for(Class<? extends ConfiguredObject> childClass : object.getModel().getChildTypes(clazz))
         {
             Collection<? extends ConfiguredObject> children = object.getChildren(childClass);
@@ -66,7 +69,7 @@ public class StructureServlet extends Ab
 
                 for(ConfiguredObject child : children)
                 {
-                    childObjects.add(generateStructure(child, childClass));
+                    childObjects.add(generateStructure(child, childClass, false));
                 }
 
                 if(!childObjects.isEmpty())
@@ -75,6 +78,29 @@ public class StructureServlet extends Ab
                 }
             }
         }
+        if(includeAssociated)
+        {
+
+            ConfiguredObjectFinder finder = getConfiguredObjectFinder(object);
+            for(Class<? extends ConfiguredObject> childClass : finder.getAssociatedChildCategories())
+            {
+                Collection<? extends ConfiguredObject> children = finder.getAssociatedChildren(childClass);
+                if(children != null)
+                {
+                    List<Map<String, Object>> childObjects = new ArrayList<Map<String, Object>>();
+
+                    for(ConfiguredObject child : children)
+                    {
+                        childObjects.add(generateStructure(child, childClass, false));
+                    }
+
+                    if(!childObjects.isEmpty())
+                    {
+                        structure.put(pluralize(childClass),childObjects);
+                    }
+                }
+            }
+        }
 
         return structure;
     }

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/TimeZoneServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/TimeZoneServlet.java?rev=1772491&r1=1772490&r2=1772491&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/TimeZoneServlet.java (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/TimeZoneServlet.java Sat Dec  3 22:11:17 2016
@@ -30,6 +30,8 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.qpid.server.model.ConfiguredObject;
+
 public class TimeZoneServlet extends AbstractServlet
 {
     private static final long serialVersionUID = 1L;
@@ -43,8 +45,10 @@ public class TimeZoneServlet extends Abs
     }
 
     @Override
-    protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws ServletException,
-            IOException
+    protected void doGetWithSubjectAndActor(HttpServletRequest request,
+                                            HttpServletResponse response,
+                                            final ConfiguredObject<?> managedObject) throws ServletException,
+                                                                                            IOException
     {
         sendJsonResponse(getTimeZones(), request, response);
     }

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostQueryServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostQueryServlet.java?rev=1772491&r1=1772490&r2=1772491&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostQueryServlet.java (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostQueryServlet.java Sat Dec  3 22:11:17 2016
@@ -41,17 +41,27 @@ public class VirtualHostQueryServlet ext
     private static final long serialVersionUID = 1L;
 
     @Override
-    protected VirtualHost<?> getParent(final HttpServletRequest request)
+    protected VirtualHost<?> getParent(final HttpServletRequest request, final ConfiguredObject<?> managedObject)
     {
         final List<String>
                 path = HttpManagementUtil.getPathInfoElements(request.getServletPath(), request.getPathInfo());
-        final Broker<?> broker = HttpManagementUtil.getBroker(request.getServletContext());
-        if (path.size() == 3)
+        if(managedObject instanceof Broker)
         {
-            VirtualHostNode<?> vhn = broker.getChildByName(VirtualHostNode.class, path.get(0));
-            if (vhn != null)
+            final Broker<?> broker = HttpManagementUtil.getBroker(request.getServletContext());
+            if (path.size() == 3)
             {
-                return vhn.getChildByName(VirtualHost.class, path.get(1));
+                VirtualHostNode<?> vhn = broker.getChildByName(VirtualHostNode.class, path.get(0));
+                if (vhn != null)
+                {
+                    return vhn.getChildByName(VirtualHost.class, path.get(1));
+                }
+            }
+        }
+        else if(managedObject instanceof VirtualHost)
+        {
+            if(path.size() == 1)
+            {
+                return (VirtualHost<?>)managedObject;
             }
         }
         return null;
@@ -84,14 +94,18 @@ public class VirtualHostQueryServlet ext
         }
     }
 
-    protected String getRequestedCategory(final HttpServletRequest request)
+    protected String getRequestedCategory(final HttpServletRequest request, final ConfiguredObject<?> managedObject)
     {
         List<String> pathInfoElements =
                 HttpManagementUtil.getPathInfoElements(request.getServletPath(), request.getPathInfo());
-        if (pathInfoElements.size() == 3)
+        if (managedObject instanceof Broker && pathInfoElements.size() == 3)
         {
             return pathInfoElements.get(2);
         }
+        else if(managedObject instanceof VirtualHost && pathInfoElements.size() == 1)
+        {
+            return pathInfoElements.get(0);
+        }
         return null;
     }
 

Modified: qpid/java/trunk/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandlerTest.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandlerTest.java?rev=1772491&r1=1772490&r2=1772491&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandlerTest.java (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/RestUserPreferenceHandlerTest.java Sat Dec  3 22:11:17 2016
@@ -38,21 +38,17 @@ import java.util.UUID;
 import javax.security.auth.Subject;
 
 import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
 
 import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor;
 import org.apache.qpid.server.configuration.updater.TaskExecutor;
 import org.apache.qpid.server.model.ConfiguredObject;
-import org.apache.qpid.server.model.GroupProvider;
 import org.apache.qpid.server.model.preferences.GenericPrincipal;
 import org.apache.qpid.server.model.preferences.Preference;
 import org.apache.qpid.server.model.preferences.PreferenceFactory;
 import org.apache.qpid.server.model.preferences.UserPreferences;
 import org.apache.qpid.server.model.preferences.UserPreferencesImpl;
 import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
-import org.apache.qpid.server.security.auth.AuthenticationResult;
 import org.apache.qpid.server.security.auth.TestPrincipalUtils;
-import org.apache.qpid.server.security.auth.UsernamePrincipal;
 import org.apache.qpid.server.security.group.GroupPrincipal;
 import org.apache.qpid.server.store.preferences.PreferenceStore;
 import org.apache.qpid.test.utils.QpidTestCase;
@@ -104,7 +100,8 @@ public class RestUserPreferenceHandlerTe
 
         final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
                                                                                  Arrays.asList("X-testtype",
-                                                                                               "myprefname"));
+                                                                                               "myprefname")
+                                                                                );
 
         final Map<String, Object> pref = new HashMap<>();
         pref.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
@@ -135,7 +132,8 @@ public class RestUserPreferenceHandlerTe
 
         final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
                                                                                  Arrays.asList("X-testtype",
-                                                                                               "myprefname"));
+                                                                                               "myprefname")
+                                                                                );
 
         final Map<String, Object> pref = new HashMap<>();
         pref.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
@@ -165,8 +163,8 @@ public class RestUserPreferenceHandlerTe
     {
         final String prefName = "myprefname";
         final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
-                                                                                 Arrays.asList("X-testtype",
-                                                                                               prefName));
+                                                                                 Arrays.asList("X-testtype", prefName)
+                                                                                );
 
         final Map<String, Object> pref = new HashMap<>();
         pref.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
@@ -192,8 +190,8 @@ public class RestUserPreferenceHandlerTe
     {
         final String prefName = "myprefname";
         final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
-                                                                                 Arrays.asList("X-testtype",
-                                                                                               prefName));
+                                                                                 Arrays.asList("X-testtype", prefName)
+                                                                                );
 
         final Map<String, Object> pref = new HashMap<>();
         pref.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
@@ -266,7 +264,8 @@ public class RestUserPreferenceHandlerTe
     {
         final String prefName = "myprefname";
         final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
-                                                                                 Arrays.asList("X-testtype"));
+                                                                                 Arrays.asList("X-testtype")
+                                                                                );
 
         final Map<String, Object> pref = new HashMap<>();
         pref.put(Preference.NAME_ATTRIBUTE, prefName);
@@ -329,7 +328,8 @@ public class RestUserPreferenceHandlerTe
         final String pref2Type = "X-testtype2";
 
         final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
-                                                                                 Collections.<String>emptyList());
+                                                                                 Collections.<String>emptyList()
+                                                                                );
 
         final Map<String, Object> pref1 = new HashMap<>();
         pref1.put(Preference.NAME_ATTRIBUTE, pref1Name);
@@ -390,7 +390,8 @@ public class RestUserPreferenceHandlerTe
     public void testPostToTypeWithVisibilityList_ValidGroup() throws Exception
     {
         final RequestInfo typeRequestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
-                                                                                     Arrays.asList("X-testtype"));
+                                                                                     Arrays.asList("X-testtype")
+                                                                                    );
 
         final Map<String, Object> pref = new HashMap<>();
         pref.put(Preference.NAME_ATTRIBUTE, "testPref");
@@ -420,7 +421,8 @@ public class RestUserPreferenceHandlerTe
     public void testPostToRootWithVisibilityList_ValidGroup() throws Exception
     {
         final RequestInfo rootRequestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
-                                                                                     Collections.<String>emptyList());
+                                                                                     Collections.<String>emptyList()
+                                                                                    );
         final Map<String, Object> pref = new HashMap<>();
         pref.put(Preference.NAME_ATTRIBUTE, "testPref");
         pref.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
@@ -452,7 +454,8 @@ public class RestUserPreferenceHandlerTe
     public void testPostToTypeWithVisibilityList_InvalidGroup() throws Exception
     {
         final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
-                                                                                 Arrays.asList("X-testtype"));
+                                                                                 Arrays.asList("X-testtype")
+                                                                                );
 
         final Map<String, Object> pref = new HashMap<>();
         pref.put(Preference.NAME_ATTRIBUTE, "testPref");
@@ -483,7 +486,8 @@ public class RestUserPreferenceHandlerTe
     public void testPostToRootWithVisibilityList_InvalidGroup() throws Exception
     {
         final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
-                                                                                 Collections.<String>emptyList());
+                                                                                 Collections.<String>emptyList()
+                                                                                );
 
         final Map<String, Object> pref = new HashMap<>();
         pref.put(Preference.NAME_ATTRIBUTE, "testPref");
@@ -515,7 +519,8 @@ public class RestUserPreferenceHandlerTe
     public void testGetHasCorrectVisibilityList() throws Exception
     {
         final RequestInfo rootRequestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
-                                                                                     Collections.<String>emptyList());
+                                                                                     Collections.<String>emptyList()
+                                                                                    );
         final String type = "X-testtype";
 
         Subject.doAs(_subject, new PrivilegedAction<Void>()
@@ -587,7 +592,8 @@ public class RestUserPreferenceHandlerTe
                                      RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
                                                                               Collections.<String>emptyList(),
                                                                               Collections.singletonMap("id",
-                                                                                                       Collections.singletonList(id.toString())));
+                                                                                                       Collections.singletonList(id.toString()))
+                                                                             );
 
                              Map<String, List<Map<String, Object>>> typeToPreferenceListMap =
                                      (Map<String, List<Map<String, Object>>>) _handler.handleGET(_userPreferences, rootRequestInfo);
@@ -639,7 +645,8 @@ public class RestUserPreferenceHandlerTe
                                      RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
                                                                               Collections.<String>emptyList(),
                                                                               Collections.singletonMap("id",
-                                                                                                       Collections.singletonList(id.toString())));
+                                                                                                       Collections.singletonList(id.toString()))
+                                                                             );
 
                              _handler.handleDELETE(_userPreferences, rootRequestInfo);
 
@@ -658,7 +665,8 @@ public class RestUserPreferenceHandlerTe
         final String preferenceName = "myprefname";
         final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
                                                                                  Arrays.asList(preferenceType,
-                                                                                               preferenceName));
+                                                                                               preferenceName)
+                                                                                );
 
         final Map<String, Object> pref = new HashMap<>();
         pref.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
@@ -671,7 +679,8 @@ public class RestUserPreferenceHandlerTe
         final String preferenceType = "X-testtype";
         final String preferenceName = "myprefname";
         final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
-                                                                                 Arrays.asList(preferenceType));
+                                                                                 Arrays.asList(preferenceType)
+                                                                                );
 
         final Map<String, Object> pref = new HashMap<>();
         pref.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
@@ -684,7 +693,8 @@ public class RestUserPreferenceHandlerTe
         final String preferenceType = "X-testtype";
         final String preferenceName = "myprefname";
         final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(Collections.<String>emptyList(),
-                                                                                 Collections.<String>emptyList());
+                                                                                 Collections.<String>emptyList()
+                                                                                );
 
         final Map<String, Object> pref = new HashMap<>();
         pref.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
@@ -699,7 +709,8 @@ public class RestUserPreferenceHandlerTe
         final RequestInfo rootRequestInfo =
                 RequestInfo.createVisiblePreferencesRequestInfo(Collections.<String>emptyList(),
                                                                 Collections.<String>emptyList(),
-                                                                Collections.<String, List<String>>emptyMap());
+                                                                Collections.<String, List<String>>emptyMap()
+                                                               );
 
         Subject.doAs(_subject, new PrivilegedAction<Void>()
                      {
@@ -772,7 +783,8 @@ public class RestUserPreferenceHandlerTe
         final RequestInfo rootRequestInfo =
                 RequestInfo.createVisiblePreferencesRequestInfo(Collections.<String>emptyList(),
                                                                 Arrays.asList(prefType),
-                                                                Collections.<String, List<String>>emptyMap());
+                                                                Collections.<String, List<String>>emptyMap()
+                                                               );
 
         Subject.doAs(_subject, new PrivilegedAction<Void>()
                      {
@@ -842,7 +854,8 @@ public class RestUserPreferenceHandlerTe
         final RequestInfo rootRequestInfo =
                 RequestInfo.createVisiblePreferencesRequestInfo(Collections.<String>emptyList(),
                                                                 Arrays.asList(prefType, prefName),
-                                                                Collections.<String, List<String>>emptyMap());
+                                                                Collections.<String, List<String>>emptyMap()
+                                                               );
 
         Subject.doAs(_subject, new PrivilegedAction<Void>()
                      {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message