Index: httpcore/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java =================================================================== --- httpcore/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java (revision 609160) +++ httpcore/module-main/src/test/java/org/apache/http/params/TestBasicHttpParams.java (working copy) @@ -31,6 +31,9 @@ package org.apache.http.params; +import java.util.Set; +import java.util.HashSet; + import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -94,4 +97,32 @@ "something", copy.getParameter("parent+")); } + + public void testCollectNames() { + BasicHttpParams granny = new BasicHttpParams(); + BasicHttpParams parent = new BasicHttpParams(granny); + BasicHttpParams child = new BasicHttpParams(parent); + parent.setParameter("p1", "something"); + parent.setParameter("p2", "something"); + child.setParameter("c1", "something"); + child.setParameter("c2", "something"); + + Set names = new HashSet(); + granny.collectParameterNames(names); + assertEquals("wrong number of granny param names", 0, names.size()); + + names.clear(); + parent.collectParameterNames(names); + assertEquals("wrong number of parent param names", 2, names.size()); + assertTrue(names.contains("p1")); + assertTrue(names.contains("p2")); + + names.clear(); + child.collectParameterNames(names); + assertEquals("wrong number of child param names", 4, names.size()); + assertTrue(names.contains("p1")); + assertTrue(names.contains("p2")); + assertTrue(names.contains("c1")); + assertTrue(names.contains("c2")); + } } Index: httpcore/module-main/src/main/java/org/apache/http/params/HttpParams.java =================================================================== --- httpcore/module-main/src/main/java/org/apache/http/params/HttpParams.java (revision 609160) +++ httpcore/module-main/src/main/java/org/apache/http/params/HttpParams.java (working copy) @@ -31,10 +31,15 @@ package org.apache.http.params; + +import java.util.Set; + + /** * Represents a collection of HTTP protocol and framework parameters. * * @author Oleg Kalnichevski + * @author and others * * @version $Revision$ * @@ -64,6 +69,30 @@ HttpParams setParameter(String name, Object value); /** + * Collects the parameter names. + * The names of the defined parameters will be added to the argument set + * as String objects. + * This is an expensive operation that should be used with care. + * Implementations that form hierarchies or otherwise reference multiple + * instances of this interface are expected to pass this call on to the + * referenced instances. + *
+ * Note: + * There may be implementations that cannot provide all parameter names, + * for example because the lookup is technically not possible, or + * requires additional privileges, or simply because the set would be + * too large. Such implementations may collect only a subset of parameter + * names, which may even be an empty set. + *
+ * Note: + * Some parameters may be set to null. The names of these + * parameters will still appear in the result set. + * + * @param names the set in which parameter names shall be collected + */ + void collectParameterNames(Set names); + + /** * Creates a copy of these parameters. * * @return a new set of parameters holding the same values as this one Index: httpcore/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java =================================================================== --- httpcore/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java (revision 609160) +++ httpcore/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java (working copy) @@ -33,6 +33,7 @@ import java.io.Serializable; import java.util.Map; +import java.util.Set; import java.util.HashMap; import java.util.Iterator; @@ -139,6 +140,22 @@ } } + public void collectParameterNames(Set names) { + if (names == null) { + throw new IllegalArgumentException + ("Set in which to collect must not be null."); + } + // The order in which the defaults and the local parameter names are + // added should not matter. But assuming that many parameters are set + // as defaults and few locally, this could perform a trifle better. + if (this.defaults != null) { + this.defaults.collectParameterNames(names); + } + if (this.parameters != null) { + names.addAll(this.parameters.keySet()); + } + } + public boolean isParameterSet(final String name) { return getParameter(name) != null; } Index: httpclient/module-client/src/main/java/org/apache/http/impl/client/ClientParamsStack.java =================================================================== --- httpclient/module-client/src/main/java/org/apache/http/impl/client/ClientParamsStack.java (revision 609152) +++ httpclient/module-client/src/main/java/org/apache/http/impl/client/ClientParamsStack.java (working copy) @@ -32,6 +32,8 @@ package org.apache.http.impl.client; +import java.util.Set; + import org.apache.http.params.HttpParams; import org.apache.http.params.AbstractHttpParams; @@ -249,6 +251,30 @@ } + // non-JavaDoc, see interface HttpParams + public void collectParameterNames(Set names) { + if (names == null) { + throw new IllegalArgumentException + ("Set in which to collect must not be null."); + } + // The order in which the defaults and the local parameter names are + // added should not matter. We're going top down, assuming that many + // parameters are set higher up and fewer further down. + if (applicationParams != null) { + applicationParams.collectParameterNames(names); + } + if (clientParams != null) { + clientParams.collectParameterNames(names); + } + if (requestParams != null) { + requestParams.collectParameterNames(names); + } + if (overrideParams != null) { + overrideParams.collectParameterNames(names); + } + } + + /** * Does not set a parameter. * Parameter stacks are read-only. It is possible, though discouraged,