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-6477] Updating the proxy code to resolve path parameters from the body beans if possible
Date Tue, 09 Jun 2015 13:14:33 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 4626a863a -> 96ddcf58f


[CXF-6477] Updating the proxy code to resolve path parameters from the body beans if possible


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

Branch: refs/heads/3.0.x-fixes
Commit: 96ddcf58fff4ef5e31e593c33a189312383f277f
Parents: 4626a86
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Jun 9 14:10:26 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Jun 9 14:13:57 2015 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/client/ClientProxyImpl.java  | 18 +++++++++++++-----
 .../org/apache/cxf/systest/jaxrs/BookStore.java   | 10 ++++++++++
 .../systest/jaxrs/JAXRSClientServerBookTest.java  |  7 +++++++
 3 files changed, 30 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/96ddcf58/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 c9b211e..09da8a5 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
@@ -166,11 +166,10 @@ public class ClientProxyImpl extends AbstractClient implements
         MultivaluedMap<ParameterType, Parameter> types = getParametersInfo(m, params,
ori);
         List<Parameter> beanParamsList =  getParameters(types, ParameterType.BEAN);
         
-        
-        List<Object> pathParams = getPathParamValues(m, params, types, beanParamsList,
ori);
-        
         int bodyIndex = getBodyIndex(types, ori);
         
+        List<Object> pathParams = getPathParamValues(m, params, types, beanParamsList,
ori, bodyIndex);
+        
         UriBuilder builder = getCurrentBuilder().clone(); 
         if (isRoot) {
             addNonEmptyPath(builder, ori.getClassResourceInfo().getURITemplate().getValue());
@@ -391,7 +390,8 @@ public class ClientProxyImpl extends AbstractClient implements
                                             Object[] params,
                                             MultivaluedMap<ParameterType, Parameter>
map,
                                             List<Parameter> beanParams,
-                                            OperationResourceInfo ori) {
+                                            OperationResourceInfo ori,
+                                            int bodyIndex) {
         List<Object> list = new LinkedList<Object>();
         if (isRoot) {
             list.addAll(valuesMap.values());
@@ -416,7 +416,7 @@ public class ClientProxyImpl extends AbstractClient implements
         for (Parameter p : beanParams) {
             beanParamValues.putAll(getValuesFromBeanParam(params[p.getIndex()], PathParam.class));
         }
-        
+        Object requestBody = bodyIndex == -1 ? null : params[bodyIndex];
         for (String varName : methodVars) {
             Parameter p = paramsMap.remove(varName);
             if (p != null) {
@@ -424,6 +424,14 @@ public class ClientProxyImpl extends AbstractClient implements
             } else if (beanParamValues.containsKey(varName)) {
                 BeanPair pair = beanParamValues.get(varName);
                 list.add(convertParamValue(pair.getValue(), pair.getAnns()));
+            } else if (requestBody != null) {
+                try {
+                    Method getter = requestBody.getClass().getMethod("get" + StringUtils.capitalize(varName),

+                                                                     new Class<?>[]{});
+                    list.add(getter.invoke(requestBody, new Object[]{}));
+                } catch (Exception ex) {
+                    // continue
+                }
             }
         }
         

http://git-wip-us.apache.org/repos/asf/cxf/blob/96ddcf58/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
index ffa7617..01a5c75 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
@@ -163,6 +163,16 @@ public class BookStore {
     public Book getBookRoot() {
         return new Book("root", 124L);
     }
+    @PUT
+    @Path("/updatebook/{id}")
+    @Consumes("application/xml")
+    @Produces("application/xml")
+    public Book updateEchoBook(Book book) {
+        if (book.getId() != Long.parseLong(ui.getPathParameters().getFirst("id"))) {
+            throw new WebApplicationException(404);
+        }
+        return new Book("root", book.getId());
+    }
     @GET
     @Path("/books/wildcard")
     @Produces("text/*")

http://git-wip-us.apache.org/repos/asf/cxf/blob/96ddcf58/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index 7d81457..9c4487a 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -107,6 +107,13 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
         assertEquals(500, r.getStatus());
     }
     @Test
+    public void testUpdateBookWithProxy() throws Exception {
+        String address = "http://localhost:" + PORT;
+        BookStore store = JAXRSClientFactory.create(address, BookStore.class);
+        Book b = store.updateEchoBook(new Book("CXF", 125L));
+        assertEquals(125L, b.getId());
+    }
+    @Test
     public void testGetBookRoot() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/;JSESSIONID=xxx";
         WebClient wc = WebClient.create(address);


Mime
View raw message