cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1329200 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/
Date Mon, 23 Apr 2012 12:15:03 GMT
Author: sergeyb
Date: Mon Apr 23 12:15:02 2012
New Revision: 1329200

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

................
  r1329185 | sergeyb | 2012-04-23 12:18:09 +0100 (Mon, 23 Apr 2012) | 20 lines
  
  Merged revisions 1329183 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes
  
  ................
    r1329183 | sergeyb | 2012-04-23 12:11:55 +0100 (Mon, 23 Apr 2012) | 13 lines
    
    Merged revisions 1329178,1329180 via svnmerge from 
    https://svn.apache.org/repos/asf/cxf/trunk
    
    ........
      r1329178 | sergeyb | 2012-04-23 12:07:09 +0100 (Mon, 23 Apr 2012) | 1 line
      
      [CXF-4243] Fixing Request.selectVariant implementation
    ........
      r1329180 | sergeyb | 2012-04-23 12:08:06 +0100 (Mon, 23 Apr 2012) | 1 line
      
      [CXF-4259] Updating SetCookie handler to ignore the Expires property
    ........
  ................
................

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/impl/NewCookieHeaderProvider.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.5.x-fixes:r1329183
  Merged /cxf/branches/2.4.x-fixes:r1329185
  Merged /cxf/trunk:r1329178-1329180

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/impl/NewCookieHeaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java?rev=1329200&r1=1329199&r2=1329200&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
Mon Apr 23 12:15:02 2012
@@ -30,6 +30,7 @@ public class NewCookieHeaderProvider imp
     private static final String MAX_AGE = "Max-Age";
     private static final String COMMENT = "Comment";
     private static final String SECURE = "Secure";
+    private static final String EXPIRES = "Expires";
     
     public NewCookie fromString(String c) {
         
@@ -60,6 +61,9 @@ public class NewCookieHeaderProvider imp
                 comment = theToken.substring(COMMENT.length() + 1);
             } else if (theToken.startsWith(SECURE)) {
                 isSecure = true;
+            } else if (theToken.startsWith(EXPIRES)) {
+                // ignore
+                continue;
             } else {
                 int i = theToken.indexOf('=');
                 if (i != -1) {

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java?rev=1329200&r1=1329199&r2=1329200&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
Mon Apr 23 12:15:02 2012
@@ -36,6 +36,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.Variant;
 
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
@@ -61,22 +62,25 @@ public class RequestImpl implements Requ
         if (vars == null || vars.isEmpty()) {
             throw new IllegalArgumentException("List of Variants is either null or empty");
         }
-        MediaType inMediaType = headers.getMediaType();
-        Locale inLang = headers.getLanguage();
-        String inEnc = headers.getRequestHeaders().getFirst(HttpHeaders.CONTENT_ENCODING);
+        List<MediaType> acceptMediaTypes = headers.getAcceptableMediaTypes();
+        List<Locale> acceptLangs = headers.getAcceptableLanguages();
+        List<String> acceptEncs = parseAcceptEnc(
+            headers.getRequestHeaders().getFirst(HttpHeaders.ACCEPT_ENCODING));
         
         List<Variant> matchingVars = new LinkedList<Variant>();
         for (Variant var : vars) {
             MediaType mt = var.getMediaType();
             Locale lang = var.getLanguage();
             String enc = var.getEncoding();
+                        
+            boolean mtMatched = mt == null || acceptMediaTypes.isEmpty()
+                || JAXRSUtils.intersectMimeTypes(acceptMediaTypes, mt).size() != 0;
             
-            boolean mtMatched = mt == null || inMediaType == null
-                || JAXRSUtils.intersectMimeTypes(Collections.singletonList(inMediaType),
mt).size() != 0;
+            boolean encMatched = acceptEncs.isEmpty() || enc == null 
+                || acceptEncs.contains(enc);
             
-            boolean encMatched = inEnc == null || enc == null || inEnc.equalsIgnoreCase(enc);
-            
-            boolean langMatched = inLang == null || lang == null || inLang.equals(lang);
+            boolean langMatched = lang == null || acceptLangs.isEmpty()
+                || isLanguageMatched(acceptLangs, lang);
             
             if (mtMatched && encMatched && langMatched) {
                 matchingVars.add(var);
@@ -88,8 +92,29 @@ public class RequestImpl implements Requ
         return matchingVars.isEmpty() ? null : matchingVars.get(0);
     }
 
+    private static boolean isLanguageMatched(List<Locale> locales, Locale l) {
+        for (Locale locale : locales) {
+            if (locale.getLanguage().equalsIgnoreCase(l.getLanguage())) {
+                return true;
+            }
+        }
+        return false;
+    }
 
-
+    private static List<String> parseAcceptEnc(String acceptEnc) {
+        if (StringUtils.isEmpty(acceptEnc)) {
+            return Collections.emptyList();
+        }
+        List<String> list = new LinkedList<String>();
+        String[] values = acceptEnc.split(",");
+        for (String value : values) {
+            String[] pair = value.trim().split(";");
+            // ignore encoding qualifiers if any for now
+            list.add(pair[0]);
+        }
+        return list;
+    }
+    
     public ResponseBuilder evaluatePreconditions(EntityTag eTag) {
         ResponseBuilder rb = evaluateIfMatch(eTag);
         if (rb == null) {

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java?rev=1329200&r1=1329199&r2=1329200&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
Mon Apr 23 12:15:02 2012
@@ -38,6 +38,13 @@ public class NewCookieHeaderProviderTest
                    && "foo".equals(c.getName()));
     }
     
+    @Test
+    public void testFromSimpleStringWithExpires() {
+        NewCookie c = NewCookie.valueOf("foo=bar;Expires=Wed, 09 Jun 2021 10:18:14 GMT");
+        assertTrue("bar".equals(c.getValue())
+                   && "foo".equals(c.getName()));
+    }
+    
         
     @Test
     public void testFromComplexString() {

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java?rev=1329200&r1=1329199&r2=1329200&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java
Mon Apr 23 12:15:02 2012
@@ -86,9 +86,9 @@ public class RequestImplTest extends Ass
     
     @Test
     public void testSingleNonMatchingVariant() {
-        metadata.putSingle(HttpHeaders.CONTENT_TYPE, "application/xml");
-        metadata.putSingle(HttpHeaders.CONTENT_LANGUAGE, "en");
-        metadata.putSingle(HttpHeaders.CONTENT_ENCODING, "utf-8");
+        metadata.putSingle(HttpHeaders.ACCEPT, "application/xml");
+        metadata.putSingle(HttpHeaders.ACCEPT_LANGUAGE, "en");
+        metadata.putSingle(HttpHeaders.ACCEPT_ENCODING, "utf-8");
         
         List<Variant> list = new ArrayList<Variant>();
         list.add(new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en"), "utf-8"));
@@ -98,9 +98,9 @@ public class RequestImplTest extends Ass
     
     @Test
     public void testMultipleNonMatchingVariants() {
-        metadata.putSingle(HttpHeaders.CONTENT_TYPE, "application/xml");
-        metadata.putSingle(HttpHeaders.CONTENT_LANGUAGE, "en");
-        metadata.putSingle(HttpHeaders.CONTENT_ENCODING, "utf-8");
+        metadata.putSingle(HttpHeaders.ACCEPT, "application/xml");
+        metadata.putSingle(HttpHeaders.ACCEPT_LANGUAGE, "en");
+        metadata.putSingle(HttpHeaders.ACCEPT_ENCODING, "utf-8");
         
         List<Variant> list = new ArrayList<Variant>();
         list.add(new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en"), "utf-8"));
@@ -112,15 +112,15 @@ public class RequestImplTest extends Ass
     
     @Test
     public void testMultipleVariantsSingleMatch() {
-        metadata.putSingle(HttpHeaders.CONTENT_TYPE, "application/xml");
-        metadata.putSingle(HttpHeaders.CONTENT_LANGUAGE, "en");
-        metadata.putSingle(HttpHeaders.CONTENT_ENCODING, "utf-8");
+        metadata.putSingle(HttpHeaders.ACCEPT, "application/xml");
+        metadata.putSingle(HttpHeaders.ACCEPT_LANGUAGE, "en");
+        metadata.putSingle(HttpHeaders.ACCEPT_ENCODING, "gzip");
         
         List<Variant> list = new ArrayList<Variant>();
         list.add(new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en"), "utf-8"));
         list.add(new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("es"), "utf-8"));
         
-        Variant var3 = new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("en"), "utf-8");
+        Variant var3 = new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("en"), "gzip");
         list.add(var3);
         assertSame(var3, new RequestImpl(m).selectVariant(list));
         
@@ -128,13 +128,13 @@ public class RequestImplTest extends Ass
     
     @Test
     public void testMultipleVariantsBestMatch() {
-        metadata.putSingle(HttpHeaders.CONTENT_TYPE, "application/xml");
-        metadata.putSingle(HttpHeaders.CONTENT_LANGUAGE, "en");
-        metadata.putSingle(HttpHeaders.CONTENT_ENCODING, "utf-8");
+        metadata.putSingle(HttpHeaders.ACCEPT, "application/xml");
+        metadata.putSingle(HttpHeaders.ACCEPT_LANGUAGE, "en-us");
+        metadata.putSingle(HttpHeaders.ACCEPT_ENCODING, "gzip;q=1.0, compress");
         
         List<Variant> list = new ArrayList<Variant>();
-        list.add(new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en"), "utf-8"));
-        Variant var2 = new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("en"), "utf-8");
+        list.add(new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en"), "gzip"));
+        Variant var2 = new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("en"), "gzip");
         list.add(var2);
         Variant var3 = new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("en"), null);
         list.add(var3);
@@ -142,7 +142,6 @@ public class RequestImplTest extends Ass
         list.clear();
         list.add(var3);
         assertSame(var3, new RequestImpl(m).selectVariant(list));
-        
     }
     
     private void assertSameVariant(MediaType mt, Locale lang, String enc) {



Mime
View raw message