qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lqu...@apache.org
Subject svn commit: r1742259 - in /qpid/java/branches/6.0.x: ./ broker-plugins/management-http/ broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ broker-plugins/management-http/src/test/java/org/apache/qpid/ser...
Date Wed, 04 May 2016 12:24:59 GMT
Author: lquack
Date: Wed May  4 12:24:59 2016
New Revision: 1742259

URL: http://svn.apache.org/viewvc?rev=1742259&view=rev
Log:
QPID-7211: [Java Broker] Introduce request parameter to not transfer context variables

merged from trunk with command:
svn merge -c 1742257 ^/qpid/java/trunk

Modified:
    qpid/java/branches/6.0.x/   (props changed)
    qpid/java/branches/6.0.x/broker-plugins/management-http/pom.xml
    qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
    qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
    qpid/java/branches/6.0.x/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java

Propchange: qpid/java/branches/6.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed May  4 12:24:59 2016
@@ -9,5 +9,5 @@
 /qpid/branches/java-broker-vhost-refactor/java:1493674-1494547
 /qpid/branches/java-network-refactor/qpid/java:805429-821809
 /qpid/branches/qpid-2935/qpid/java:1061302-1072333
-/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619,1716636,1717269,1717299,1717401,1717446,1717449,1717626,1717691,1717735,1717780,1718744,1718889,1718893,1718918,1718922,1719026,1719028,1719033,1719037,1719047,1719051,1720340,1720664,1721151,1721198,1722019-1722020,1722246,1722339,1722416,1722674,1722678,1722683,1722711,1723064,1723194,1723563,1724216,1724251,1724257,1724292,1724375,1724397,1724432,1724582,1724603,1724780,1724843-1724844,1725295,1725569,1725760,1726176,1726244-1726246,1726249,1726358,1726436,1726449,1726456,1726646,1726653,1726755,1726778,1727532,1727555,1727608,1727951,1727954,1728089,1728167,1728302,1728497,1728501,1728524,1728639,1728651,1728772,1729215,1729297,1729347,1729356,1729406,1729408,1729412,1729515,1729638,1729656-1729
 657,1729783,1729828,1729832,1729841,1729851,1729886,1729904,1729973,1730019,1730025,1730052,1730072,1730088,1730494,1730499,1730547,1730559,1730567,1730578,1730585,1730651,1730697,1730712-1730713,1730805,1731029,1731110,1731210,1731225,1731444,1731551,1731612,1732184,1732452,1732461,1732525,1732812,1734452,1736478,1736751,1736838,1737804,1737835,1737853,1737984,1737992,1738119,1738135,1738231,1738271,1738607,1738610,1738731,1738914,1741702
+/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619,1716636,1717269,1717299,1717401,1717446,1717449,1717626,1717691,1717735,1717780,1718744,1718889,1718893,1718918,1718922,1719026,1719028,1719033,1719037,1719047,1719051,1720340,1720664,1721151,1721198,1722019-1722020,1722246,1722339,1722416,1722674,1722678,1722683,1722711,1723064,1723194,1723563,1724216,1724251,1724257,1724292,1724375,1724397,1724432,1724582,1724603,1724780,1724843-1724844,1725295,1725569,1725760,1726176,1726244-1726246,1726249,1726358,1726436,1726449,1726456,1726646,1726653,1726755,1726778,1727532,1727555,1727608,1727951,1727954,1728089,1728167,1728302,1728497,1728501,1728524,1728639,1728651,1728772,1729215,1729297,1729347,1729356,1729406,1729408,1729412,1729515,1729638,1729656-1729
 657,1729783,1729828,1729832,1729841,1729851,1729886,1729904,1729973,1730019,1730025,1730052,1730072,1730088,1730494,1730499,1730547,1730559,1730567,1730578,1730585,1730651,1730697,1730712-1730713,1730805,1731029,1731110,1731210,1731225,1731444,1731551,1731612,1732184,1732452,1732461,1732525,1732812,1734452,1736478,1736751,1736838,1737804,1737835,1737853,1737984,1737992,1738119,1738135,1738231,1738271,1738607,1738610,1738731,1738914,1741702,1742257
 /qpid/trunk/qpid:796646-796653

Modified: qpid/java/branches/6.0.x/broker-plugins/management-http/pom.xml
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-plugins/management-http/pom.xml?rev=1742259&r1=1742258&r2=1742259&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/broker-plugins/management-http/pom.xml (original)
+++ qpid/java/branches/6.0.x/broker-plugins/management-http/pom.xml Wed May  4 12:24:59 2016
@@ -99,6 +99,14 @@
       <version>${project.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.qpid</groupId>
+      <artifactId>qpid-broker-core</artifactId>
+      <version>${project.version}</version>
+      <classifier>tests</classifier>
+      <scope>test</scope>
+    </dependency>
+
   </dependencies>
 
   <build>

Modified: qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java?rev=1742259&r1=1742258&r2=1742259&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java (original)
+++ qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java Wed May  4 12:24:59 2016
@@ -52,28 +52,20 @@ public class ConfiguredObjectToMapConver
 
     public Map<String, Object> convertObjectToMap(final ConfiguredObject<?> confObject,
                                                   Class<? extends ConfiguredObject> clazz,
-                                                  int depth,
-                                                  final boolean useActualValues,
-                                                  final boolean inheritedActuals,
-                                                  final boolean includeSystemContext,
-                                                  final boolean extractAsConfig,
-                                                  final int oversizeThreshold,
-                                                  final boolean isSecureTransport
+                                                  ConverterOptions converterOptions
                                                  )
     {
         Map<String, Object> object = new LinkedHashMap<>();
 
-        incorporateAttributesIntoMap(confObject, object, useActualValues, inheritedActuals, includeSystemContext,
-                                     extractAsConfig, oversizeThreshold, isSecureTransport);
-        if(!extractAsConfig)
+        incorporateAttributesIntoMap(confObject, object, converterOptions);
+        if(!converterOptions.isExtractAsConfig())
         {
             incorporateStatisticsIntoMap(confObject, object);
         }
 
-        if(depth > 0)
+        if(converterOptions.getDepth() > 0)
         {
-            incorporateChildrenIntoMap(confObject, clazz, depth, object, useActualValues, inheritedActuals,
-                                       includeSystemContext, extractAsConfig, oversizeThreshold, isSecureTransport);
+            incorporateChildrenIntoMap(confObject, clazz, object, converterOptions);
         }
         return object;
     }
@@ -82,15 +74,10 @@ public class ConfiguredObjectToMapConver
     private void incorporateAttributesIntoMap(
             final ConfiguredObject<?> confObject,
             Map<String, Object> object,
-            final boolean useActualValues,
-            final boolean inheritedActuals,
-            final boolean includeSystemContext,
-            final boolean extractAsConfig,
-            final int oversizeThreshold,
-            final boolean isSecureTransport)
+            ConverterOptions converterOptions)
     {
         // if extracting as config add a fake attribute for each secondary parent
-        if(extractAsConfig && confObject.getModel().getParentTypes(confObject.getCategoryClass()).size()>1)
+        if(converterOptions.isExtractAsConfig() && confObject.getModel().getParentTypes(confObject.getCategoryClass()).size()>1)
         {
             Iterator<Class<? extends ConfiguredObject>> parentClasses =
                     confObject.getModel().getParentTypes(confObject.getCategoryClass()).iterator();
@@ -112,10 +99,10 @@ public class ConfiguredObjectToMapConver
 
         for(String name : confObject.getAttributeNames())
         {
-            if (!(extractAsConfig && CONFIG_EXCLUDED_ATTRIBUTES.contains(name)))
+            if (!(converterOptions.isExtractAsConfig() && CONFIG_EXCLUDED_ATTRIBUTES.contains(name)))
             {
                 Object value =
-                        useActualValues ? confObject.getActualAttributes().get(name) : confObject.getAttribute(name);
+                        converterOptions.isUseActualValues() ? confObject.getActualAttributes().get(name) : confObject.getAttribute(name);
                 if (value instanceof ConfiguredObject)
                 {
                     object.put(name, ((ConfiguredObject) value).getName());
@@ -123,17 +110,14 @@ public class ConfiguredObjectToMapConver
                 else if (ConfiguredObject.CONTEXT.equals(name))
                 {
                     Map<String, Object> contextValues = new HashMap<>();
-                    if (useActualValues)
+                    if (!converterOptions.isExcludeInheritedContext())
                     {
-                        collectContext(contextValues, confObject.getModel(), confObject, inheritedActuals);
-                    }
-                    else
-                    {
-                        for (String contextName : confObject.getContextKeys(!includeSystemContext))
-                        {
-                            contextValues.put(contextName, confObject.getContextValue(String.class, contextName));
-                        }
+                        contextValues.putAll(confObject.getModel().getTypeRegistry().getDefaultContext());
+                        contextValues.putAll(System.getenv());
+                        contextValues.putAll((Map) System.getProperties());
                     }
+                    collectContext(contextValues, confObject, converterOptions);
+
                     if (!contextValues.isEmpty())
                     {
                         object.put(ConfiguredObject.CONTEXT, contextValues);
@@ -162,21 +146,21 @@ public class ConfiguredObjectToMapConver
                             .getAttributeTypes(confObject.getClass())
                             .get(name);
 
-                    if (attribute.isSecureValue(value) && !(isSecureTransport && extractAsConfig))
+                    if (attribute.isSecureValue(value) && !(converterOptions.isSecureTransport() && converterOptions.isExtractAsConfig()))
                     {
                         // do not expose actual secure attribute value
                         // getAttribute() returns encoded value
                         value =  confObject.getAttribute(name);
                     }
 
-                    if(attribute.isOversized() && !extractAsConfig && !useActualValues)
+                    if(attribute.isOversized() && !converterOptions.isExtractAsConfig() && !converterOptions.isUseActualValues())
                     {
                         String valueString = String.valueOf(value);
-                        if(valueString.length() > oversizeThreshold)
+                        if(valueString.length() > converterOptions.getOversizeThreshold())
                         {
 
                             String replacementValue = "".equals(attribute.getOversizedAltText())
-                                    ? String.valueOf(value).substring(0, oversizeThreshold - 4) + "..."
+                                    ? String.valueOf(value).substring(0, converterOptions.getOversizeThreshold() - 4) + "..."
                                     : attribute.getOversizedAltText();
 
                             object.put(name, replacementValue);
@@ -191,7 +175,7 @@ public class ConfiguredObjectToMapConver
                         object.put(name, value);
                     }
                 }
-                else if (extractAsConfig)
+                else if (converterOptions.isExtractAsConfig())
                 {
                     ConfiguredObjectAttribute<?, ?> attribute = confObject.getModel()
                             .getTypeRegistry()
@@ -207,10 +191,11 @@ public class ConfiguredObjectToMapConver
         }
     }
 
-    private void collectContext(Map<String, Object> contextValues, Model model, ConfiguredObject<?> confObject, boolean inheritedContext)
+    private void collectContext(Map<String, Object> contextValues, ConfiguredObject<?> confObject, ConverterOptions options)
     {
+        Model model = confObject.getModel();
         Object value = confObject.getActualAttributes().get(ConfiguredObject.CONTEXT);
-        if (inheritedContext)
+        if (!options.isExcludeInheritedContext())
         {
             Collection<Class<? extends ConfiguredObject>> parents = model.getParentTypes(confObject.getCategoryClass());
             if(parents != null && !parents.isEmpty())
@@ -218,13 +203,23 @@ public class ConfiguredObjectToMapConver
                 ConfiguredObject parent = confObject.getParent(parents.iterator().next());
                 if(parent != null)
                 {
-                    collectContext(contextValues, model, parent, inheritedContext);
+                    collectContext(contextValues, parent, options);
                 }
             }
         }
         if (value instanceof Map)
         {
-            contextValues.putAll((Map<String,String>)value);
+            if (options.isUseActualValues())
+            {
+                contextValues.putAll((Map<String,String>)value);
+            }
+            else
+            {
+                for (String contextKey : ((Map<String,String>)value).keySet())
+                {
+                    contextValues.put(contextKey, confObject.getContextValue(String.class, contextKey));
+                }
+            }
         }
     }
 
@@ -244,14 +239,8 @@ public class ConfiguredObjectToMapConver
     private void incorporateChildrenIntoMap(
             final ConfiguredObject confObject,
             Class<? extends ConfiguredObject> clazz,
-            int depth,
             Map<String, Object> object,
-            final boolean useActualValues,
-            final boolean inheritedActuals,
-            final boolean includeSystemContext,
-            final boolean extractAsConfig,
-            final int oversizeThreshold,
-            final boolean isSecure)
+            ConverterOptions converterOptions)
     {
         List<Class<? extends ConfiguredObject>> childTypes = new ArrayList<>(confObject.getModel().getChildTypes(clazz));
 
@@ -263,9 +252,11 @@ public class ConfiguredObjectToMapConver
                 return o1.getSimpleName().compareTo(o2.getSimpleName());
             }
         });
+
+        ConverterOptions childConverterOptions = new ConverterOptions(converterOptions, converterOptions.getDepth() - 1);
         for(Class<? extends ConfiguredObject> childClass : childTypes)
         {
-            if(!(extractAsConfig && confObject.getModel().getParentTypes(childClass).iterator().next() != confObject.getCategoryClass()))
+            if(!(converterOptions.isExtractAsConfig() && confObject.getModel().getParentTypes(childClass).iterator().next() != confObject.getCategoryClass()))
             {
 
                 Collection children = confObject.getChildren(childClass);
@@ -283,19 +274,14 @@ public class ConfiguredObjectToMapConver
 
                     List<Map<String, Object>> childObjects = new ArrayList<>();
 
+
                     for (ConfiguredObject child : sortedChildren)
                     {
-                        if (!(extractAsConfig && !child.isDurable()))
+                        if (!(converterOptions.isExtractAsConfig() && !child.isDurable()))
                         {
                             childObjects.add(convertObjectToMap(child,
                                                                 childClass,
-                                                                depth - 1,
-                                                                useActualValues,
-                                                                inheritedActuals,
-                                                                includeSystemContext,
-                                                                extractAsConfig,
-                                                                oversizeThreshold,
-                                                                isSecure));
+                                                                childConverterOptions));
                         }
                     }
 
@@ -310,5 +296,68 @@ public class ConfiguredObjectToMapConver
     }
 
 
+    public static final class ConverterOptions
+    {
+        private final int _depth;
+        private final boolean _useActualValues;
+        private final boolean _extractAsConfig;
+        private final int _oversizeThreshold;
+        private final boolean _secureTransport;
+        private final boolean _excludeInheritedContext;
+
+        public ConverterOptions(ConverterOptions options, int depth)
+        {
+            this(depth,
+                 options.isUseActualValues(),
+                 options.isExtractAsConfig(),
+                 options.getOversizeThreshold(),
+                 options.isSecureTransport(),
+                 options.isExcludeInheritedContext());
+        }
 
+        public ConverterOptions(final int depth,
+                                final boolean useActualValues,
+                                final boolean extractAsConfig,
+                                final int oversizeThreshold,
+                                final boolean secureTransport,
+                                final boolean excludeInheritedContext)
+        {
+            _depth = depth;
+            _useActualValues = useActualValues;
+            _extractAsConfig = extractAsConfig;
+            _oversizeThreshold = oversizeThreshold;
+            _secureTransport = secureTransport;
+            _excludeInheritedContext = excludeInheritedContext;
+        }
+
+        public int getDepth()
+        {
+            return _depth;
+        }
+
+        public boolean isUseActualValues()
+        {
+            return _useActualValues;
+        }
+
+        public boolean isExtractAsConfig()
+        {
+            return _extractAsConfig;
+        }
+
+        public int getOversizeThreshold()
+        {
+            return _oversizeThreshold;
+        }
+
+        public boolean isSecureTransport()
+        {
+            return _secureTransport;
+        }
+
+        public boolean isExcludeInheritedContext()
+        {
+            return _excludeInheritedContext;
+        }
+    }
 }

Modified: qpid/java/branches/6.0.x/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/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java?rev=1742259&r1=1742258&r2=1742259&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java (original)
+++ qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java Wed May  4 12:24:59 2016
@@ -51,12 +51,12 @@ import org.apache.qpid.server.model.Abst
 import org.apache.qpid.server.model.Broker;
 import org.apache.qpid.server.model.ConfiguredObject;
 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.Content;
 import org.apache.qpid.server.model.Model;
-import org.apache.qpid.server.util.urlstreamhandler.data.Handler;
 import org.apache.qpid.server.util.ServerScopedRuntimeException;
+import org.apache.qpid.server.util.urlstreamhandler.data.Handler;
 import org.apache.qpid.util.DataUrlUtils;
 
 public class RestServlet extends AbstractServlet
@@ -74,6 +74,7 @@ public class RestServlet extends Abstrac
     public static final String INCLUDE_SYS_CONTEXT_PARAM = "includeSysContext";
     public static final String INHERITED_ACTUALS_PARAM = "inheritedActuals";
     public static final String EXTRACT_INITIAL_CONFIG_PARAM = "extractInitialConfig";
+    public static final String EXCLUDE_INHERITED_CONTEXT_PARAM = "excludeInheritedContext";
     public static final int SC_UNPROCESSABLE_ENTITY = 422;
 
     /**
@@ -81,7 +82,6 @@ public class RestServlet extends Abstrac
      * response with the value attachment.  This filename will be derived from the parameter value.
      */
     public static final String CONTENT_DISPOSITION_ATTACHMENT_FILENAME_PARAM = "contentDispositionAttachmentFilename";
-
     public static final Set<String> RESERVED_PARAMS =
             new HashSet<>(Arrays.asList(DEPTH_PARAM,
                                         SORT_PARAM,
@@ -90,7 +90,8 @@ public class RestServlet extends Abstrac
                                         INCLUDE_SYS_CONTEXT_PARAM,
                                         EXTRACT_INITIAL_CONFIG_PARAM,
                                         INHERITED_ACTUALS_PARAM,
-                                        CONTENT_DISPOSITION_ATTACHMENT_FILENAME_PARAM));
+                                        CONTENT_DISPOSITION_ATTACHMENT_FILENAME_PARAM,
+                                        EXCLUDE_INHERITED_CONTEXT_PARAM));
     public static final int DEFAULT_DEPTH = 1;
     public static final int DEFAULT_OVERSIZE = 120;
 
@@ -379,25 +380,82 @@ public class RestServlet extends Abstrac
 
                 int depth;
                 boolean actuals;
-                boolean includeSystemContext;
-                boolean inheritedActuals;
                 int oversizeThreshold;
+                boolean excludeInheritedContext;
 
                 if (extractInitialConfig)
                 {
                     depth = Integer.MAX_VALUE;
                     oversizeThreshold = Integer.MAX_VALUE;
                     actuals = true;
-                    includeSystemContext = false;
-                    inheritedActuals = false;
+                    excludeInheritedContext = true;
                 }
                 else
                 {
                     depth = getIntParameterFromRequest(request, DEPTH_PARAM, DEFAULT_DEPTH);
                     oversizeThreshold = getIntParameterFromRequest(request, OVERSIZE_PARAM, DEFAULT_OVERSIZE);
                     actuals = getBooleanParameterFromRequest(request, ACTUALS_PARAM);
-                    includeSystemContext = getBooleanParameterFromRequest(request, INCLUDE_SYS_CONTEXT_PARAM);
-                    inheritedActuals = getBooleanParameterFromRequest(request, INHERITED_ACTUALS_PARAM);
+                    String includeSystemContextParameter = request.getParameter(INCLUDE_SYS_CONTEXT_PARAM);
+                    String inheritedActualsParameter = request.getParameter(INHERITED_ACTUALS_PARAM);
+                    String excludeInheritedContextParameter = request.getParameter(EXCLUDE_INHERITED_CONTEXT_PARAM);
+
+                    if (excludeInheritedContextParameter == null)
+                    {
+                        /* backward (pre v6.1) compatible behaviour */
+                        if (inheritedActualsParameter == null && includeSystemContextParameter == null)
+                        {
+                            excludeInheritedContext = actuals;
+                        }
+                        else if (inheritedActualsParameter != null && includeSystemContextParameter != null)
+                        {
+                            if (actuals)
+                            {
+                                excludeInheritedContext = !Boolean.parseBoolean(inheritedActualsParameter);
+                            }
+                            else
+                            {
+                                excludeInheritedContext = !Boolean.parseBoolean(includeSystemContextParameter);
+                            }
+                        }
+                        else if (inheritedActualsParameter != null)
+                        {
+                            if (actuals)
+                            {
+                                excludeInheritedContext = !Boolean.parseBoolean(inheritedActualsParameter);
+                            }
+                            else
+                            {
+                                excludeInheritedContext = false;
+                            }
+                        }
+                        else
+                        {
+                            if (actuals)
+                            {
+                                excludeInheritedContext = true;
+                            }
+                            else
+                            {
+                                excludeInheritedContext = !Boolean.parseBoolean(includeSystemContextParameter);
+                            }
+                        }
+                    }
+                    else
+                    {
+                        if (inheritedActualsParameter != null || includeSystemContextParameter != null)
+                        {
+                            sendJsonErrorResponse(request,
+                                                  response,
+                                                  SC_UNPROCESSABLE_ENTITY,
+                                                  String.format(
+                                                          "Parameter '%s' cannot be specified together with '%s' or '%s'",
+                                                          EXCLUDE_INHERITED_CONTEXT_PARAM,
+                                                          INHERITED_ACTUALS_PARAM,
+                                                          INCLUDE_SYS_CONTEXT_PARAM));
+                            return;
+                        }
+                        excludeInheritedContext = Boolean.parseBoolean(excludeInheritedContextParameter);
+                    }
                 }
 
                 List<Map<String, Object>> output = new ArrayList<>();
@@ -405,7 +463,13 @@ public class RestServlet extends Abstrac
                 {
 
                     output.add(_objectConverter.convertObjectToMap(configuredObject, getConfiguredClass(),
-                            depth, actuals, inheritedActuals, includeSystemContext, extractInitialConfig, oversizeThreshold, request.isSecure()));
+                                                                   new ConfiguredObjectToMapConverter.ConverterOptions(
+                                                                           depth,
+                                                                           actuals,
+                                                                           extractInitialConfig,
+                                                                           oversizeThreshold,
+                                                                           request.isSecure(),
+                                                                           excludeInheritedContext)));
                 }
 
 
@@ -640,10 +704,18 @@ public class RestServlet extends Abstrac
         }
         else
         {
+            final ConfiguredObjectToMapConverter.ConverterOptions converterOptions =
+                    new ConfiguredObjectToMapConverter.ConverterOptions(DEFAULT_DEPTH,
+                                                                        false,
+                                                                        false,
+                                                                        DEFAULT_OVERSIZE,
+                                                                        request.isSecure(),
+                                                                        true);
             if (ConfiguredObject.class.isAssignableFrom(operation.getReturnType()))
             {
-                returnVal = _objectConverter.convertObjectToMap((ConfiguredObject<?>) returnVal, operation.getReturnType(), DEFAULT_DEPTH,
-                                                                false, false, false, false, DEFAULT_OVERSIZE, request.isSecure());
+                returnVal = _objectConverter.convertObjectToMap((ConfiguredObject<?>) returnVal,
+                                                                operation.getReturnType(),
+                                                                converterOptions);
             }
             else if (returnsCollectionOfConfiguredObjects(operation))
             {
@@ -651,8 +723,8 @@ public class RestServlet extends Abstrac
                 for (Object configuredObject : (Collection)returnVal)
                 {
                     output.add(_objectConverter.convertObjectToMap((ConfiguredObject<?>) configuredObject,
-                               getCollectionMemberType((ParameterizedType) operation.getGenericReturnType()),
-                               DEFAULT_DEPTH, false, false, false, false, DEFAULT_OVERSIZE, request.isSecure()));
+                                                                   getCollectionMemberType((ParameterizedType) operation.getGenericReturnType()),
+                                                                   converterOptions));
                 }
                 returnVal = output;
             }
@@ -1013,7 +1085,16 @@ public class RestServlet extends Abstrac
 
     private boolean getBooleanParameterFromRequest(HttpServletRequest request, final String paramName)
     {
-        return Boolean.parseBoolean(request.getParameter(paramName));
+        return getBooleanParameterFromRequest(request, paramName, false);
     }
 
+    private boolean getBooleanParameterFromRequest(HttpServletRequest request, final String paramName, final boolean defaultValue)
+    {
+        String value = request.getParameter(paramName);
+        if (value == null)
+        {
+            return defaultValue;
+        }
+        return Boolean.parseBoolean(value);
+    }
 }

Modified: qpid/java/branches/6.0.x/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java?rev=1742259&r1=1742258&r2=1742259&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java (original)
+++ qpid/java/branches/6.0.x/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java Wed May  4 12:24:59 2016
@@ -41,6 +41,9 @@ import org.apache.qpid.server.model.Conf
 import org.apache.qpid.server.model.ConfiguredObjectMethodAttribute;
 import org.apache.qpid.server.model.ConfiguredObjectTypeRegistry;
 import org.apache.qpid.server.model.Model;
+import org.apache.qpid.server.model.testmodels.hierarchy.TestCar;
+import org.apache.qpid.server.model.testmodels.hierarchy.TestElecEngineImpl;
+import org.apache.qpid.server.model.testmodels.hierarchy.TestEngine;
 import org.apache.qpid.test.utils.QpidTestCase;
 
 public class ConfiguredObjectToMapConverterTest extends QpidTestCase
@@ -63,13 +66,13 @@ public class ConfiguredObjectToMapConver
 
         Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject,
                                                                       ConfiguredObject.class,
-                                                                      0,
-                                                                      false,
-                                                                      false,
-                                                                      false,
-                                                                      false,
-                                                                      120,
-                                                                      false);
+                                                                      new ConfiguredObjectToMapConverter.ConverterOptions(
+                                                                              0,
+                                                                              false,
+                                                                              false,
+                                                                              120,
+                                                                              false,
+                                                                              false));
         Map<String, Object> statsAsMap = (Map<String, Object>) resultMap.get(STATISTICS_MAP_KEY);
         assertNotNull("Statistics should be part of map", statsAsMap);
         assertEquals("Unexpected number of statistics", 1, statsAsMap.size());
@@ -86,13 +89,13 @@ public class ConfiguredObjectToMapConver
 
         Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject,
                                                                       ConfiguredObject.class,
-                                                                      0,
-                                                                      false,
-                                                                      false,
-                                                                      false,
-                                                                      false,
-                                                                      120,
-                                                                      false);
+                                                                      new ConfiguredObjectToMapConverter.ConverterOptions(
+                                                                              0,
+                                                                              false,
+                                                                              false,
+                                                                              120,
+                                                                              false,
+                                                                              false));
         assertEquals("Unexpected number of attributes", 1, resultMap.size());
         assertEquals("Unexpected attribute value", attributeValue, resultMap.get(attributeName));
     }
@@ -111,13 +114,13 @@ public class ConfiguredObjectToMapConver
 
         Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject,
                                                                       ConfiguredObject.class,
-                                                                      0,
-                                                                      false,
-                                                                      false,
-                                                                      false,
-                                                                      false,
-                                                                      120,
-                                                                      false);
+                                                                      new ConfiguredObjectToMapConverter.ConverterOptions(
+                                                                              0,
+                                                                              false,
+                                                                              false,
+                                                                              120,
+                                                                              false,
+                                                                              false));
         assertEquals("Unexpected number of attributes", 1, resultMap.size());
         assertEquals("Unexpected attribute value", "attributeConfiguredObjectName", resultMap.get(attributeName));
     }
@@ -137,13 +140,13 @@ public class ConfiguredObjectToMapConver
 
         Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject,
                                                                       ConfiguredObject.class,
-                                                                      1,
-                                                                      false,
-                                                                      false,
-                                                                      false,
-                                                                      false,
-                                                                      120,
-                                                                      false);
+                                                                      new ConfiguredObjectToMapConverter.ConverterOptions(
+                                                                              1,
+                                                                              false,
+                                                                              false,
+                                                                              120,
+                                                                              false,
+                                                                              false));
         assertEquals("Unexpected parent map size", 1, resultMap.size());
 
         final List<Map<String, Object>> childList = (List<Map<String, Object>>) resultMap.get("testchilds");
@@ -182,13 +185,13 @@ public class ConfiguredObjectToMapConver
 
         Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject,
                                                                       ConfiguredObject.class,
-                                                                      1,
-                                                                      true,
-                                                                      false,
-                                                                      false,
-                                                                      false,
-                                                                      120,
-                                                                      false);
+                                                                      new ConfiguredObjectToMapConverter.ConverterOptions(
+                                                                              1,
+                                                                              true,
+                                                                              false,
+                                                                              120,
+                                                                              false,
+                                                                              true));
         assertEquals("Unexpected parent map size", 2, resultMap.size());
         assertEquals("Incorrect context", resultMap.get(ConfiguredObject.CONTEXT), actualContext);
         List<Map<String, Object>> childList = (List<Map<String, Object>>) resultMap.get("testchilds");
@@ -201,18 +204,16 @@ public class ConfiguredObjectToMapConver
 
         resultMap = _converter.convertObjectToMap(_configuredObject,
                                                   ConfiguredObject.class,
-                                                  1,
-                                                  false,
-                                                  false,
-                                                  false,
-                                                  false,
-                                                  120,
-                                                  false);
+                                                  new ConfiguredObjectToMapConverter.ConverterOptions(1,
+                                                                                                      false,
+                                                                                                      false,
+                                                                                                      120,
+                                                                                                      false,
+                                                                                                      true));
         assertEquals("Unexpected parent map size", 2, resultMap.size());
-        Map<String, Object> inheritedContext = new HashMap<>();
-        inheritedContext.put("key","value");
-        inheritedContext.put("inheritedkey","foo");
-        assertEquals("Incorrect context", inheritedContext, resultMap.get(ConfiguredObject.CONTEXT));
+        Map<String, Object> effectiveContext = new HashMap<>();
+        effectiveContext.put("key","value");
+        assertEquals("Incorrect context", effectiveContext, resultMap.get(ConfiguredObject.CONTEXT));
         childList = (List<Map<String, Object>>) resultMap.get("testchilds");
         assertEquals("Unexpected number of children", 1, childList.size());
         childMap = childList.get(0);
@@ -243,14 +244,14 @@ public class ConfiguredObjectToMapConver
 
 
          Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject,
-                                                                            ConfiguredObject.class,
-                                                                            1,
-                                                                            false,
-                                                                            false,
-                                                                            false,
-                                                                            false,
-                                                                            20,
-                                                                            false);
+                                                                       ConfiguredObject.class,
+                                                                       new ConfiguredObjectToMapConverter.ConverterOptions(
+                                                                               1,
+                                                                               false,
+                                                                               false,
+                                                                               20,
+                                                                               false,
+                                                                               false));
         Object children = resultMap.get("testchilds");
         assertNotNull(children);
         assertTrue(children instanceof Collection);
@@ -263,13 +264,12 @@ public class ConfiguredObjectToMapConver
 
         resultMap = _converter.convertObjectToMap(_configuredObject,
                                                   ConfiguredObject.class,
-                                                  1,
-                                                  false,
-                                                  false,
-                                                  false,
-                                                  false,
-                                                  8,
-                                                  false);
+                                                  new ConfiguredObjectToMapConverter.ConverterOptions(1,
+                                                                                                      false,
+                                                                                                      false,
+                                                                                                      8,
+                                                                                                      false,
+                                                                                                      false));
 
         children = resultMap.get("testchilds");
         assertNotNull(children);
@@ -286,13 +286,12 @@ public class ConfiguredObjectToMapConver
 
         resultMap = _converter.convertObjectToMap(_configuredObject,
                                                   ConfiguredObject.class,
-                                                  1,
-                                                  false,
-                                                  false,
-                                                  false,
-                                                  false,
-                                                  8,
-                                                  false);
+                                                  new ConfiguredObjectToMapConverter.ConverterOptions(1,
+                                                                                                      false,
+                                                                                                      false,
+                                                                                                      8,
+                                                                                                      false,
+                                                                                                      false));
 
         children = resultMap.get("testchilds");
         assertNotNull(children);
@@ -331,14 +330,14 @@ public class ConfiguredObjectToMapConver
         when(mockChild.isDurable()).thenReturn(true);
 
         Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject,
-                ConfiguredObject.class,
-                1,
-                false,
-                false,
-                false,
-                false,
-                20,
-                false);
+                                                                      ConfiguredObject.class,
+                                                                      new ConfiguredObjectToMapConverter.ConverterOptions(
+                                                                              1,
+                                                                              false,
+                                                                              false,
+                                                                              20,
+                                                                              false,
+                                                                              false));
         Object children = resultMap.get("testchilds");
         assertNotNull(children);
         assertTrue(children instanceof Collection);
@@ -348,14 +347,13 @@ public class ConfiguredObjectToMapConver
         assertEquals("*****", ((Map) attrs).get("secureAttribute"));
 
         resultMap = _converter.convertObjectToMap(_configuredObject,
-                ConfiguredObject.class,
-                1,
-                true,
-                true,
-                false,
-                true,
-                20,
-                true);
+                                                  ConfiguredObject.class,
+                                                  new ConfiguredObjectToMapConverter.ConverterOptions(1,
+                                                                                                      true,
+                                                                                                      true,
+                                                                                                      20,
+                                                                                                      true,
+                                                                                                      false));
 
         children = resultMap.get("testchilds");
         assertNotNull(children);
@@ -366,14 +364,13 @@ public class ConfiguredObjectToMapConver
         assertEquals("secret", ((Map) attrs).get("secureAttribute"));
 
         resultMap = _converter.convertObjectToMap(_configuredObject,
-                ConfiguredObject.class,
-                1,
-                true,
-                true,
-                false,
-                false,
-                20,
-                true);
+                                                  ConfiguredObject.class,
+                                                  new ConfiguredObjectToMapConverter.ConverterOptions(1,
+                                                                                                      true,
+                                                                                                      false,
+                                                                                                      20,
+                                                                                                      true,
+                                                                                                      false));
 
         children = resultMap.get("testchilds");
         assertNotNull(children);
@@ -384,6 +381,114 @@ public class ConfiguredObjectToMapConver
         assertEquals("*****", ((Map) attrs).get("secureAttribute"));
     }
 
+    public void testExcludeInheritedContext()
+    {
+        Model model = org.apache.qpid.server.model.testmodels.hierarchy.TestModel.getInstance();
+        final Map<String, Object> carAttributes = new HashMap<>();
+        carAttributes.put(ConfiguredObject.NAME, "myCar");
+        carAttributes.put(ConfiguredObject.CONTEXT, Collections.singletonMap("parentTest", "parentTestValue"));
+        TestCar car = model.getObjectFactory().create(TestCar.class,
+                                                      carAttributes);
+        final Map<String, Object> engineAttributes = new HashMap<>();
+        engineAttributes.put(ConfiguredObject.NAME, "myEngine");
+        engineAttributes.put(ConfiguredObject.TYPE, TestElecEngineImpl.TEST_ELEC_ENGINE_TYPE);
+        engineAttributes.put(ConfiguredObject.CONTEXT, Collections.singletonMap("test", "testValue"));
+        TestEngine engine = (TestEngine) car.createChild(TestEngine.class, engineAttributes);
+
+        Map<String, Object> resultMap = _converter.convertObjectToMap(engine,
+                                                                      ConfiguredObject.class,
+                                                                      new ConfiguredObjectToMapConverter.ConverterOptions(
+                                                                              1,
+                                                                              false,
+                                                                              false,
+                                                                              0,
+                                                                              false,
+                                                                              false));
+        Object contextValue = resultMap.get("context");
+        assertTrue("Unexpected type of context", contextValue instanceof Map);
+        assertTrue("Unexpected size of context", ((Map)contextValue).size() > 1);
+        assertEquals("Unexpected context content", "testValue", ((Map)contextValue).get("test"));
+        assertEquals("Unexpected context content", "parentTestValue", ((Map)contextValue).get("parentTest"));
+
+        resultMap = _converter.convertObjectToMap(engine,
+                                                  ConfiguredObject.class,
+                                                  new ConfiguredObjectToMapConverter.ConverterOptions(1,
+                                                                                                      false,
+                                                                                                      false,
+                                                                                                      0,
+                                                                                                      false,
+                                                                                                      true));
+        contextValue = resultMap.get("context");
+        assertTrue("Unexpected type of context", contextValue instanceof Map);
+        assertEquals("Unexpected size of context", 1, ((Map)contextValue).size());
+        assertEquals("Unexpected context content","testValue", ((Map)contextValue).get("test"));
+
+
+
+
+
+        /*
+
+
+
+//        Model model = createTestModel();
+        ConfiguredObjectTypeRegistry typeRegistry = model.getTypeRegistry();
+        Map<String, ConfiguredObjectAttribute<?, ?>> attributeTypes = typeRegistry.getAttributeTypes(TestChild.class);
+        ConfiguredObjectAttribute contextAttribute = mock(ConfiguredObjectMethodAttribute.class);
+        when(attributeTypes.get(eq("context"))).thenReturn(contextAttribute);
+
+        TestChild mockChild = mock(TestChild.class);
+        when(mockChild.getModel()).thenReturn(model);
+        when(mockChild.getCategoryClass()).thenReturn(TestChild.class);
+        when(mockChild.getParent(Matchers.<Class>any())).thenReturn(_configuredObject);
+        when(_configuredObject.getModel()).thenReturn(model);
+        when(_configuredObject.getChildren(TestChild.class)).thenReturn(Arrays.asList(mockChild));
+        when(model.getParentTypes(TestChild.class)).thenReturn(Collections.<Class<? extends ConfiguredObject>>singleton(TestChild.class));
+        when(_configuredObject.getCategoryClass()).thenReturn(TestChild.class);
+
+
+        // set encoded value
+        final Map<String,String> context = new HashMap<>();
+        context.put("test", "testValue");
+        configureMockToReturnOneAttribute(mockChild, "context", context);
+        when(mockChild.getContextKeys(anyBoolean())).thenReturn(context.keySet());
+        when(mockChild.getContextValue(String.class, "test")).thenReturn(context.get("test"));
+
+        final Map<String, String> parentContext = new HashMap<>();
+        parentContext.put("parentTest", "parentTestValue");
+        configureMockToReturnOneAttribute(_configuredObject, "context", parentContext);
+        when(_configuredObject.getContextKeys(anyBoolean())).thenReturn(parentContext.keySet());
+        when(_configuredObject.getContextValue(String.class, "parentTest")).thenReturn(parentContext.get("parentTest"));
+
+        Map<String, Object> resultMap = _converter.convertObjectToMap(mockChild,
+                                                                      ConfiguredObject.class,
+                                                                      new ConfiguredObjectToMapConverter.ConverterOptions(
+                                                                              1,
+                                                                              false,
+                                                                              false,
+                                                                              0,
+                                                                              false,
+                                                                              false));
+        Object contextValue = resultMap.get("context");
+        assertTrue("Unexpected type of context", contextValue instanceof Map);
+        assertEquals("Unexpected size of context", 2, ((Map)contextValue).size());
+        assertEquals("Unexpected context content", "testValue", ((Map)contextValue).get("test"));
+        assertEquals("Unexpected context content", "parentTestValue", ((Map)contextValue).get("parentTest"));
+
+        resultMap = _converter.convertObjectToMap(mockChild,
+                                                  ConfiguredObject.class,
+                                                  new ConfiguredObjectToMapConverter.ConverterOptions(1,
+                                                                                                      false,
+                                                                                                      false,
+                                                                                                      0,
+                                                                                                      false,
+                                                                                                      true));
+        contextValue = resultMap.get("context");
+        assertTrue("Unexpected type of context", contextValue instanceof Map);
+        assertEquals("Unexpected size of context", 1, ((Map)contextValue).size());
+        assertEquals("Unexpected context content","testValue", ((Map)contextValue).get("test"));*/
+    }
+
     private Model createTestModel()
     {
         Model model = mock(Model.class);



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


Mime
View raw message