cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r724770 - in /cxf/branches/2.1.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/te...
Date Tue, 09 Dec 2008 16:31:37 GMT
Author: sergeyb
Date: Tue Dec  9 08:31:37 2008
New Revision: 724770

URL: http://svn.apache.org/viewvc?rev=724770&view=rev
Log:
Merged revisions 722412 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r722412 | sergeyb | 2008-12-02 10:20:54 +0000 (Tue, 02 Dec 2008) | 1 line
  
  JAXRS : fixing issues with the lists of HTTP header values
........

Modified:
    cxf/branches/2.1.x-fixes/   (props changed)
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
    cxf/branches/2.1.x-fixes/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_async_noservice.wsdl
  (props changed)

Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Dec  9 08:31:37 2008
@@ -1 +1 @@
-/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937,704997,705150,705235,705274,705340,705446,705548,705614,705692,705708,706482,706631,706675,706900,706909,707034,707089,707100,707902,708035,708044,708074,708410,708417,708550,708554,709353-709354,709425,710076,710150,71015
 4,711193,711388,711410,711490,711635,711949,711975,712194,712198,712238,712272,712299,712312,712670,712893,713082,713095-713096,713099,713584,713597,713737,713804,713899,714167-714168,714245,714255,717937-717961,718281-718448,718565,718620,718640,718665,718970,719017,719210,719215-719218,719222-719273,719305,719327-719680,720053,720119-720218,720238,720293-720316,720497,721221,721241,721501,722117,722129,723024,723338,723716-723791,724333-724372,724433-724438,724449,724481,724485,724668
+/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937,704997,705150,705235,705274,705340,705446,705548,705614,705692,705708,706482,706631,706675,706900,706909,707034,707089,707100,707902,708035,708044,708074,708410,708417,708550,708554,709353-709354,709425,710076,710150,71015
 4,711193,711388,711410,711490,711635,711949,711975,712194,712198,712238,712272,712299,712312,712670,712893,713082,713095-713096,713099,713584,713597,713737,713804,713899,714167-714168,714245,714255,717937-717961,718281-718448,718565,718620,718640,718665,718970,719017,719210,719215-719218,719222-719273,719305,719327-719680,720053,720119-720218,720238,720293-720316,720497,721221,721241,721501,722117,722129,722412,723024,723338,723716-723791,724333-724372,724433-724438,724449,724481,724485,724668

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

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

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java?rev=724770&r1=724769&r2=724770&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
Tue Dec  9 08:31:37 2008
@@ -73,12 +73,14 @@
     public MultivaluedMap<String, String> getRequestHeaders() {
         // should we really worry about immutability given that the Message does not ?
         MultivaluedMap<String, String> map = new MetadataMap<String, String>();
-        map.putAll(headers);
+        for (String key : headers.keySet()) {
+            map.put(key, getRequestHeader(key));
+        }
         return map;
     }
 
     public List<String> getAcceptableLanguages() {
-        List<String> values = getRequestHeader(HttpHeaders.ACCEPT_LANGUAGE);
+        List<String> values = headers.get(HttpHeaders.ACCEPT_LANGUAGE);
         if (values == null || values.isEmpty()) {
             return Collections.emptyList();
         }
@@ -108,7 +110,16 @@
     }
 
     public List<String> getRequestHeader(String name) {
-        return headers.get(name);
+        List<String> values = headers.get(name); 
+        if (values == null || values.isEmpty()) {
+            return Collections.emptyList();
+        }
+        List<String> hValues = new ArrayList<String>();
+        String[] ls =  values.get(0).split(",");
+        for (String s : ls) {
+            hValues.add(s.trim());
+        }
+        return hValues;
     }
 
     private static class AcceptLanguageComparator implements Comparator<String> {

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=724770&r1=724769&r2=724770&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Tue Dec  9 08:31:37 2008
@@ -32,7 +32,6 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -514,21 +513,23 @@
     }
     
     @SuppressWarnings("unchecked")
-    private static Object processHeaderParam(Message m, String header, 
-                                             Class<?> pClass, Type genericType, String
defaultValue) {
-        Map<String, List<String>> headers = (Map<String, List<String>>)m.get(Message.PROTOCOL_HEADERS);
-        List<String> values = headers.get(header);
-        StringBuilder sb = new StringBuilder();
-        if (values != null) {
-            for (Iterator<String> it = values.iterator(); it.hasNext();) {
-                sb.append(it.next());
-                if (it.hasNext()) {
-                    sb.append(',');
-                }
-            }
-        }
-        return sb.length() > 0 ? InjectionUtils.handleParameter(sb.toString(), pClass,
false) 
-                               : defaultValue;
+    private static Object processHeaderParam(Message m, 
+                                             String header, 
+                                             Class<?> pClass, 
+                                             Type genericType, 
+                                             String defaultValue) {
+        
+        List<String> values = new HttpHeadersImpl(m).getRequestHeader(header);
+        
+        return InjectionUtils.createParameterObject(values, 
+                                                    pClass, 
+                                                    genericType,
+                                                    defaultValue,
+                                                    false,
+                                                    false,
+                                                    false);
+             
+        
     }
     
     @SuppressWarnings("unchecked")

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=724770&r1=724769&r2=724770&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
Tue Dec  9 08:31:37 2008
@@ -229,7 +229,8 @@
                            @Context Request r,
                            @Context SecurityContext s,
                            @Context MessageBodyWorkers workers,
-                           @HeaderParam("Foo") String h) {
+                           @HeaderParam("Foo") String h,
+                           @HeaderParam("Foo") List<String> l) {
         // complete
     }
     

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java?rev=724770&r1=724769&r2=724770&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
Tue Dec  9 08:31:37 2008
@@ -50,12 +50,31 @@
         control.replay();
         HttpHeaders h = new HttpHeadersImpl(m);
         MultivaluedMap<String, String> hs = h.getRequestHeaders();
-        assertEquals(hs.getFirst("Accept"), "text/*");
+        List<String> acceptValues = hs.get("Accept");
+        assertEquals("text/*;q=1", acceptValues.get(0));
+        assertEquals("application/xml", acceptValues.get(1));
         assertEquals(hs.getFirst("Content-Type"), "*/*");
     }
+
+    public void testGetHeader() throws Exception {
+        
+        Message m = control.createMock(Message.class);
+        m.get(Message.PROTOCOL_HEADERS);
+        EasyMock.expectLastCall().andReturn(createHeaders());
+        control.replay();
+        HttpHeaders h = new HttpHeadersImpl(m);
+        List<String> acceptValues = h.getRequestHeader("Accept");
+        assertEquals(2, acceptValues.size());
+        assertEquals("text/*;q=1", acceptValues.get(0));
+        assertEquals("application/xml", acceptValues.get(1));
+        List<String> contentValues = h.getRequestHeader("Content-Type");
+        assertEquals(1, contentValues.size());
+        assertEquals("*/*", contentValues.get(0));
+        
+    }
     
     @Test
-    public void testGetLanguage() throws Exception {
+    public void testGetNullLanguage() throws Exception {
         
         Message m = control.createMock(Message.class);
         m.get(Message.PROTOCOL_HEADERS);
@@ -68,7 +87,7 @@
         
     private Map<String, List<String>> createHeaders() {
         MetadataMap<String, String> hs = new MetadataMap<String, String>();
-        hs.putSingle("Accept", "text/*");
+        hs.putSingle("Accept", "text/*;q=1,application/xml");
         hs.putSingle("Content-Type", "*/*");
         return hs;
     }

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=724770&r1=724769&r2=724770&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Tue Dec  9 08:31:37 2008
@@ -661,6 +661,7 @@
         assertSame(ori, ori2);
     }
     
+    @SuppressWarnings("unchecked")
     @Test
     public void testHttpContextParameters() throws Exception {
         
@@ -673,26 +674,30 @@
                                                      Request.class,
                                                      SecurityContext.class,
                                                      MessageBodyWorkers.class,
-                                                     String.class}), 
+                                                     String.class,
+                                                     List.class}), 
                 cri);
         ori.setHttpMethod("GET");
         MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
-        headers.add("Foo", "bar");
-        headers.add("Foo", "baz");
+        headers.add("Foo", "bar, baz");
         
         Message m = new MessageImpl();
         m.put(Message.PROTOCOL_HEADERS, headers);
         
         List<Object> params = 
             JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m);
-        assertEquals("6 parameters expected", 6, params.size());
+        assertEquals("7 parameters expected", 7, params.size());
         assertSame(UriInfoImpl.class, params.get(0).getClass());
         assertSame(HttpHeadersImpl.class, params.get(1).getClass());
         assertSame(RequestImpl.class, params.get(2).getClass());
         assertSame(SecurityContextImpl.class, params.get(3).getClass());
         assertSame(MessageBodyWorkersImpl.class, params.get(4).getClass());
         assertSame(String.class, params.get(5).getClass());
-        assertEquals("Wrong header param", "bar,baz", params.get(5));
+        assertEquals("Wrong header param", "bar", params.get(5));
+        List<String> values = (List<String>)params.get(6);
+        assertEquals("Wrong headers size", 2, values.size());
+        assertEquals("Wrong 1st header param", "bar", values.get(0));
+        assertEquals("Wrong 2nd header param", "baz", values.get(1));
     }
     
     @Test

Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=724770&r1=724769&r2=724770&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Tue Dec  9 08:31:37 2008
@@ -24,12 +24,14 @@
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.ConsumeMime;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
 import javax.ws.rs.MatrixParam;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
@@ -116,6 +118,13 @@
     }
     
     @GET
+    @Path("/bookheaders/")
+    public Book getBookByHeader(@HeaderParam("BOOK") List<String> ids) throws Exception
{
+        
+        return doGetBook(ids.get(0) + ids.get(1) + ids.get(2));
+    }
+    
+    @GET
     @Path("/bookquery")
     public Book getBookByURLQuery(@QueryParam("urlid") String urlValue) throws Exception
{
         String url2 = new URL(urlValue).toString();

Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=724770&r1=724769&r2=724770&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Tue Dec  9 08:31:37 2008
@@ -219,6 +219,13 @@
     }
     
     @Test
+    public void testGetBookByHeader() throws Exception {
+        getAndCompareAsStrings("http://localhost:9080/bookstore/bookheaders",
+                               "resources/expected_get_book123.txt",
+                               "application/xml", 200);
+    }
+    
+    @Test
     public void testGetBookByMatrixParameters() throws Exception {
         getAndCompareAsStrings("http://localhost:9080/bookstore/segment/matrix;first=12;second=3",
                                "resources/expected_get_book123.txt",
@@ -661,6 +668,7 @@
         GetMethod get = new GetMethod(address);
         get.setRequestHeader("Accept", acceptType);
         get.setRequestHeader("Accept-Language", "en,da;q=0.8");
+        get.setRequestHeader("BOOK", "1,2,3");
         HttpClient httpClient = new HttpClient();
         try {
             int result = httpClient.executeMethod(get);

Propchange: cxf/branches/2.1.x-fixes/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_async_noservice.wsdl
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Dec  9 08:31:37 2008
@@ -1 +1 @@
-/cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_async_noservice.wsdl:724485,724668
+/cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_async_noservice.wsdl:722412,724485,724668



Mime
View raw message