cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r998736 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/ main/java/org/apache/cxf/jaxrs/utils/ test/java/org/apache/cxf/jaxrs/ test/java/org/apache/cxf/jaxrs/impl/ test/java/org/apache/cxf/jaxrs/utils/
Date Sun, 19 Sep 2010 21:25:50 GMT
Author: sergeyb
Date: Sun Sep 19 21:25:49 2010
New Revision: 998736

URL: http://svn.apache.org/viewvc?rev=998736&view=rev
Log:
making comma a default separator for Cache-Control and fixing the issue of the empty collections
in the absense of @DefaultValue

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java?rev=998736&r1=998735&r2=998736&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProvider.java
Sun Sep 19 21:25:49 2010
@@ -27,8 +27,15 @@ import java.util.Map;
 import javax.ws.rs.core.CacheControl;
 import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
 
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.PhaseInterceptorChain;
+
 public class CacheControlHeaderProvider implements HeaderDelegate<CacheControl> {
     
+    public static final String CACHE_CONTROL_SEPARATOR_PROPERTY =
+        "org.apache.cxf.http.cache-control.separator";
+    private static final String DEFAULT_SEPARATOR = ",";
+    
     private static final String PUBLIC = "public";
     private static final String PRIVATE = "private";
     private static final String NO_CACHE = "no-cache";
@@ -51,9 +58,11 @@ public class CacheControlHeaderProvider 
         int maxAge = -1;
         int sMaxAge = -1;
        
+        String separator = getSeparator();
         
-        String[] tokens = c.split(";");
-        for (String token : tokens) {
+        String[] tokens = c.split(separator);
+        for (String rawToken : tokens) {
+            String token = rawToken.trim();
             if (token.startsWith(MAX_AGE)) {
                 maxAge = Integer.parseInt(token.substring(MAX_AGE.length() + 1));
             } else if (token.startsWith(SMAX_AGE)) {
@@ -93,32 +102,36 @@ public class CacheControlHeaderProvider 
     }
 
     public String toString(CacheControl c) {
+        String separator = getSeparator();
+        
         StringBuilder sb = new StringBuilder();
         if (c.isPrivate()) {
             sb.append(PRIVATE);
             handleFields(c.getPrivateFields(), sb);
+            sb.append(separator);
         }
         if (c.isNoCache()) {
             sb.append(NO_CACHE);
             handleFields(c.getNoCacheFields(), sb);
+            sb.append(separator);
         }
         if (c.isNoStore()) {
-            sb.append(NO_STORE).append(';');
+            sb.append(NO_STORE).append(separator);
         }
         if (c.isNoTransform()) {
-            sb.append(NO_TRANSFORM).append(';');
+            sb.append(NO_TRANSFORM).append(separator);
         }
         if (c.isMustRevalidate()) {
-            sb.append(MUST_REVALIDATE).append(';');
+            sb.append(MUST_REVALIDATE).append(separator);
         }
         if (c.isProxyRevalidate()) {
-            sb.append(PROXY_REVALIDATE).append(';');
+            sb.append(PROXY_REVALIDATE).append(separator);
         }
         if (c.getMaxAge() != -1) {
-            sb.append(MAX_AGE).append('=').append(c.getMaxAge()).append(';');
+            sb.append(MAX_AGE).append('=').append(c.getMaxAge()).append(separator);
         }
         if (c.getSMaxAge() != -1) {
-            sb.append(SMAX_AGE).append('=').append(c.getSMaxAge()).append(';');
+            sb.append(SMAX_AGE).append('=').append(c.getSMaxAge()).append(separator);
         }
         Map<String, String> exts = c.getCacheExtension();
         for (Map.Entry<String, String> entry : exts.entrySet()) {
@@ -132,10 +145,10 @@ public class CacheControlHeaderProvider 
                     sb.append(v);
                 }
             }
-            sb.append(';');
+            sb.append(separator);
         }
         String s = sb.toString();
-        return s.endsWith(";") ? s.substring(0, s.length() - 1) : s; 
+        return s.endsWith(separator) ? s.substring(0, s.length() - 1) : s; 
     }
     
     private static void addFields(List<String> fields, String token) {
@@ -155,15 +168,34 @@ public class CacheControlHeaderProvider 
     }
 
     private static void handleFields(List<String> fields, StringBuilder sb) {
-        if (!fields.isEmpty()) {
-            sb.append('=');
+        if (fields.isEmpty()) {
+            return;
         }
+        sb.append('=');
         for (Iterator<String> it = fields.iterator(); it.hasNext();) {
             sb.append('\"').append(it.next()).append('\"');
             if (it.hasNext()) {
                 sb.append(',');
             }
         }
-        sb.append(';');
+    }
+    
+    protected String getSeparator() {
+        
+        String separator = DEFAULT_SEPARATOR;
+        
+        Message message = getCurrentMessage();
+        
+        if (message != null) {
+            Object sepProperty = message.getContextualProperty(CACHE_CONTROL_SEPARATOR_PROPERTY);
+            if (sepProperty != null) {
+                separator = sepProperty.toString();
+            }
+        }
+        return separator;
+    }
+    
+    protected Message getCurrentMessage() {
+        return PhaseInterceptorChain.getCurrentMessage();
     }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=998736&r1=998735&r2=998736&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Sun Sep 19 21:25:49 2010
@@ -671,6 +671,8 @@ public final class InjectionUtils {
                 if (paramType.isPrimitive()) {
                     paramValues = Collections.singletonList(
                         boolean.class == paramType ? "false" : "0");
+                } else if (InjectionUtils.isSupportedCollectionOrArray(paramType)) {
+                    paramValues = Collections.emptyList();
                 } else {
                     return null;
                 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=998736&r1=998735&r2=998736&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java Sun Sep 19
21:25:49 2010
@@ -268,7 +268,18 @@ public class Customer extends AbstractCu
     
     @Produces("text/xml")   
     public void testQuery(@QueryParam("query") String queryString, 
-                          @QueryParam("query") int queryInt) {
+                          @QueryParam("query") int queryInt,
+                          @QueryParam("query2") String query2,
+                          @QueryParam("query3") String query3) {
+        // complete
+    }
+    
+    @Produces("text/xml")   
+    public void testQueryAsList(
+        @DefaultValue("default") @QueryParam("query") List<String> queryString,
+        @QueryParam("query2") List<String> queryString2,
+        @QueryParam("query3") List<String> queryString3,
+        @QueryParam("query4") List<String> queryString4) {
         // complete
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProviderTest.java?rev=998736&r1=998735&r2=998736&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CacheControlHeaderProviderTest.java
Sun Sep 19 21:25:49 2010
@@ -21,17 +21,18 @@ package org.apache.cxf.jaxrs.impl;
 
 import javax.ws.rs.core.CacheControl;
 
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+
 import org.junit.Assert;
 import org.junit.Test;
 
 public class CacheControlHeaderProviderTest extends Assert {
     
-    
-        
     @Test
     public void testFromSimpleString() {
         CacheControl c = CacheControl.valueOf(
-            "public;must-revalidate");
+            "public,must-revalidate");
         assertTrue(!c.isPrivate() && !c.isNoStore()
                    && c.isMustRevalidate() && !c.isProxyRevalidate());
         assertTrue(!c.isNoCache()
@@ -42,6 +43,27 @@ public class CacheControlHeaderProviderT
     @Test
     public void testFromComplexString() {
         CacheControl c = CacheControl.valueOf(
+            "private=\"foo\",no-cache=\"bar\",no-store,no-transform,"
+            + "must-revalidate,proxy-revalidate,max-age=2,s-maxage=3");
+        assertTrue(c.isPrivate() && c.isNoStore()
+                   && c.isMustRevalidate() && c.isProxyRevalidate() &&
c.isNoCache());
+        assertTrue(c.isNoTransform() && c.getNoCacheFields().size() == 1
+                   && c.getPrivateFields().size() == 1);
+        assertEquals("foo", c.getPrivateFields().get(0));
+        assertEquals("bar", c.getNoCacheFields().get(0));
+        
+    }
+    
+    @Test
+    public void testFromComplexStringWithSemicolon() {
+        CacheControlHeaderProvider cp = new CacheControlHeaderProvider() {
+            protected Message getCurrentMessage() {
+                Message m = new MessageImpl();
+                m.put(CacheControlHeaderProvider.CACHE_CONTROL_SEPARATOR_PROPERTY, ";");
+                return m;
+            }
+        };
+        CacheControl c = cp.fromString(
             "private=\"foo\";no-cache=\"bar\";no-store;no-transform;"
             + "must-revalidate;proxy-revalidate;max-age=2;s-maxage=3");
         assertTrue(c.isPrivate() && c.isNoStore()
@@ -56,8 +78,8 @@ public class CacheControlHeaderProviderT
     
     @Test
     public void testToString() {
-        String s = "private=\"foo\";no-cache=\"bar\";no-store;no-transform;"
-            + "must-revalidate;proxy-revalidate;max-age=2;s-maxage=3";
+        String s = "private=\"foo\",no-cache=\"bar\",no-store,no-transform,"
+            + "must-revalidate,proxy-revalidate,max-age=2,s-maxage=3";
         String parsed = CacheControl.valueOf(s).toString();
         assertEquals(s, parsed);       
     }
@@ -66,7 +88,7 @@ public class CacheControlHeaderProviderT
     public void testNoCacheEnabled() {
         CacheControl cc = new CacheControl();
         cc.setNoCache(true);
-        assertEquals("no-cache;no-transform", cc.toString());
+        assertEquals("no-cache,no-transform", cc.toString());
     }
     
     @Test

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=998736&r1=998735&r2=998736&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Sun Sep 19 21:25:49 2010
@@ -526,18 +526,50 @@ public class JAXRSUtilsTest extends Asse
     
     @Test
     public void testQueryParameters() throws Exception {
-        Class[] argType = {String.class, Integer.TYPE};
+        Class[] argType = {String.class, Integer.TYPE, String.class, String.class};
         Method m = Customer.class.getMethod("testQuery", argType);
         MessageImpl messageImpl = new MessageImpl();
         
-        messageImpl.put(Message.QUERY_STRING, "query=24");
+        messageImpl.put(Message.QUERY_STRING, "query=24&query2");
         List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null),
                                                            null, 
                                                            messageImpl);
+        assertEquals(4, params.size());
         assertEquals("Query Parameter was not matched correctly", "24", params.get(0));
         assertEquals("Primitive Query Parameter was not matched correctly", 24, params.get(1));
-        
-        
+        assertEquals("", params.get(2));
+        assertNull(params.get(3));
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testQueryParamAsListWithDefaultValue() throws Exception {
+        Class[] argType = {List.class, List.class, List.class, List.class};
+        Method m = Customer.class.getMethod("testQueryAsList", argType);
+        MessageImpl messageImpl = new MessageImpl();
+        messageImpl.put(Message.QUERY_STRING, "query2=query2Value&query3");
+        List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null),
+                                                           null, 
+                                                           messageImpl);
+        assertEquals(4, params.size());
+        List<String> queryList = (List<String>)params.get(0);
+        assertNotNull(queryList);
+        assertEquals(1, queryList.size());
+        assertEquals("default", queryList.get(0));
+        
+        List<String> queryList2 = (List<String>)params.get(1);
+        assertNotNull(queryList2);
+        assertEquals(1, queryList2.size());
+        assertEquals("query2Value", queryList2.get(0));
+        
+        List<String> queryList3 = (List<String>)params.get(2);
+        assertNotNull(queryList3);
+        assertEquals(1, queryList3.size());
+        assertEquals("", queryList3.get(0));
+        
+        List<String> queryList4 = (List<String>)params.get(3);
+        assertNotNull(queryList4);
+        assertEquals(0, queryList4.size());
     }
     
     @Test



Mime
View raw message