You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2015/11/20 15:46:44 UTC
cxf git commit: [CXF-6688] Updating ClientProxyImpl to do the best
effort at mapping BeanParam bean's PathParam values to class-level template
vars
Repository: cxf
Updated Branches:
refs/heads/3.1.x-fixes 296ce494a -> ab063a7cd
[CXF-6688] Updating ClientProxyImpl to do the best effort at mapping BeanParam bean's PathParam values to class-level template vars
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/ab063a7c
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/ab063a7c
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/ab063a7c
Branch: refs/heads/3.1.x-fixes
Commit: ab063a7cd6321d471dd0f28fd9b4eff22a6b86e1
Parents: 296ce49
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Fri Nov 20 14:40:21 2015 +0000
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Fri Nov 20 14:46:17 2015 +0000
----------------------------------------------------------------------
.../cxf/jaxrs/client/ClientProxyImpl.java | 28 +++++++++++++++-----
.../cxf/systest/jaxrs/BookStoreSimple.java | 22 +++++++++++++++
...ientServerResourceCreatedSpringBookTest.java | 19 +++++++++++++
3 files changed, 63 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/ab063a7c/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 d41721f..37b798f 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
@@ -398,12 +398,32 @@ public class ClientProxyImpl extends AbstractClient implements
OperationResourceInfo ori,
int bodyIndex) {
List<Object> list = new LinkedList<Object>();
+
+ List<String> methodVars = ori.getURITemplate().getVariables();
+ List<Parameter> paramsList = getParameters(map, ParameterType.PATH);
+ Map<String, BeanPair> beanParamValues = new HashMap<String, BeanPair>(beanParams.size());
+ for (Parameter p : beanParams) {
+ beanParamValues.putAll(getValuesFromBeanParam(params[p.getIndex()], PathParam.class));
+ }
+ if (!beanParamValues.isEmpty() && !methodVars.containsAll(beanParamValues.keySet())) {
+ List<String> classVars = ori.getClassResourceInfo().getURITemplate().getVariables();
+ for (String classVar : classVars) {
+ BeanPair pair = beanParamValues.get(classVar);
+ if (pair != null) {
+ Object paramValue = convertParamValue(pair.getValue(), pair.getAnns());
+ if (isRoot) {
+ valuesMap.put(classVar, paramValue);
+ } else {
+ list.add(paramValue);
+ }
+ }
+ }
+ }
if (isRoot) {
list.addAll(valuesMap.values());
}
- List<String> methodVars = ori.getURITemplate().getVariables();
- List<Parameter> paramsList = getParameters(map, ParameterType.PATH);
+
Map<String, Parameter> paramsMap = new LinkedHashMap<String, Parameter>();
for (Parameter p : paramsList) {
if (p.getName().length() == 0) {
@@ -417,10 +437,6 @@ public class ClientProxyImpl extends AbstractClient implements
}
}
- Map<String, BeanPair> beanParamValues = new HashMap<String, BeanPair>(beanParams.size());
- 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);
http://git-wip-us.apache.org/repos/asf/cxf/blob/ab063a7c/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSimple.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSimple.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSimple.java
index a046a42..46ee30c 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSimple.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSimple.java
@@ -20,12 +20,29 @@ package org.apache.cxf.systest.jaxrs;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
+import javax.ws.rs.BeanParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@Path("/simplebooks/{id}")
public class BookStoreSimple {
+ public static class BookBean {
+ private long id;
+ public BookBean() {
+
+ }
+ public BookBean(long id) {
+ this.id = id;
+ }
+ public long getId() {
+ return id;
+ }
+ @PathParam("id")
+ public void setId(long id) {
+ this.id = id;
+ }
+ }
@Resource
private Book injectedBook;
@@ -46,4 +63,9 @@ public class BookStoreSimple {
throw new IllegalStateException("Book resource has not been injected");
}
}
+ @GET
+ @Path("/beanparam")
+ public Book getBookBeanParam(@BeanParam BookBean bookBean) {
+ return getBook(bookBean.getId());
+ }
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/ab063a7c/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java
index 58736ef..efa661f 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringBookTest.java
@@ -25,6 +25,7 @@ import java.net.URLConnection;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -67,6 +68,24 @@ public class JAXRSClientServerResourceCreatedSpringBookTest extends AbstractBusC
}
@Test
+ public void testGetBookSimpleProxy() throws Exception {
+
+ String address = "http://localhost:" + PORT + "/webapp/rest";
+ BookStoreSimple bookStore = JAXRSClientFactory.create(address, BookStoreSimple.class);
+ Book book = bookStore.getBook(444L);
+ assertEquals(444L, book.getId());
+ }
+
+ @Test
+ public void testGetBookSimpleBeanParamProxy() throws Exception {
+
+ String address = "http://localhost:" + PORT + "/webapp/rest";
+ BookStoreSimple bookStore = JAXRSClientFactory.create(address, BookStoreSimple.class);
+ Book book = bookStore.getBookBeanParam(new BookStoreSimple.BookBean(444));
+ assertEquals(444L, book.getId());
+ }
+
+ @Test
public void testGetBook123() throws Exception {
String endpointAddress =