cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1055905 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ 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...
Date Thu, 06 Jan 2011 14:58:28 GMT
Author: sergeyb
Date: Thu Jan  6 14:58:27 2011
New Revision: 1055905

URL: http://svn.apache.org/viewvc?rev=1055905&view=rev
Log:
Merged revisions 1055895 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1055895 | sergeyb | 2011-01-06 14:37:16 +0000 (Thu, 06 Jan 2011) | 1 line
  
  [JAX-RS] Making sure ParameterHandlers are checked in case of String constructors throwing
exceptions
........

Added:
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer2.java
      - copied unchanged from r1055895, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer2.java
Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerParameterHandler.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan  6 14:58:27 2011
@@ -1 +1 @@
-/cxf/trunk:1055184,1055554,1055566,1055582,1055584,1055649,1055817
+/cxf/trunk:1055184,1055554,1055566,1055582,1055584,1055649,1055817,1055895

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

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1055905&r1=1055904&r2=1055905&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Thu Jan  6 14:58:27 2011
@@ -180,8 +180,7 @@ public class WebClient extends AbstractC
     /**
      * Creates WebClient, baseURI will be set to Client currentURI
      * @param client existing client
-     * @param inheritHeaders  if existing Client headers can be inherited by new proxy 
-     *        and subresource proxies if any 
+     * @param inheritHeaders  if existing Client headers can be inherited by new client 
      */
     public static WebClient fromClient(Client client, boolean inheritHeaders) {
         

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1055905&r1=1055904&r2=1055905&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Thu Jan  6 14:58:27 2011
@@ -318,7 +318,11 @@ public final class InjectionUtils {
             // try valueOf
         } catch (WebApplicationException ex) {
             throw ex;
-        } catch (Exception ex) { 
+        } catch (Exception ex) {
+            Object result = createFromParameterHandler(value, pClass, message);
+            if (result != null) {
+                return result;
+            }
             LOG.severe(new org.apache.cxf.common.i18n.Message("CLASS_CONSTRUCTOR_FAILURE",

                                                                BUNDLE, 
                                                                pClass.getName()).toString());
@@ -337,22 +341,31 @@ public final class InjectionUtils {
             }
         }
         
-        if (result == null && message != null) {
+        if (result == null) {
+            result = createFromParameterHandler(value, pClass, message);
+        }
+        
+        if (result == null) {
+            reportServerError("WRONG_PARAMETER_TYPE", pClass.getName());
+        }
+        
+        return result;
+    }
+
+    private static Object createFromParameterHandler(String value, 
+                                                     Class<?> pClass,
+                                                     Message message) {
+        Object result = null;
+        if (message != null) {
             ParameterHandler<?> pm = ProviderFactory.getInstance(message)
                 .createParameterHandler(pClass);
             if (pm != null) {
                 result = pm.fromString(value);
             }
         }
-        
-        if (result != null) {
-            return result;
-        }
-        
-        reportServerError("WRONG_PARAMETER_TYPE", pClass.getName());
-        return null;
+        return result;
     }
-
+    
     public static void reportServerError(String messageName, String parameter) {
         org.apache.cxf.common.i18n.Message errorMessage = 
             new org.apache.cxf.common.i18n.Message(messageName, 

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=1055905&r1=1055904&r2=1055905&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
Thu Jan  6 14:58:27 2011
@@ -307,7 +307,9 @@ public class Customer extends AbstractCu
         // complete
     }
     
-    public void testCustomerParam(@QueryParam("p1") Customer c, @QueryParam("p2") Customer[]
c2) {
+    public void testCustomerParam(@QueryParam("p1") Customer c, 
+                                  @QueryParam("p2") Customer[] c2,
+                                  @QueryParam("p3") Customer2 c3) {
         // complete
     }
     

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerParameterHandler.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerParameterHandler.java?rev=1055905&r1=1055904&r2=1055905&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerParameterHandler.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerParameterHandler.java
Thu Jan  6 14:58:27 2011
@@ -24,7 +24,10 @@ import org.apache.cxf.jaxrs.ext.Paramete
 public class CustomerParameterHandler implements ParameterHandler<Customer> {
 
     public Customer fromString(String s) {
-        Customer c = new Customer();
+        if ("noName".equals(s)) {
+            throw new IllegalArgumentException();
+        }
+        Customer c = Character.isLowerCase(((CharSequence)s).charAt(0)) ? new Customer2()
: new Customer();
         c.setName(s);
         return c;
     }

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1055905&r1=1055904&r2=1055905&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Thu Jan  6 14:58:27 2011
@@ -47,6 +47,7 @@ import javax.xml.bind.JAXBContext;
 
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.jaxrs.Customer;
+import org.apache.cxf.jaxrs.Customer2;
 import org.apache.cxf.jaxrs.CustomerGender;
 import org.apache.cxf.jaxrs.CustomerParameterHandler;
 import org.apache.cxf.jaxrs.JAXBContextProvider;
@@ -644,20 +645,49 @@ public class JAXRSUtilsTest extends Asse
         Message messageImpl = createMessage();
         ProviderFactory.getInstance(messageImpl).registerUserProvider(
             new CustomerParameterHandler());
-        Class[] argType = {Customer.class, Customer[].class};
+        Class[] argType = {Customer.class, Customer[].class, Customer2.class};
         Method m = Customer.class.getMethod("testCustomerParam", argType);
         
-        messageImpl.put(Message.QUERY_STRING, "p1=Fred&p2=Barry");
+        messageImpl.put(Message.QUERY_STRING, "p1=Fred&p2=Barry&p3=Jack&p4=John");
         List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null),
                                                            null, 
                                                            messageImpl);
-        assertEquals(2, params.size());
+        assertEquals(3, params.size());
         Customer c = (Customer)params.get(0);
         assertEquals("Fred", c.getName());
         Customer c2 = ((Customer[])params.get(1))[0];
         assertEquals("Barry", c2.getName());
+        Customer2 c3 = (Customer2)params.get(2);
+        assertEquals("Jack", c3.getName());
+        
+        try {
+            messageImpl.put(Message.QUERY_STRING, "p3=noName");
+            JAXRSUtils.processParameters(new OperationResourceInfo(m, null), null, messageImpl);
+            fail("Customer2 constructor does not accept names starting with lower-case chars");
+        } catch (Exception ex) {
+            // expected
+        }
+        
+    }
+    
+    @Test
+    public void testConstructorFirstAndParameterHandler() throws Exception {
+        Message messageImpl = createMessage();
+        ProviderFactory.getInstance(messageImpl).registerUserProvider(
+            new CustomerParameterHandler());
+        Class[] argType = {Customer.class, Customer[].class, Customer2.class};
+        Method m = Customer.class.getMethod("testCustomerParam", argType);
+        
+        messageImpl.put(Message.QUERY_STRING, "p3=jack");
+        List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null),
+                                                           null, 
+                                                           messageImpl);
+        assertEquals(3, params.size());
+        Customer2 c3 = (Customer2)params.get(2);
+        assertEquals("jack", c3.getName());
     }
     
+    
     @Test
     public void testArrayParamNoProvider() throws Exception {
         Message messageImpl = createMessage();



Mime
View raw message