This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.1.x-fixes by this push:
     new 6b7aa4f  [CXF-7652] UriBuilderImpl: null-empty differentiation for 
query/matrix param
6b7aa4f is described below

commit 6b7aa4f2ed0fce60dd4fb97d0b7bca1870691422
Author: Alexey Markevich <amarkev...@talend.com>
AuthorDate: Wed Feb 21 11:52:03 2018 +0300

    [CXF-7652] UriBuilderImpl: null-empty differentiation for query/matrix
    param
---
 .../org/apache/cxf/jaxrs/impl/UriBuilderImpl.java  | 32 ++++++++++---------
 .../org/apache/cxf/jaxrs/utils/JAXRSUtils.java     | 28 ++++++++---------
 .../test/java/org/apache/cxf/jaxrs/Customer.java   | 16 +++++-----
 .../org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java | 36 ++++++++++++----------
 .../systest/jaxrs/JAXRS20ClientServerBookTest.java |  2 +-
 5 files changed, 60 insertions(+), 54 deletions(-)

diff --git 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
index 62e39b8..fbda422 100644
--- 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
+++ 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
@@ -807,7 +807,7 @@ public class UriBuilderImpl extends UriBuilder implements 
Cloneable {
      */
     private List<String> toStringList(boolean encodeSlash, Object... values) 
throws IllegalArgumentException {
         List<String> list = new ArrayList<String>();
-        if (values != null) {
+        if (values != null && values.length > 0) {
             for (int i = 0; i < values.length; i++) {
                 Object value = values[i];
                 if (value == null) {
@@ -819,9 +819,8 @@ public class UriBuilderImpl extends UriBuilder implements 
Cloneable {
                 }
                 list.add(strValue);
             }
-        }
-        if (list.isEmpty()) {
-            list.add("");
+        } else {
+            list.add(null);
         }
         return list;
     }
@@ -841,18 +840,21 @@ public class UriBuilderImpl extends UriBuilder implements 
Cloneable {
             Map.Entry<String, List<String>> entry = it.next();
             for (Iterator<String> sit = entry.getValue().iterator(); 
sit.hasNext();) {
                 String val = sit.next();
-                boolean templateValue = val.startsWith("{") && 
val.endsWith("}");
-                if (!templateValue) { 
-                    val = HttpUtils.encodePartiallyEncoded(val, isQuery);
-                    if (!isQuery) {
-                        val = val.replaceAll("/", "%2F");
-                    }
-                } else {
-                    val = 
URITemplate.createExactTemplate(val).encodeLiteralCharacters(isQuery);
-                }
                 b.append(entry.getKey());
-                if (val.length() != 0) {
-                    b.append('=').append(val);
+                if (val != null) {
+                    boolean templateValue = val.startsWith("{") && 
val.endsWith("}");
+                    if (!templateValue) {
+                        val = HttpUtils.encodePartiallyEncoded(val, isQuery);
+                        if (!isQuery) {
+                            val = val.replaceAll("/", "%2F");
+                        }
+                    } else {
+                        val = 
URITemplate.createExactTemplate(val).encodeLiteralCharacters(isQuery);
+                    }
+                    b.append('=');
+                    if (!val.isEmpty()) {
+                        b.append(val);
+                    }
                 }
                 if (sit.hasNext() || it.hasNext()) {
                     b.append(separator);
diff --git 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
index 6eebcc6..2c316a1 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
@@ -1262,16 +1262,14 @@ public final class JAXRSUtils {
                                            String sep, 
                                            boolean decode,
                                            boolean decodePlus,
-                                           boolean valueIsCollection) {    
-        if (!StringUtils.isEmpty(query)) {            
-            List<String> parts = Arrays.asList(StringUtils.split(query, sep));
-            for (String part : parts) {
+                                           boolean valueIsCollection) {
+        if (!StringUtils.isEmpty(query)) {
+            for (String part : query.split(sep)) { // fastpath expected
                 int index = part.indexOf('=');
-                String name = null;
+                final String name;
                 String value = null;
                 if (index == -1) {
                     name = part;
-                    value = "";
                 } else {
                     name = part.substring(0, index);
                     value =  index < part.length() ? part.substring(index + 1) 
: "";
@@ -1292,14 +1290,16 @@ public final class JAXRSUtils {
                                                String name,
                                                String value,
                                                boolean decode,
-                                               boolean decodePlus) {    
-        
-        if (decodePlus && value.contains("+")) {
-            value = value.replace('+', ' ');
-        }
-        if (decode) {
-            value = (";".equals(sep))
-                ? HttpUtils.pathDecode(value) : HttpUtils.urlDecode(value); 
+                                               boolean decodePlus) {
+
+        if (value != null) {
+            if (decodePlus && value.contains("+")) {
+                value = value.replace('+', ' ');
+            }
+            if (decode) {
+                value = (";".equals(sep))
+                    ? HttpUtils.pathDecode(value) : HttpUtils.urlDecode(value);
+            }
         }
         
         queries.add(HttpUtils.urlDecode(name), value);
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
index 9f23023..a30f0cb 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
@@ -402,20 +402,22 @@ public class Customer extends AbstractCustomer implements 
CustomerInfo {
                                 @PathParam("ps") String path) {
         // complete
     }
-    
-    @Produces("text/xml")   
-    public void testMultipleQuery(@QueryParam("query")  String queryString, 
+    @Produces("text/xml")
+    //CHECKSTYLE:OFF: checkstyle:parameternumber
+    public void testMultipleQuery(@QueryParam("query")  String queryString,
                                   @QueryParam("query2") String queryString2,
                                   @QueryParam("query3") Long queryString3,
                                   @QueryParam("query4") boolean queryBoolean4,
                                   @QueryParam("query5") char queryChar5,
                                   @QueryParam("query6") String queryString6,
-                                  @QueryParam("query7") Boolean queryString7) {
+                                  @QueryParam("query7") Boolean queryString7,
+                                  @QueryParam("query8") String queryString8) {
         // complete
     }
-    
-    @Produces("text/xml")   
-    public void testMatrixParam(@MatrixParam("p1") String mp1, 
+    //CHECKSTYLE:ON: checkstyle:parameternumber
+
+    @Produces("text/xml")
+    public void testMatrixParam(@MatrixParam("p1") String mp1,
                                 @MatrixParam("p2") String mp2,
                                 @MatrixParam("p3") String mp3,
                                 @MatrixParam("p4") String mp4,
diff --git 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
index a72c3c6..1cfb7fa 100644
--- 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
+++ 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
@@ -824,9 +824,9 @@ public class JAXRSUtilsTest extends Assert {
         Class<?>[] argType = {String.class, Integer.TYPE, String.class, 
String.class};
         Method m = Customer.class.getMethod("testQuery", argType);
         Message messageImpl = createMessage();
-        
-        messageImpl.put(Message.QUERY_STRING, "query=24&query2");
-        List<Object> params = JAXRSUtils.processParameters(new 
OperationResourceInfo(m, 
+
+        messageImpl.put(Message.QUERY_STRING, "query=24&query2=");
+        List<Object> params = JAXRSUtils.processParameters(new 
OperationResourceInfo(m,
                                                                new 
ClassResourceInfo(Customer.class)),
                                                            null, 
                                                            messageImpl);
@@ -901,9 +901,9 @@ public class JAXRSUtilsTest extends Assert {
         Message messageImpl = createMessage();
         ProviderFactory.getInstance(messageImpl)
             .registerUserProvider(new MyTypeParamConverterProvider());
-        messageImpl.put(Message.QUERY_STRING, 
-                
"query2=query2Value&query2=query2Value2&query3=1&query3=2&query4");
-        List<Object> params = JAXRSUtils.processParameters(new 
OperationResourceInfo(m, 
+        messageImpl.put(Message.QUERY_STRING,
+                
"query2=query2Value&query2=query2Value2&query3=1&query3=2&query4=");
+        List<Object> params = JAXRSUtils.processParameters(new 
OperationResourceInfo(m,
                                                                new 
ClassResourceInfo(Customer.class)),
                                                            null, 
                                                            messageImpl);
@@ -1473,12 +1473,12 @@ public class JAXRSUtilsTest extends Assert {
     @Test
     public void testMultipleQueryParameters() throws Exception {
         Class<?>[] argType = {String.class, String.class, Long.class,
-                              Boolean.TYPE, char.class, String.class, 
Boolean.class};
+                              Boolean.TYPE, char.class, String.class, 
Boolean.class, String.class};
         Method m = Customer.class.getMethod("testMultipleQuery", argType);
         Message messageImpl = createMessage();
 
         messageImpl.put(Message.QUERY_STRING,
-                        
"query=first&query2=second&query3=3&query4=true&query6&query7=true");
+                        
"query=first&query2=second&query3=3&query4=true&query6=&query7=true&query8");
         List<Object> params = JAXRSUtils.processParameters(new 
OperationResourceInfo(m,
                                                                new 
ClassResourceInfo(Customer.class)),
                                                            null, messageImpl);
@@ -1486,16 +1486,18 @@ public class JAXRSUtilsTest extends Assert {
                      params.get(0));
         assertEquals("Second Query Parameter of multiple was not matched 
correctly", 
                      "second", params.get(1));
-        assertEquals("Third Query Parameter of multiple was not matched 
correctly", 
-                     new Long(3), params.get(2));
+        assertEquals("Third Query Parameter of multiple was not matched 
correctly",
+                    3L, params.get(2));
         assertSame("Fourth Query Parameter of multiple was not matched 
correctly",
                      Boolean.TRUE, params.get(3));
         assertEquals("Fifth Query Parameter of multiple was not matched 
correctly", 
                      '\u0000', params.get(4));
-        assertEquals("Six Query Parameter of multiple was not matched 
correctly", 
+        assertEquals("Sixth Query Parameter of multiple was not matched 
correctly",
                      "", params.get(5));
         assertSame("Seventh Query Parameter of multiple was not matched 
correctly",
                 Boolean.TRUE, params.get(6));
+        assertNull("Eighth Query Parameter of multiple was not matched 
correctly",
+                params.get(7));
     }
     
     @SuppressWarnings("unchecked")
@@ -1505,10 +1507,10 @@ public class JAXRSUtilsTest extends Assert {
                               List.class, String.class};
         Method m = Customer.class.getMethod("testMatrixParam", argType);
         Message messageImpl = createMessage();
-        
-        messageImpl.put(Message.REQUEST_URI, 
"/foo;p4=0;p3=3/bar;p1=1;p2/baz;p4=4;p4=5;p5");
-        List<Object> params = JAXRSUtils.processParameters(new 
OperationResourceInfo(m, 
-                                                               new 
ClassResourceInfo(Customer.class)), 
+
+        messageImpl.put(Message.REQUEST_URI, 
"/foo;p4=0;p3=3/bar;p1=1;p2=/baz;p4=4;p4=5;p5");
+        List<Object> params = JAXRSUtils.processParameters(new 
OperationResourceInfo(m,
+                                                               new 
ClassResourceInfo(Customer.class)),
                                                            null, messageImpl);
         assertEquals("5 Matrix params should've been identified", 6, 
params.size());
         
@@ -1525,8 +1527,8 @@ public class JAXRSUtilsTest extends Assert {
         assertEquals("0", list.get(0));
         assertEquals("4", list.get(1));
         assertEquals("5", list.get(2));
-        assertEquals("Sixth Matrix Parameter was not matched correctly", 
-                     "", params.get(5));
+        assertNull("Sixth Matrix Parameter was not matched correctly",
+                     params.get(5));
     }
     
     @Test
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
index 9fa3bbf..43ff2b5 100644
--- 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
@@ -302,7 +302,7 @@ public class JAXRS20ClientServerBookTest extends 
AbstractBusClientServerTestBase
 
     @Test
     public void testPostMatchContainerFilterThrowsException() {
-        String address = "http://localhost:"; + PORT + 
"/bookstore/bookheaders/simple?throwException";
+        String address = "http://localhost:"; + PORT + 
"/bookstore/bookheaders/simple?throwException=true";
         WebClient wc = WebClient.create(address);
         Response response = wc.get();
         assertEquals(500, response.getStatus());

-- 
To stop receiving notification emails like this one, please contact
buhhu...@apache.org.

Reply via email to