cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1221206 - in /cxf/branches/2.4.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/utils/
Date Tue, 20 Dec 2011 11:30:03 GMT
Author: sergeyb
Date: Tue Dec 20 11:30:02 2011
New Revision: 1221206

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

........
  r1221204 | sergeyb | 2011-12-20 11:26:59 +0000 (Tue, 20 Dec 2011) | 1 line
  
  [CXF-3984] Better support for Locale parameters
........

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

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1221204

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

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1221206&r1=1221205&r2=1221206&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Tue Dec 20 11:30:02 2011
@@ -41,6 +41,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.Set;
@@ -323,7 +324,10 @@ public final class InjectionUtils {
             adapterHasToBeUsed = true;
         }
         
-        Object result = null;
+        Object result = instantiateFromParameterHandler(value, pClass, message);
+        if (result != null) {
+            return result;
+        }
         // check constructors accepting a single String value
         try {
             Constructor<?> c = pClass.getConstructor(new Class<?>[]{String.class});
@@ -374,6 +378,19 @@ public final class InjectionUtils {
         return result;
     }
 
+    private static Object instantiateFromParameterHandler(String value, 
+                                                     Class<?> pClass,
+                                                     Message message) {
+        // TODO: Consider always checking custom parameter handlers first.
+        // Right now, Locale and Date are two special cases so it's very cheap
+        // just to check if it is Locale or not; 
+        if (Locale.class == pClass) {
+            return createFromParameterHandler(value, pClass, message);
+        } else {
+            return null;
+        }
+    }
+    
     private static Object createFromParameterHandler(String value, 
                                                      Class<?> pClass,
                                                      Message message) {

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=1221206&r1=1221205&r2=1221206&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
Tue Dec 20 11:30:02 2011
@@ -21,6 +21,7 @@ package org.apache.cxf.jaxrs;
 
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.UUID;
 
@@ -187,6 +188,10 @@ public class Customer extends AbstractCu
         
     }
     
+    public void testLocaleParam(@QueryParam("p1") Locale l) {
+        
+    }
+    
     public void testXmlAdapter(@QueryParam("a") 
                                @XmlJavaTypeAdapter(CustomerBeanAdapter.class) 
                                CustomerBean cb) {

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1221206&r1=1221205&r2=1221206&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Tue Dec 20 11:30:02 2011
@@ -27,6 +27,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.UUID;
 
 import javax.servlet.ServletConfig;
@@ -62,6 +63,7 @@ import org.apache.cxf.jaxrs.JAXRSService
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.SimpleFactory;
 import org.apache.cxf.jaxrs.Timezone;
+import org.apache.cxf.jaxrs.ext.ParameterHandler;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.impl.HttpServletResponseFilter;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
@@ -88,6 +90,7 @@ import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
 import org.easymock.EasyMock;
+
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -815,6 +818,24 @@ public class JAXRSUtilsTest extends Asse
     }
     
     @Test
+    public void testLocaleParameter() throws Exception {
+        Message messageImpl = createMessage();
+        ProviderFactory.getInstance(messageImpl).registerUserProvider(
+            new LocaleParameterHandler());
+        Class[] argType = {Locale.class};
+        Method m = Customer.class.getMethod("testLocaleParam", argType);
+        
+        messageImpl.put(Message.QUERY_STRING, "p1=en_us");
+        List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null),
+                                                           null, 
+                                                           messageImpl);
+        assertEquals(1, params.size());
+        Locale l = (Locale)params.get(0);
+        assertEquals("en", l.getLanguage());
+        assertEquals("US", l.getCountry());
+    }
+    
+    @Test
     public void testConstructorFirstAndParameterHandler() throws Exception {
         Message messageImpl = createMessage();
         ProviderFactory.getInstance(messageImpl).registerUserProvider(
@@ -1754,4 +1775,13 @@ public class JAXRSUtilsTest extends Asse
         e.put(Endpoint.class, endpoint);
         return m;
     }
+    
+    private static class LocaleParameterHandler implements ParameterHandler<Locale>
{
+
+        public Locale fromString(String s) {
+            String[] values = s.split("_");
+            return values.length == 2 ? new Locale(values[0], values[1]) : new Locale(s);
+        }
+        
+    }
 }



Mime
View raw message