cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nea...@apache.org
Subject cxf git commit: [CXF-7307] fix the 404 error in empty string query parameter injection.
Date Fri, 31 Mar 2017 12:01:08 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 551f30a4f -> 91b2c2012


[CXF-7307] fix the 404 error in empty string query parameter injection.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/91b2c201
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/91b2c201
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/91b2c201

Branch: refs/heads/3.1.x-fixes
Commit: 91b2c201227e6fd150e68f45a29c4995d69f4555
Parents: 551f30a
Author: Neal Hu <huxingjiang2649@tops001.com>
Authored: Fri Mar 31 19:59:06 2017 +0800
Committer: Neal Hu <huxingjiang2649@tops001.com>
Committed: Fri Mar 31 19:59:06 2017 +0800

----------------------------------------------------------------------
 .../org/apache/cxf/common/util/PrimitiveUtils.java  |  5 +++++
 .../org/apache/cxf/jaxrs/utils/InjectionUtils.java  |  5 +++++
 .../apache/cxf/jaxrs/utils/InjectionUtilsTest.java  | 16 ++++++++++++++++
 3 files changed, 26 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/91b2c201/core/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java b/core/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java
index dc131de..7a0b64e 100644
--- a/core/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java
+++ b/core/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java
@@ -75,6 +75,11 @@ public final class PrimitiveUtils {
 
     public static <T> Object read(String value, Class<T> type) {
         Object ret = value;
+        if (!(Character.TYPE.equals(type) || Character.class.equals(type))
+                && value != null && value.equals("")) {
+            //pass empty string to number type will result in Exception
+            value = "0";
+        }
         if (Integer.TYPE.equals(type) || Integer.class.equals(type)) {
             ret = Integer.valueOf(value);
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/91b2c201/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
index 3e9252a..dd143c2 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
@@ -406,6 +406,11 @@ public final class InjectionUtils {
             }
             return theResult;
         }
+
+        if (Number.class.isAssignableFrom(pClass) && "".equals(value)) {
+            //pass empty string to boxed number type will result in 404
+            return null;
+        }
         if (pClass.isPrimitive()) {
             try {
                 T ret = (T)PrimitiveUtils.read(value, pClass);

http://git-wip-us.apache.org/repos/asf/cxf/blob/91b2c201/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
index 74b8f08..edbcd55 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
@@ -150,6 +150,22 @@ public class InjectionUtilsTest extends Assert {
     }
 
     @Test
+    public void testInstantiateIntegerInQuery() {
+        Integer integer = InjectionUtils.handleParameter("", false, Integer.class,
+                Integer.class, null,
+                ParameterType.QUERY, null);
+        assertNull("Integer is not null", integer);
+    }
+
+    @Test
+    public void testInstantiateFloatInQuery() {
+        Float f = InjectionUtils.handleParameter("", false, float.class,
+                float.class, null,
+                ParameterType.QUERY, null);
+        assertEquals("Float is not 0", Float.valueOf(0F), f);
+    }
+
+    @Test
     public void testGenericInterfaceType() throws NoSuchMethodException {
         Type str = InjectionUtils.getGenericResponseType(GenericInterface.class.getMethod("get"),
                        TestService.class, "", String.class, new ExchangeImpl());


Mime
View raw message