cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1405642 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/client/AbstractClient.java test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
Date Sun, 04 Nov 2012 21:43:03 GMT
Author: sergeyb
Date: Sun Nov  4 21:43:02 2012
New Revision: 1405642

URL: http://svn.apache.org/viewvc?rev=1405642&view=rev
Log:
Fixing the regression in the way empty query parameters are handled

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1405642&r1=1405641&r2=1405642&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Sun Nov  4 21:43:02 2012
@@ -617,47 +617,54 @@ public abstract class AbstractClient imp
                                                  String paramName, 
                                                  ParameterType pt,
                                                  Object... pValues) {
-        if (pValues == null) {
-            throw new IllegalArgumentException("Null parameters are not supported");
-        }
         if (pt != ParameterType.MATRIX && pt != ParameterType.QUERY) {
             throw new IllegalArgumentException("This method currently deal "
                                                + "with matrix and query parameters only");
         }
         if (!"".equals(paramName)) {
-            for (Object pValue : pValues) {
-                if (InjectionUtils.isSupportedCollectionOrArray(pValue.getClass())) {
-                    Collection<?> c = pValue.getClass().isArray() 
-                        ? Arrays.asList((Object[]) pValue) : (Collection<?>) pValue;
-                    for (Iterator<?> it = c.iterator(); it.hasNext();) {
-                        addMatrixOrQueryToBuilder(ub, paramName, it.next(), pt);
+            if (pValues != null && pValues.length > 0) {
+                for (Object pValue : pValues) {
+                    if (InjectionUtils.isSupportedCollectionOrArray(pValue.getClass())) {
+                        Collection<?> c = pValue.getClass().isArray() 
+                            ? Arrays.asList((Object[]) pValue) : (Collection<?>) pValue;
+                        for (Iterator<?> it = c.iterator(); it.hasNext();) {
+                            convertMatrixOrQueryToBuilder(ub, paramName, it.next(), pt);
+                        }
+                    } else { 
+                        convertMatrixOrQueryToBuilder(ub, paramName, pValue, pt); 
                     }
-                } else { 
-                    addMatrixOrQueryToBuilder(ub, paramName, pValue, pt); 
                 }
-            }    
-                    
+            } else {
+                addMatrixOrQueryToBuilder(ub, paramName, pt, pValues);    
+            }
         } else {
             Object pValue = pValues[0];
             MultivaluedMap<String, Object> values = 
                 InjectionUtils.extractValuesFromBean(pValue, "");
             for (Map.Entry<String, List<Object>> entry : values.entrySet()) {
                 for (Object v : entry.getValue()) {
-                    addMatrixOrQueryToBuilder(ub, entry.getKey(), v, pt);
+                    convertMatrixOrQueryToBuilder(ub, entry.getKey(), v, pt);
                 }
             }
         }
     }
 
-    private void addMatrixOrQueryToBuilder(UriBuilder ub, 
+    private void convertMatrixOrQueryToBuilder(UriBuilder ub, 
                                            String paramName, 
                                            Object pValue,
                                            ParameterType pt) {
         Object convertedValue = convertParamValue(pValue);
+        addMatrixOrQueryToBuilder(ub, paramName, pt, convertedValue);
+    }
+    
+    private void addMatrixOrQueryToBuilder(UriBuilder ub, 
+                                           String paramName, 
+                                           ParameterType pt,
+                                           Object... pValue) {
         if (pt == ParameterType.MATRIX) {
-            ub.matrixParam(paramName, convertedValue);
+            ub.matrixParam(paramName, pValue);
         } else {
-            ub.queryParam(paramName, convertedValue);
+            ub.queryParam(paramName, pValue);
         }
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java?rev=1405642&r1=1405641&r2=1405642&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
Sun Nov  4 21:43:02 2012
@@ -97,6 +97,13 @@ public class WebClientTest extends Asser
     }
     
     @Test 
+    public void testEmptyQuery() {
+        WebClient wc = WebClient.create("http://foo");
+        wc.query("_wadl");
+        assertEquals("http://foo?_wadl", wc.getCurrentURI().toString());
+    }
+    
+    @Test 
     public void testForward() {
         WebClient wc = WebClient.create("http://foo");
         wc.to("http://foo/bar", true);



Mime
View raw message