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:26:39 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 56267745c -> 25ae30750


[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/25ae3075
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/25ae3075
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/25ae3075

Branch: refs/heads/3.0.x-fixes
Commit: 25ae30750a2216af5f9c16e0db31d7fc07585cb1
Parents: 5626774
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:26:26 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/25ae3075/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 0a5956e..f2e28af 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
@@ -747,7 +747,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());
@@ -760,7 +763,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);
@@ -774,7 +776,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/25ae3075/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 3a2dd9c..27a626a 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/25ae3075/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 a2e2d6a..bb0b82e 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;
@@ -35,6 +37,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;
 
@@ -849,8 +853,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());
@@ -1008,4 +1013,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