cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1299635 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/ systests/jaxrs/src/test/java...
Date Mon, 12 Mar 2012 11:38:02 GMT
Author: sergeyb
Date: Mon Mar 12 11:38:02 2012
New Revision: 1299635

URL: http://svn.apache.org/viewvc?rev=1299635&view=rev
Log:
[CXF-4177] Fixing ClientProxyImpl to keep the correct order of path parameter values

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreSubresourcesOnly.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1299635&r1=1299634&r2=1299635&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Mon Mar 12 11:38:02 2012
@@ -77,7 +77,7 @@ public class ClientProxyImpl extends Abs
     private ClassResourceInfo cri;
     private boolean inheritHeaders;
     private boolean isRoot;
-    private Map<String, Object> valuesMap;
+    private Map<String, Object> valuesMap = Collections.emptyMap();
     
     public ClientProxyImpl(URI baseURI, ClassResourceInfo cri, boolean isRoot, 
                            boolean inheritHeaders, Object... varValues) {
@@ -98,21 +98,23 @@ public class ClientProxyImpl extends Abs
     }
     
     private void initValuesMap(Object... varValues) {
-        if (isRoot && varValues.length != 0) {
-            valuesMap = new LinkedHashMap<String, Object>();
+        if (isRoot) {
             List<String> vars = cri.getURITemplate().getVariables();
+            valuesMap = new LinkedHashMap<String, Object>();
             for (int i = 0; i < vars.size(); i++) {
-                if (i < varValues.length) {
-                    valuesMap.put(vars.get(i), varValues[i]);
+                if (varValues.length > 0) {
+                    if (i < varValues.length) {
+                        valuesMap.put(vars.get(i), varValues[i]);
+                    } else {
+                        org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(
+                             "ROOT_VARS_MISMATCH", BUNDLE, vars.size(), varValues.length);
+                        LOG.info(msg.toString());
+                        break;
+                    }
                 } else {
-                    org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(
-                         "ROOT_VARS_MISMATCH", BUNDLE, vars.size(), varValues.length);
-                    LOG.info(msg.toString());
-                    break;
+                    valuesMap.put(vars.get(i), "");
                 }
             }
-        } else {
-            valuesMap = Collections.emptyMap();
         }
     }
     
@@ -333,40 +335,46 @@ public class ClientProxyImpl extends Abs
     private List<Object> getPathParamValues(MultivaluedMap<ParameterType, Parameter>
map,
                                             Object[] params,
                                             OperationResourceInfo ori) {
-        List<Parameter> paramsList =  getParameters(map, ParameterType.PATH);
         List<Object> list = new LinkedList<Object>();
         if (isRoot) {
             list.addAll(valuesMap.values());
         }
-        List<String> vars = ori.getURITemplate().getVariables();
-        // TODO : unfortunately, UriBuilder will lose a method-scoped parameter 
-        // if a same name variable exists in a class scope which is an api bug.
-        // It's a rare case but we might want just to use UriBuilderImpl() directly 
-        // on the client side and tell it to choose the last variable value
+        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 (valuesMap.containsKey(p.getName()) && !vars.contains(p.getName()))
{
+            if (p.getName().length() == 0) {
+                MultivaluedMap<String, Object> values = 
+                    InjectionUtils.extractValuesFromBean(params[p.getIndex()], "");
+                for (String var : methodVars) {
+                    list.addAll(values.get(var));
+                }
+            } else {
+                paramsMap.put(p.getName(), p);
+            }
+        }
+        
+        for (String varName : methodVars) {
+            Parameter p = paramsMap.remove(varName);
+            if (p != null) {
+                list.add(params[p.getIndex()]);
+            }
+        }
+        
+        for (Parameter p : paramsMap.values()) {
+            if (valuesMap.containsKey(p.getName())) {
                 int index = 0; 
                 for (Iterator<String> it = valuesMap.keySet().iterator(); it.hasNext();
index++) {
-                    if (it.next().equals(p.getName())) {
+                    if (it.next().equals(p.getName()) && index < list.size())
{
                         list.remove(index);
                         list.add(index, params[p.getIndex()]);
                         break;
                     }
                 }
-            } else {
-                String paramName = p.getName();
-                if (!"".equals(paramName)) {
-                    list.add(params[p.getIndex()]);
-                } else {
-                    MultivaluedMap<String, Object> values = 
-                        InjectionUtils.extractValuesFromBean(params[p.getIndex()], "");
-                    for (String var : vars) {
-                        list.addAll(values.get(var));
-                    }
-                }
-                
-            }
+            }    
         }
+        
         return list;
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java?rev=1299635&r1=1299634&r2=1299635&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java
Mon Mar 12 11:38:02 2012
@@ -118,8 +118,19 @@ public class JAXRSClientFactoryBeanTest 
         bean.setAddress("http://bar");
         bean.setResourceClass(BookStoreSubresourcesOnly.class);
         BookStoreSubresourcesOnly store = bean.create(BookStoreSubresourcesOnly.class, 1,
2, 3);
-        BookStoreSubresourcesOnly store2 = store.getItself2("11", "33");
-        assertEquals("http://bar/bookstore/11/2/33/sub2", 
+        BookStoreSubresourcesOnly store2 = store.getItself2("4", "11", "33");
+        assertEquals("http://bar/bookstore/11/2/33/sub2/4", 
+                     WebClient.client(store2).getCurrentURI().toString());
+    }
+    
+    @Test
+    public void testTemplateInRootReplaceEmpty() throws Exception {
+        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+        bean.setAddress("http://bar");
+        bean.setResourceClass(BookStoreSubresourcesOnly.class);
+        BookStoreSubresourcesOnly store = bean.create(BookStoreSubresourcesOnly.class);
+        BookStoreSubresourcesOnly store2 = store.getItself4("4", "11", "22", "33");
+        assertEquals("http://bar/bookstore/11/22/33/sub2/4", 
                      WebClient.client(store2).getCurrentURI().toString());
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreSubresourcesOnly.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreSubresourcesOnly.java?rev=1299635&r1=1299634&r2=1299635&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreSubresourcesOnly.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreSubresourcesOnly.java
Mon Mar 12 11:38:02 2012
@@ -31,8 +31,9 @@ public class BookStoreSubresourcesOnly {
         return this;
     }
     
-    @Path("/sub2")
-    public BookStoreSubresourcesOnly getItself2(@PathParam("id") String id1, @PathParam("id3")
String id3) { 
+    @Path("/sub2/{id4}")
+    public BookStoreSubresourcesOnly getItself2(@PathParam("id4") String id4,
+                                                @PathParam("id") String id1, @PathParam("id3")
String id3) { 
         return this;
     }
     
@@ -40,6 +41,14 @@ public class BookStoreSubresourcesOnly {
     public BookStoreSubresourcesOnly getItself3(@PathParam("id4") String id4) { 
         return this;
     }
+    
+    @Path("/sub2/{id4}")
+    public BookStoreSubresourcesOnly getItself4(@PathParam("id4") String id4,
+                                                @PathParam("id") String id1,
+                                                @PathParam("id2") String id2,
+                                                @PathParam("id3") String id3) { 
+        return this;
+    }
 }
 
 

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java?rev=1299635&r1=1299634&r2=1299635&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java
Mon Mar 12 11:38:02 2012
@@ -79,6 +79,13 @@ public interface BookSubresource {
                      @FormParam("") Book formBook) throws BookNotFoundFault;
     
     @POST
+    @Path("/subresource5/{id}/{name}")
+    @Produces("application/xml")
+    @Consumes("application/xml")
+    Book getTheBook5(@PathParam("name") String name,
+                     @PathParam("id") long id) throws BookNotFoundFault;
+    
+    @POST
     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
     @Produces("application/xml")
     OrderBean addOrder(@FormParam("") OrderBean order);

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java?rev=1299635&r1=1299634&r2=1299635&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java
Mon Mar 12 11:38:02 2012
@@ -107,4 +107,8 @@ public class BookSubresourceImpl impleme
         return getTheBook();
     }
 
+    public Book getTheBook5(String name, long bookid) throws BookNotFoundFault {
+        return new Book(name, bookid);
+    }
+
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=1299635&r1=1299634&r2=1299635&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Mon Mar 12 11:38:02 2012
@@ -89,7 +89,7 @@ public class JAXRSSoapBookTest extends A
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", 
-                   launchServer(BookServerRestSoap.class));
+                   launchServer(BookServerRestSoap.class, true));
     }
     
     @Test
@@ -494,6 +494,18 @@ public class JAXRSSoapBookTest extends A
     }
     
     @Test
+    public void testGetBookSubresourceParamOrder() throws Exception {
+        
+        String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
+        BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress,
+                                                              BookStoreJaxrsJaxws.class);
+        BookSubresource bs = proxy.getBookSubresource("139");
+        Book b = bs.getTheBook5("CXF", 555L);
+        assertEquals(555, b.getId());
+        assertEquals("CXF", b.getName());
+    }
+    
+    @Test
     public void testAddOrderFormBean() throws Exception {
         
         String baseAddress = "http://localhost:" + PORT + "/test/services/rest";



Mime
View raw message