cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r769027 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/ test/java/org/apache/cxf/jaxrs/impl/
Date Mon, 27 Apr 2009 15:29:38 GMT
Author: sergeyb
Date: Mon Apr 27 15:29:37 2009
New Revision: 769027

URL: http://svn.apache.org/viewvc?rev=769027&view=rev
Log:
JAXRS: minor updates to Cookie and ETag handlers

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CookieHeaderProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProviderTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java?rev=769027&r1=769026&r2=769027&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java
Mon Apr 27 15:29:37 2009
@@ -27,9 +27,15 @@
     private static final String PATH = "$Path";
     private static final String DOMAIN = "$Domain";
     
+    private static final String DOUBLE_QUOTE = "\""; 
+    
     public Cookie fromString(String c) {
         
-        int version = Cookie.DEFAULT_VERSION;
+        if (c == null) {
+            throw new IllegalArgumentException("Cookie value can not be null");
+        }
+        
+        int version = 0;
         String name = null;
         String value = null;
         String path = null;
@@ -38,17 +44,18 @@
         // ignore the fact the possible version may be seperated by ','
         String[] tokens = c.split(";");
         for (String token : tokens) {
-            if (token.startsWith(VERSION)) {
-                version = Integer.parseInt(token.substring(VERSION.length() + 1));
-            } else if (token.startsWith(PATH)) {
-                path = token.substring(PATH.length() + 1);
-            } else if (token.startsWith(DOMAIN)) {
-                domain = token.substring(DOMAIN.length() + 1);
+            String theToken = token.trim();
+            if (theToken.startsWith(VERSION)) {
+                version = Integer.parseInt(stripQuotes(theToken.substring(VERSION.length()
+ 1)));
+            } else if (theToken.startsWith(PATH)) {
+                path = stripQuotes(theToken.substring(PATH.length() + 1));
+            } else if (theToken.startsWith(DOMAIN)) {
+                domain = stripQuotes(theToken.substring(DOMAIN.length() + 1));
             } else {
-                int i = token.indexOf('=');
+                int i = theToken.indexOf('=');
                 if (i != -1) {
-                    name = token.substring(0, i);
-                    value = i == token.length()  + 1 ? "" : token.substring(i + 1);
+                    name = theToken.substring(0, i);
+                    value = i == theToken.length()  + 1 ? "" : stripQuotes(theToken.substring(i
+ 1));
                 }
             }
         }
@@ -60,11 +67,14 @@
         return new Cookie(name, value, path, domain, version);
     }
 
+    private String stripQuotes(String value) {
+        return value.replaceAll(DOUBLE_QUOTE, "");
+    }
     
     public String toString(Cookie c) {
         StringBuilder sb = new StringBuilder();
         
-        if (c.getVersion() != Cookie.DEFAULT_VERSION) {
+        if (c.getVersion() != 0) {
             sb.append(VERSION).append('=').append(c.getVersion()).append(';');
         }
         sb.append(c.getName()).append('=').append(c.getValue());

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java?rev=769027&r1=769026&r2=769027&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java
Mon Apr 27 15:29:37 2009
@@ -27,6 +27,11 @@
     private static final String WEAK_PREFIX = "W/";
     
     public EntityTag fromString(String header) {
+        
+        if (header == null) {
+            throw new IllegalArgumentException("ETag value can not be null");
+        }
+        
         String tag = null;
         boolean weak =  false;
         int i = header.indexOf(WEAK_PREFIX);

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CookieHeaderProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CookieHeaderProviderTest.java?rev=769027&r1=769026&r2=769027&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CookieHeaderProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CookieHeaderProviderTest.java
Mon Apr 27 15:29:37 2009
@@ -31,7 +31,8 @@
     public void testFromSimpleString() {
         Cookie c = Cookie.valueOf("foo=bar");
         assertTrue("bar".equals(c.getValue())
-                   && "foo".equals(c.getName()));
+                   && "foo".equals(c.getName())
+                   && 0 == c.getVersion());
     }
     
     @Test
@@ -58,4 +59,20 @@
                      c.toString());
                
     }
+    
+    @Test
+    public void testCookieWithQuotes() {
+        Cookie c = Cookie.valueOf("$Version=\"1\"; foo=\"bar\"; $Path=\"/path\"");
+        assertTrue("bar".equals(c.getValue())
+                   && "foo".equals(c.getName())
+                   && 1 == c.getVersion()
+                   && "/path".equals(c.getPath())
+                   && null == c.getDomain());
+    }
+    
+    @Test(expected = IllegalArgumentException.class)
+    public void testNullValue() throws Exception {
+        Cookie.valueOf(null);
+    }
+    
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProviderTest.java?rev=769027&r1=769026&r2=769027&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProviderTest.java
Mon Apr 27 15:29:37 2009
@@ -49,4 +49,9 @@
         assertEquals("\"bar\"", tag.toString());
         
     }
+    
+    @Test(expected = IllegalArgumentException.class)
+    public void testNullValue() throws Exception {
+        EntityTag.valueOf(null);
+    }
 }



Mime
View raw message