cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1460016 - in /cxf/branches/2.7.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 Fri, 22 Mar 2013 21:49:13 GMT
Author: sergeyb
Date: Fri Mar 22 21:49:13 2013
New Revision: 1460016

URL: http://svn.apache.org/r1460016
Log:
Merged revisions 1460012 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1460012 | sergeyb | 2013-03-22 21:45:21 +0000 (Fri, 22 Mar 2013) | 1 line
  
  Minor updates to HttpHeadersImpl to return correct defaults for missing Accept and Locale
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1460012

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

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java?rev=1460016&r1=1460015&r2=1460016&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
Fri Mar 22 21:49:13 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/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java?rev=1460016&r1=1460015&r2=1460016&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
Fri Mar 22 21:49:13 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/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java?rev=1460016&r1=1460015&r2=1460016&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
Fri Mar 22 21:49:13 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