cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nea...@apache.org
Subject [2/2] cxf git commit: [CXF-7307] fix the 404 error in empty string query parameter injection.
Date Fri, 31 Mar 2017 11:01:55 GMT
[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/0dc7db7a
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/0dc7db7a
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/0dc7db7a

Branch: refs/heads/master
Commit: 0dc7db7aa48f36235f33ff1e7281bec525222903
Parents: fe4c8b6 6fd7678
Author: Neal Hu <nealhu@apache.org>
Authored: Fri Mar 31 17:56:57 2017 +0800
Committer: Neal Hu <nealhu@apache.org>
Committed: Fri Mar 31 17:56:57 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/0dc7db7a/core/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java
index 1c1b9ff,1c1b9ff..86c175c
--- a/core/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java
+++ b/core/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java
@@@ -74,6 -74,6 +74,11 @@@ public final class PrimitiveUtils 
      }
  
      public static <T> Object read(String value, Class<T> type) {
++        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";
++        }
          Object ret = value;
          if (Integer.TYPE.equals(type) || Integer.class.equals(type)) {
              ret = Integer.valueOf(value);

http://git-wip-us.apache.org/repos/asf/cxf/blob/0dc7db7a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
----------------------------------------------------------------------
diff --cc rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
index 1f278ae,1f278ae..334a464
--- 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
@@@ -433,6 -433,6 +433,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/0dc7db7a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
----------------------------------------------------------------------
diff --cc rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
index 3c96039,3c96039..dafb8ae
--- 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,6 +150,22 @@@ public class InjectionUtilsTest extend
      }
  
      @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("Long 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