cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1399354 - in /cxf/branches/2.5.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/ rt/frontend/jaxrs...
Date Wed, 17 Oct 2012 17:22:49 GMT
Author: sergeyb
Date: Wed Oct 17 17:22:48 2012
New Revision: 1399354

URL: http://svn.apache.org/viewvc?rev=1399354&view=rev
Log:
Merged revisions 1399350 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

................
  r1399350 | sergeyb | 2012-10-17 18:11:22 +0100 (Wed, 17 Oct 2012) | 9 lines
  
  Merged revisions 1399336 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1399336 | sergeyb | 2012-10-17 17:47:56 +0100 (Wed, 17 Oct 2012) | 1 line
    
    [CXF-4580] Getting 'is' boolean getters supported
  ........
................

Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1399336
  Merged /cxf/branches/2.6.x-fixes:r1399350

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1399354&r1=1399353&r2=1399354&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Wed Oct 17 17:22:48 2012
@@ -496,7 +496,8 @@ public final class InjectionUtils {
                         && m.getParameterTypes().length == 1) {
                         setter = m;
                     } else if (m.getName().equalsIgnoreCase("get" + memberKey)
-                        && m.getReturnType() != Void.TYPE) {
+                        || isBooleanType(m.getReturnType()) 
+                           && m.getName().equalsIgnoreCase("is" + memberKey)) {
                         getter = m;
                     }
                     if (setter != null && getter != null) {
@@ -1006,12 +1007,25 @@ public final class InjectionUtils {
         return values;
     }
     
+    private static boolean isBooleanType(Class<?> cls) {
+        return boolean.class == cls || Boolean.class == cls;
+    }
+    
     public static void fillInValuesFromBean(Object bean, String baseName, 
                                             MultivaluedMap<String, Object> values)
{
         for (Method m : bean.getClass().getMethods()) {
-            if (m.getName().startsWith("get") && m.getParameterTypes().length ==
0 
-                && m.getName().length() > 3) {
-                String propertyName = m.getName().substring(3);
+            String methodName = m.getName(); 
+            boolean startsFromGet = methodName.startsWith("get");
+            if ((startsFromGet 
+                || isBooleanType(m.getReturnType()) && methodName.startsWith("is"))

+                && m.getParameterTypes().length == 0) {
+                
+                int minLen = startsFromGet ? 3 : 2; 
+                if (methodName.length() <= minLen) {
+                    continue;
+                }
+                
+                String propertyName =  methodName.substring(minLen);
                 if (propertyName.length() == 1) {
                     propertyName = propertyName.toLowerCase();
                 } else {
@@ -1057,9 +1071,17 @@ public final class InjectionUtils {
                                                                       boolean checkIgnorable)
{
         Map<Parameter, Class<?>> params = new LinkedHashMap<Parameter, Class<?>>();
         for (Method m : beanClass.getMethods()) {
-            if (m.getName().startsWith("get") && m.getParameterTypes().length ==
0 
-                && m.getName().length() > 3) {
-                String propertyName = m.getName().substring(3).toLowerCase();
+            String methodName = m.getName(); 
+            boolean startsFromGet = methodName.startsWith("get");
+            if ((startsFromGet 
+                || isBooleanType(m.getReturnType()) && methodName.startsWith("is"))

+                && m.getParameterTypes().length == 0) {
+                
+                int minLen = startsFromGet ? 3 : 2; 
+                if (methodName.length() <= minLen) {
+                    continue;
+                }
+                String propertyName = methodName.substring(minLen).toLowerCase();
                 if (m.getReturnType() == Class.class
                     || checkIgnorable && canPropertyBeIgnored(m, propertyName)) {
                     continue;

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=1399354&r1=1399353&r2=1399354&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
Wed Oct 17 17:22:48 2012
@@ -72,6 +72,7 @@ public class Customer extends AbstractCu
     public static class CustomerBean implements CustomerBeanInterface {
         private String a;
         private Long b;
+        private boolean cb;
         private List<String> c;
         private CustomerBean d;
         private Map<String, List<String>> g;
@@ -109,6 +110,12 @@ public class Customer extends AbstractCu
         public Map<String, List<String>> getG() {
             return g;
         }
+        public boolean isCb() {
+            return cb;
+        }
+        public void setCb(boolean cb) {
+            this.cb = cb;
+        }
         
     }
     

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java?rev=1399354&r1=1399353&r2=1399354&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
Wed Oct 17 17:22:48 2012
@@ -205,10 +205,10 @@ public class BookStore {
     }
     
     public static class QueryBean3 {
-        private int a;
+        private boolean a;
         private int b;
         
-        public int getA() {
+        public boolean isA() {
             return a;
         }
         

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=1399354&r1=1399353&r2=1399354&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Wed Oct 17 17:22:48 2012
@@ -511,7 +511,7 @@ public class WadlGeneratorTest extends A
                          new Param("a", "query", "xs:int"),
                          new Param("c.a", "query", "xs:int"),
                          new Param("c.b", "query", "xs:int"),
-                         new Param("c.d.a", "query", "xs:int"),
+                         new Param("c.d.a", "query", "xs:boolean"),
                          new Param("e", "query", "xs:string", Collections.singleton("A")));
         
         assertEquals(0, DOMUtils.getChildrenWithName(requestEls.get(0), 

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1399354&r1=1399353&r2=1399354&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Wed Oct 17 17:22:48 2012
@@ -1056,6 +1056,30 @@ public class JAXRSUtilsTest extends Asse
     }
     
     @Test
+    public void testFormParametersBeanWithBoolean() throws Exception {
+        Class<?>[] argType = {Customer.CustomerBean.class};
+        Method m = Customer.class.getMethod("testFormBean", argType);
+        MessageImpl messageImpl = new MessageImpl();
+        messageImpl.put(Message.REQUEST_URI, "/bar");
+        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
+        headers.putSingle("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
+        messageImpl.put(Message.PROTOCOL_HEADERS, headers);
+        String body = "a=aValue&b=123&cb=true";
+        messageImpl.setContent(InputStream.class, new ByteArrayInputStream(body.getBytes()));
+        
+        List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null),
+                                                           null, 
+                                                           messageImpl);
+        assertEquals("Bean should be created", 1, params.size());
+        Customer.CustomerBean cb = (Customer.CustomerBean)params.get(0);
+        assertNotNull(cb);
+        
+        assertEquals("aValue", cb.getA());
+        assertEquals(new Long(123), cb.getB());
+        assertTrue(cb.isCb());
+    }
+    
+    @Test
     public void testFormParametersBean() throws Exception {
         Class[] argType = {Customer.CustomerBean.class};
         Method m = Customer.class.getMethod("testFormBean", argType);
@@ -1064,7 +1088,7 @@ public class JAXRSUtilsTest extends Asse
         MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
         headers.putSingle("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
         messageImpl.put(Message.PROTOCOL_HEADERS, headers);
-        String body = "a=aValue&b=123";
+        String body = "a=aValue&b=123&cb=true";
         messageImpl.setContent(InputStream.class, new ByteArrayInputStream(body.getBytes()));
 
         MessageImpl complexMessageImpl = new MessageImpl();



Mime
View raw message