cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1460012 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
Date Fri, 22 Mar 2013 21:45:21 GMT
Author: sergeyb
Date: Fri Mar 22 21:45:21 2013
New Revision: 1460012

URL: http://svn.apache.org/r1460012
Log:
Minor updates to HttpHeadersImpl to return correct defaults for missing Accept and Locale

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java?rev=1460012&r1=1460011&r2=1460012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
Fri Mar 22 21:45:21 2013
@@ -87,8 +87,8 @@ public class HttpHeadersImpl implements 
     
     public List<MediaType> getAcceptableMediaTypes() {
         List<String> lValues = headers.get(HttpHeaders.ACCEPT);
-        if (lValues == null || lValues.isEmpty()) {
-            return Collections.emptyList();
+        if (lValues == null || lValues.isEmpty() || lValues.get(0) == null) {
+            return Collections.singletonList(MediaType.WILDCARD_TYPE);
         }
         List<MediaType> mediaTypes = JAXRSUtils.parseMediaTypes(lValues.get(0));
         sortMediaTypesUsingQualityFactor(mediaTypes); 
@@ -148,6 +148,9 @@ public class HttpHeadersImpl implements 
 
     public List<Locale> getAcceptableLanguages() {
         List<String> ls = getListValues(HttpHeaders.ACCEPT_LANGUAGE);
+        if (ls.isEmpty()) {
+            return Collections.singletonList(new Locale("*"));
+        }
         
         List<Locale> newLs = new ArrayList<Locale>(); 
         Map<Locale, Float> prefs = new HashMap<Locale, Float>();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java?rev=1460012&r1=1460011&r2=1460012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java Fri
Mar 22 21:45:21 2013
@@ -93,8 +93,11 @@ public class RequestImpl implements Requ
     }
 
     private static boolean isLanguageMatched(List<Locale> locales, Locale l) {
+        
         for (Locale locale : locales) {
-            if (locale.getLanguage().equalsIgnoreCase(l.getLanguage())) {
+            String language = locale.getLanguage();
+            if ("*".equals(language) 
+                || language.equalsIgnoreCase(l.getLanguage())) {
                 return true;
             }
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java?rev=1460012&r1=1460011&r2=1460012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
Fri Mar 22 21:45:21 2013
@@ -255,6 +255,32 @@ public class HttpHeadersImplTest extends
     }
     
     @Test
+    public void testGetNoMediaTypes() throws Exception {
+        
+        Message m = control.createMock(Message.class);
+        m.get(Message.PROTOCOL_HEADERS);
+        EasyMock.expectLastCall().andReturn(Collections.emptyMap());
+        control.replay();
+        HttpHeaders h = new HttpHeadersImpl(m);
+        List<MediaType> acceptValues = h.getAcceptableMediaTypes();
+        assertEquals(1, acceptValues.size());
+        assertEquals("*/*", acceptValues.get(0).toString());
+    }
+    
+    @Test
+    public void testGetNoLanguages() throws Exception {
+        
+        Message m = control.createMock(Message.class);
+        m.get(Message.PROTOCOL_HEADERS);
+        EasyMock.expectLastCall().andReturn(Collections.emptyMap());
+        control.replay();
+        HttpHeaders h = new HttpHeadersImpl(m);
+        List<Locale> locales = h.getAcceptableLanguages();
+        assertEquals(1, locales.size());
+        assertEquals("*", locales.get(0).toString());
+    }
+    
+    @Test
     public void testGetHeader() throws Exception {
         
         Message m = control.createMock(Message.class);



Mime
View raw message