cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7089] et ParamConverters handle null proxy path parameters
Date Thu, 13 Oct 2016 10:25:42 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 9a46a89c4 -> 6eb9cd56b


[CXF-7089] et ParamConverters handle null proxy path parameters


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

Branch: refs/heads/3.1.x-fixes
Commit: 6eb9cd56b2566e45b1682d3dcd3eabb77ca5c767
Parents: 9a46a89
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Oct 13 11:24:32 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Oct 13 11:25:27 2016 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/client/AbstractClient.java |  8 +++---
 .../cxf/jaxrs/client/ClientProxyImpl.java       |  4 ++-
 .../jaxrs/JAXRSClientServerSpringBookTest.java  | 26 +++++++++++++++++++-
 3 files changed, 33 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/6eb9cd56/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
index 23e1ca7..3139934 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
@@ -761,7 +761,10 @@ public abstract class AbstractClient implements Client {
     
     
     protected String convertParamValue(Object pValue, Annotation[] anns) {
-        if (pValue == null) {
+        return convertParamValue(pValue, pValue == null ? null : pValue.getClass(), anns);
+    }
+    protected String convertParamValue(Object pValue, Class<?> pClass, Annotation[]
anns) {    
+        if (pValue == null && pClass == null) {
             return null;
         }
         ProviderFactory pf = ClientProviderFactory.getInstance(cfg.getEndpoint());
@@ -774,7 +777,6 @@ public abstract class AbstractClient implements Client {
                 m.getExchange().setOutMessage(m);
                 m.getExchange().put(Endpoint.class, cfg.getEndpoint());
             }
-            Class<?> pClass = pValue.getClass();
             @SuppressWarnings("unchecked")
             ParamConverter<Object> prov = 
                 (ParamConverter<Object>)pf.createParameterHandler(pClass, pClass, anns,
m);
@@ -788,7 +790,7 @@ public abstract class AbstractClient implements Client {
                 }
             }
         }
-        return pValue.toString();
+        return pValue == null ? null : pValue.toString();
     }
     
     protected static void reportMessageHandlerProblem(String name, Class<?> cls, MediaType
ct, Throwable ex) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/6eb9cd56/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
index c5bb980..c82b942 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
@@ -444,7 +444,9 @@ public class ClientProxyImpl extends AbstractClient implements
         for (String varName : methodVars) {
             Parameter p = paramsMap.remove(varName);
             if (p != null) {
-                list.add(convertParamValue(params[p.getIndex()], getParamAnnotations(m, p)));
+                list.add(convertParamValue(params[p.getIndex()],
+                                           m.getParameterTypes()[p.getIndex()],
+                                           getParamAnnotations(m, p)));
             } else if (beanParamValues.containsKey(varName)) {
                 BeanPair pair = beanParamValues.get(varName);
                 list.add(convertParamValue(pair.getValue(), pair.getAnns()));

http://git-wip-us.apache.org/repos/asf/cxf/blob/6eb9cd56/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
index 9597911..9dae3ae 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
@@ -23,6 +23,8 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
 import java.net.Socket;
 import java.net.URL;
 import java.net.URLConnection;
@@ -36,6 +38,8 @@ import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.core.Form;
 import javax.ws.rs.core.Link;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ParamConverter;
+import javax.ws.rs.ext.ParamConverterProvider;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
@@ -850,8 +854,9 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
                                          endpointAddress, 
                                          BookStoreNoAnnotations.class,
                                          "classpath:/org/apache/cxf/systest/jaxrs/resources/resources.xml",
+                                         Collections.singletonList(new LongTypeParamConverterProvider()),
                                          null);
-        Book b = bStore.getBook(123L);
+        Book b = bStore.getBook(null);
         assertNotNull(b);
         assertEquals(123L, b.getId());
         assertEquals("CXF in Action", b.getName());
@@ -1004,4 +1009,23 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
         }
         
     }
+    static class LongTypeParamConverterProvider implements ParamConverterProvider, ParamConverter<Long>
{
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public <T> ParamConverter<T> getConverter(Class<T> cls, Type t,
Annotation[] anns) {
+            return cls == Long.class ? (ParamConverter<T>)this : null;
+        }
+
+        @Override
+        public Long fromString(String s) {
+            return null;
+        }
+
+        @Override
+        public String toString(Long l) {
+            return l == null ? "123" : String.valueOf(l);
+        }
+        
+    }
 }


Mime
View raw message