cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1466845 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/interceptor/ main/java/org/apache/cxf/jaxrs/provider/ main/java/org/apache/cxf/jaxrs/utils/ test/java/org/apache/cxf/jaxrs/ test/java/org/apache/cxf/jaxrs/utils/
Date Thu, 11 Apr 2013 12:28:54 GMT
Author: sergeyb
Date: Thu Apr 11 12:28:53 2013
New Revision: 1466845

URL: http://svn.apache.org/r1466845
Log:
[CXF-4950] Removing few JAXRSUtils shortcut methods to avoid the unexpected results

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=1466845&r1=1466844&r2=1466845&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Thu Apr 11 12:28:53 2013
@@ -138,7 +138,7 @@ public class JAXRSInInterceptor extends 
         }
         List<MediaType> acceptContentTypes = null;
         try {
-            acceptContentTypes = JAXRSUtils.sortMediaTypes(acceptTypes);
+            acceptContentTypes = JAXRSUtils.sortMediaTypes(acceptTypes, JAXRSUtils.MEDIA_TYPE_Q_PARAM);
         } catch (IllegalArgumentException ex) {
             throw new NotAcceptableException();
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1466845&r1=1466844&r2=1466845&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Thu Apr 11 12:28:53 2013
@@ -705,11 +705,11 @@ public abstract class ProviderFactory {
             MessageBodyReader<?> e1 = p1.getProvider();
             MessageBodyReader<?> e2 = p2.getProvider();
             List<MediaType> types1 = JAXRSUtils.getProviderConsumeTypes(e1);
-            types1 = JAXRSUtils.sortMediaTypes(types1);
+            types1 = JAXRSUtils.sortMediaTypes(types1, null);
             List<MediaType> types2 = JAXRSUtils.getProviderConsumeTypes(e2);
-            types2 = JAXRSUtils.sortMediaTypes(types2);
+            types2 = JAXRSUtils.sortMediaTypes(types2, null);
     
-            return JAXRSUtils.compareSortedMediaTypes(types1, types2);
+            return JAXRSUtils.compareSortedMediaTypes(types1, types2, null);
         }
     }
     
@@ -722,11 +722,11 @@ public abstract class ProviderFactory {
             MessageBodyWriter<?> e2 = p2.getProvider();
             
             List<MediaType> types1 =
-                JAXRSUtils.sortMediaTypes(JAXRSUtils.getProviderProduceTypes(e1));
+                JAXRSUtils.sortMediaTypes(JAXRSUtils.getProviderProduceTypes(e1), JAXRSUtils.MEDIA_TYPE_QS_PARAM);
             List<MediaType> types2 =
-                JAXRSUtils.sortMediaTypes(JAXRSUtils.getProviderProduceTypes(e2));
+                JAXRSUtils.sortMediaTypes(JAXRSUtils.getProviderProduceTypes(e2), JAXRSUtils.MEDIA_TYPE_QS_PARAM);
     
-            return JAXRSUtils.compareSortedMediaTypes(types1, types2);
+            return JAXRSUtils.compareSortedMediaTypes(types1, types2, JAXRSUtils.MEDIA_TYPE_QS_PARAM);
         }
     }
     
@@ -740,12 +740,12 @@ public abstract class ProviderFactory {
             
             List<MediaType> types1 =
                 JAXRSUtils.sortMediaTypes(JAXRSUtils.getProduceTypes(
-                                               e1.getClass().getAnnotation(Produces.class)));
+                     e1.getClass().getAnnotation(Produces.class)), JAXRSUtils.MEDIA_TYPE_QS_PARAM);
             List<MediaType> types2 =
                 JAXRSUtils.sortMediaTypes(JAXRSUtils.getProduceTypes(
-                                               e2.getClass().getAnnotation(Produces.class)));
+                     e2.getClass().getAnnotation(Produces.class)), JAXRSUtils.MEDIA_TYPE_QS_PARAM);
     
-            return JAXRSUtils.compareSortedMediaTypes(types1, types2);
+            return JAXRSUtils.compareSortedMediaTypes(types1, types2, JAXRSUtils.MEDIA_TYPE_QS_PARAM);
         }
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1466845&r1=1466844&r2=1466845&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Thu
Apr 11 12:28:53 2013
@@ -689,10 +689,6 @@ public final class JAXRSUtils {
         return actualMts;
     }
     
-    public static int compareSortedMediaTypes(List<MediaType> mts1, List<MediaType>
mts2) {
-        return compareSortedMediaTypes(mts1, mts2, MEDIA_TYPE_Q_PARAM);
-    }
-    
     public static int compareSortedMediaTypes(List<MediaType> mts1, List<MediaType>
mts2, String qs) {
         int size1 = mts1.size();
         int size2 = mts2.size();
@@ -1533,16 +1529,9 @@ public final class JAXRSUtils {
                                   false);
     }
     
-    public static List<MediaType> sortMediaTypes(String mediaTypes) {
-        return sortMediaTypes(JAXRSUtils.parseMediaTypes(mediaTypes));
-    }
-    
     public static List<MediaType> sortMediaTypes(String mediaTypes, String qs) {
         return sortMediaTypes(JAXRSUtils.parseMediaTypes(mediaTypes), qs);
     }
-    public static List<MediaType> sortMediaTypes(List<MediaType> types) {
-        return sortMediaTypes(types, MEDIA_TYPE_Q_PARAM);
-    }
     public static List<MediaType> sortMediaTypes(List<MediaType> types, final
String qs) {
         if (types.size() > 1) {
             Collections.sort(types, new Comparator<MediaType>() {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java?rev=1466845&r1=1466844&r2=1466845&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
Thu Apr 11 12:28:53 2013
@@ -86,6 +86,9 @@ public class SelectMethodCandidatesTest 
         doTestGenericSuperType(GenericEntityImpl3.class, "POST");
     }
     
+    private static List<MediaType> sortMediaTypes(String mediaTypes) {
+        return JAXRSUtils.sortMediaTypes(mediaTypes, JAXRSUtils.MEDIA_TYPE_Q_PARAM);
+    }
     @Test
     public void testFindFromAbstractGenericImpl4() throws Exception {
         JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
@@ -119,7 +122,7 @@ public class SelectMethodCandidatesTest 
                                                             "/books",
                                                             "POST",
                                                             values, contentTypes, 
-                                                            JAXRSUtils.sortMediaTypes(acceptContentTypes));
+                                                            sortMediaTypes(acceptContentTypes));
         assertNotNull(ori);
         assertEquals("resourceMethod needs to be selected", "postEntity",
                      ori.getMethodToInvoke().getName());
@@ -169,7 +172,7 @@ public class SelectMethodCandidatesTest 
                                                             "/books",
                                                             "PUT",
                                                             values, contentTypes, 
-                                                            JAXRSUtils.sortMediaTypes(acceptContentTypes));
+                                                            sortMediaTypes(acceptContentTypes));
         assertNotNull(ori);
         assertEquals("resourceMethod needs to be selected", "putEntity",
                      ori.getMethodToInvoke().getName());
@@ -239,7 +242,7 @@ public class SelectMethodCandidatesTest 
                                                             "POST",
                                                             values, 
                                                             contentType, 
-                                                            JAXRSUtils.sortMediaTypes(acceptContentTypes));
+                                                            sortMediaTypes(acceptContentTypes));
         assertNotNull(ori);
         assertEquals(expectedMethodName,  ori.getMethodToInvoke().getName());
     }
@@ -361,7 +364,7 @@ public class SelectMethodCandidatesTest 
      
         OperationResourceInfo ori = JAXRSUtils.findTargetMethod(mResources, m, "GET", 
                                                 values, contentType, 
-                                                JAXRSUtils.sortMediaTypes(acceptContentTypes));
+                                                sortMediaTypes(acceptContentTypes));
         assertNotNull(ori);
         assertEquals(expectedMethodName,  ori.getMethodToInvoke().getName());
         assertEquals(expectedResponseType, m.getExchange().get(Message.CONTENT_TYPE));
@@ -398,7 +401,7 @@ public class SelectMethodCandidatesTest 
                                                             path,
                                                             "PUT",
                                                             values, contentTypes, 
-                                                            JAXRSUtils.sortMediaTypes(acceptContentTypes));
+                                                            sortMediaTypes(acceptContentTypes));
         assertNotNull(ori);
         assertEquals("resourceMethod needs to be selected", methodName,
                      ori.getMethodToInvoke().getName());
@@ -460,7 +463,7 @@ public class SelectMethodCandidatesTest 
                                                             "/books",
                                                             methodName,
                                                             values, contentTypes, 
-                                                            JAXRSUtils.sortMediaTypes(acceptContentTypes));
+                                                            sortMediaTypes(acceptContentTypes));
         assertNotNull(ori);
         assertEquals("resourceMethod needs to be selected", methodName.toLowerCase() + "Entity",
                      ori.getMethodToInvoke().getName());
@@ -508,7 +511,7 @@ public class SelectMethodCandidatesTest 
                                                             path,
                                                             "GET",
                                                             values, contentTypes, 
-                                                            JAXRSUtils.sortMediaTypes(acceptContentTypes));
+                                                            sortMediaTypes(acceptContentTypes));
         assertNotNull(ori);
         assertEquals("resourceMethod needs to be selected", method,
                      ori.getMethodToInvoke().getName());
@@ -528,7 +531,7 @@ public class SelectMethodCandidatesTest 
                                                             "/1/2/3/d/resource1",
                                                             "GET",
                                                             values, contentTypes, 
-                                                            JAXRSUtils.sortMediaTypes(acceptContentTypes));
+                                                            sortMediaTypes(acceptContentTypes));
         
         assertNotNull(ori);
         assertEquals("jsonResource needs to be selected", "jsonResource",
@@ -630,7 +633,7 @@ public class SelectMethodCandidatesTest 
                                       "/1/2/3/d/custom",
                                       "GET",
                                       values, contentTypes, 
-                                      JAXRSUtils.sortMediaTypes(acceptContentTypes));
+                                      sortMediaTypes(acceptContentTypes));
         
         assertNotNull(ori);
         assertEquals("readBar", ori.getMethodToInvoke().getName());
@@ -639,7 +642,7 @@ public class SelectMethodCandidatesTest 
                                       "/1/2/3/d/custom",
                                       "GET",
                                       values, contentTypes, 
-                                      JAXRSUtils.sortMediaTypes(acceptContentTypes));
+                                      sortMediaTypes(acceptContentTypes));
         assertNotNull(ori);
         assertEquals("readFoo", ori.getMethodToInvoke().getName());
         
@@ -648,7 +651,7 @@ public class SelectMethodCandidatesTest 
                                       "/1/2/3/d/custom",
                                       "GET",
                                       values, contentTypes, 
-                                      JAXRSUtils.sortMediaTypes(acceptContentTypes));
+                                      sortMediaTypes(acceptContentTypes));
         assertNotNull(ori);
         assertEquals("readBar", ori.getMethodToInvoke().getName());
         
@@ -657,7 +660,7 @@ public class SelectMethodCandidatesTest 
                                       "/1/2/3/d/custom",
                                       "GET",
                                       values, contentTypes, 
-                                      JAXRSUtils.sortMediaTypes(acceptContentTypes));
+                                      sortMediaTypes(acceptContentTypes));
         assertNotNull(ori);
         assertEquals("readFoo", ori.getMethodToInvoke().getName());
         

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1466845&r1=1466844&r2=1466845&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Thu Apr 11 12:28:53 2013
@@ -630,10 +630,22 @@ public class JAXRSUtilsTest extends Asse
         
     }
     
+    private static List<MediaType> sortMediaTypes(String mediaTypes) {
+        return JAXRSUtils.sortMediaTypes(mediaTypes, JAXRSUtils.MEDIA_TYPE_Q_PARAM);
+    }
+    
+    private static List<MediaType> sortMediaTypes(List<MediaType> mediaTypes)
{
+        return JAXRSUtils.sortMediaTypes(mediaTypes, JAXRSUtils.MEDIA_TYPE_Q_PARAM);
+    }
+    
+    private static int compareSortedMediaTypes(List<MediaType> mt1, List<MediaType>
mt2) {
+        return JAXRSUtils.compareSortedMediaTypes(mt1, mt2, JAXRSUtils.MEDIA_TYPE_Q_PARAM);
+    }
+    
     @Test
     public void testSortMediaTypes() throws Exception {
         List<MediaType> types = 
-            JAXRSUtils.sortMediaTypes("text/*,text/plain;q=.2,text/xml,TEXT/BAR");
+            sortMediaTypes("text/*,text/plain;q=.2,text/xml,TEXT/BAR");
         assertTrue(types.size() == 4
                    && "text/xml".equals(types.get(0).toString())
                    && "text/bar".equals(types.get(1).toString())
@@ -683,14 +695,14 @@ public class JAXRSUtilsTest extends Asse
         MediaType m1 = MediaType.valueOf("text/xml");
         MediaType m2 = MediaType.valueOf("text/*");
         assertTrue("text/xml is more specific than text/*", 
-                   JAXRSUtils.compareSortedMediaTypes(Collections.singletonList(m1), 
+                   compareSortedMediaTypes(Collections.singletonList(m1), 
                                                       Collections.singletonList(m2)) <
0);
         assertTrue("text/* is less specific than text/xml", 
-                   JAXRSUtils.compareSortedMediaTypes(Collections.singletonList(m2), 
+                   compareSortedMediaTypes(Collections.singletonList(m2), 
                                                       Collections.singletonList(m1)) >
0);
         
         assertTrue("text/xml is the same as text/xml", 
-                   JAXRSUtils.compareSortedMediaTypes(Collections.singletonList(m1), 
+                   compareSortedMediaTypes(Collections.singletonList(m1), 
                                                       Collections.singletonList(m1)) == 0);
         
         List<MediaType> sortedList1 = new ArrayList<MediaType>();
@@ -702,14 +714,14 @@ public class JAXRSUtilsTest extends Asse
         sortedList2.add(m2);
         
         assertTrue("lists should be equal", 
-                   JAXRSUtils.compareSortedMediaTypes(sortedList1, sortedList2) == 0);
+                   compareSortedMediaTypes(sortedList1, sortedList2) == 0);
         
         sortedList1.add(MediaType.WILDCARD_TYPE);
         assertTrue("first list should be less specific", 
-                   JAXRSUtils.compareSortedMediaTypes(sortedList1, sortedList2) > 0);
+                   compareSortedMediaTypes(sortedList1, sortedList2) > 0);
         sortedList1.add(MediaType.WILDCARD_TYPE);
         assertTrue("second list should be more specific", 
-                   JAXRSUtils.compareSortedMediaTypes(sortedList2, sortedList1) < 0);
+                   compareSortedMediaTypes(sortedList2, sortedList1) < 0);
     }
     
     @Test
@@ -1491,12 +1503,12 @@ public class JAXRSUtilsTest extends Asse
         
         ori = JAXRSUtils.findTargetMethod(getMap(cri), createMessage2(), "GET", new MetadataMap<String,
String>(), 
                                           "*/*", 
-                                          JAXRSUtils.sortMediaTypes(getTypes("*/*;q=0.1,text/plain,text/xml;q=0.8")));
+                                          sortMediaTypes(getTypes("*/*;q=0.1,text/plain,text/xml;q=0.8")));
                      
         assertSame(ori, ori2);
         ori = JAXRSUtils.findTargetMethod(getMap(cri), createMessage2(), "GET", new MetadataMap<String,
String>(), 
                                           "*/*", 
-                                          JAXRSUtils.sortMediaTypes(getTypes("*;q=0.1,text/plain,text/xml;q=0.9,x/y")));
+                                          sortMediaTypes(getTypes("*;q=0.1,text/plain,text/xml;q=0.9,x/y")));
                      
         assertSame(ori, ori2);
     }



Mime
View raw message