summaryrefslogtreecommitdiff
path: root/qpid/java/broker-plugins/management-http/src/main
diff options
context:
space:
mode:
authorRobert Godfrey <rgodfrey@apache.org>2014-07-29 12:58:37 +0000
committerRobert Godfrey <rgodfrey@apache.org>2014-07-29 12:58:37 +0000
commit2db948b9045d5c13919db8db3bfeca3712203a56 (patch)
tree69e9fdc687a976e60d3d3648dd4bf9825dc2ce2d /qpid/java/broker-plugins/management-http/src/main
parent14e411f0f8fbbd10aa8bf08e8926332265e04b1c (diff)
downloadqpid-python-2db948b9045d5c13919db8db3bfeca3712203a56.tar.gz
QPID-5937 : [Java Broker] Add parameters to REST servlet to allow return of actual vs. effective attribute values
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1614333 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker-plugins/management-http/src/main')
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java39
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java25
2 files changed, 54 insertions, 10 deletions
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
index 7c5ba5a6be..bc563c141e 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
@@ -21,6 +21,7 @@ package org.apache.qpid.server.management.plugin.servlet.rest;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -33,32 +34,54 @@ public class ConfiguredObjectToMapConverter
public static final String STATISTICS_MAP_KEY = "statistics";
public Map<String, Object> convertObjectToMap(final ConfiguredObject<?> confObject,
- Class<? extends ConfiguredObject> clazz,
- int depth)
+ Class<? extends ConfiguredObject> clazz,
+ int depth,
+ final boolean useActualValues,
+ final boolean includeSystemContext)
{
Map<String, Object> object = new LinkedHashMap<String, Object>();
- incorporateAttributesIntoMap(confObject, object);
+ incorporateAttributesIntoMap(confObject, object, useActualValues, includeSystemContext);
incorporateStatisticsIntoMap(confObject, object);
if(depth > 0)
{
- incorporateChildrenIntoMap(confObject, clazz, depth, object);
+ incorporateChildrenIntoMap(confObject, clazz, depth, object, useActualValues, includeSystemContext);
}
return object;
}
private void incorporateAttributesIntoMap(
- final ConfiguredObject<?> confObject, Map<String, Object> object)
+ final ConfiguredObject<?> confObject,
+ Map<String, Object> object,
+ final boolean useActualValues,
+ final boolean includeSystemContext)
{
+
for(String name : confObject.getAttributeNames())
{
- Object value = confObject.getAttribute(name);
+ Object value = useActualValues ? confObject.getActualAttributes().get(name) : confObject.getAttribute(name);
if(value instanceof ConfiguredObject)
{
object.put(name, ((ConfiguredObject) value).getName());
}
+ else if(ConfiguredObject.CONTEXT.equals(name))
+ {
+ Map<String,Object> contextValues = new HashMap<>();
+ if(useActualValues)
+ {
+ contextValues.putAll(confObject.getContext());
+ }
+ else
+ {
+ for(String contextName : confObject.getContextKeys(!includeSystemContext))
+ {
+ contextValues.put(contextName, confObject.getContextValue(String.class, contextName));
+ }
+ }
+ object.put(ConfiguredObject.CONTEXT, contextValues);
+ }
else if(value instanceof Collection)
{
List<Object> converted = new ArrayList();
@@ -98,7 +121,7 @@ public class ConfiguredObjectToMapConverter
private void incorporateChildrenIntoMap(
final ConfiguredObject confObject,
Class<? extends ConfiguredObject> clazz, int depth,
- Map<String, Object> object)
+ Map<String, Object> object, final boolean useActualValues, final boolean includeSystemContext)
{
for(Class<? extends ConfiguredObject> childClass : confObject.getModel().getChildTypes(clazz))
{
@@ -109,7 +132,7 @@ public class ConfiguredObjectToMapConverter
for(ConfiguredObject child : children)
{
- childObjects.add(convertObjectToMap(child, childClass, depth-1));
+ childObjects.add(convertObjectToMap(child, childClass, depth-1, useActualValues, includeSystemContext));
}
if(!childObjects.isEmpty())
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
index b261927ee7..87a4b6fb1a 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
@@ -53,9 +53,11 @@ public class RestServlet extends AbstractServlet
private static final String HIERARCHY_INIT_PARAMETER = "hierarchy";
public static final String DEPTH_PARAM = "depth";
+ public static final String ACTUALS_PARAM = "actuals";
public static final String SORT_PARAM = "sort";
+ public static final String INCLUDE_SYS_CONTEXT_PARAM = "includeSysContext";
- public static final Set<String> RESERVED_PARAMS = new HashSet<String>(Arrays.asList(DEPTH_PARAM, SORT_PARAM));
+ public static final Set<String> RESERVED_PARAMS = new HashSet<String>(Arrays.asList(DEPTH_PARAM, SORT_PARAM, ACTUALS_PARAM, INCLUDE_SYS_CONTEXT_PARAM));
private Class<? extends ConfiguredObject>[] _hierarchy;
@@ -311,12 +313,14 @@ public class RestServlet extends AbstractServlet
// TODO - sort special params, everything else should act as a filter
int depth = getDepthParameterFromRequest(request);
+ boolean actuals = getBooleanParameterFromRequest(request, ACTUALS_PARAM);
+ boolean includeSystemContext = getBooleanParameterFromRequest(request, INCLUDE_SYS_CONTEXT_PARAM);
List<Map<String, Object>> output = new ArrayList<Map<String, Object>>();
for(ConfiguredObject configuredObject : allObjects)
{
output.add(_objectConverter.convertObjectToMap(configuredObject, getConfiguredClass(),
- depth));
+ depth, actuals, includeSystemContext));
}
final Writer writer = new BufferedWriter(response.getWriter());
@@ -576,5 +580,22 @@ public class RestServlet extends AbstractServlet
return depth;
}
+ private boolean getBooleanParameterFromRequest(HttpServletRequest request, final String paramName)
+ {
+ boolean value = false;
+ final String stringValue = request.getParameter(paramName);
+ if(stringValue!=null)
+ {
+ try
+ {
+ value = Boolean.parseBoolean(stringValue);
+ }
+ catch (NumberFormatException e)
+ {
+ LOGGER.warn("Could not parse " + stringValue + " as integer");
+ }
+ }
+ return value;
+ }
}