cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1063267 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Date Tue, 25 Jan 2011 13:25:10 GMT
Author: sergeyb
Date: Tue Jan 25 13:25:10 2011
New Revision: 1063267

URL: http://svn.apache.org/viewvc?rev=1063267&view=rev
Log:
[CXF-3285] Avoiding explicit use of regular expressions in JAXRSUtils

Modified:
    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/utils/JAXRSUtilsTest.java

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=1063267&r1=1063266&r2=1063267&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 Tue
Jan 25 13:25:10 2011
@@ -1066,11 +1066,14 @@ public final class JAXRSUtils {
                     requiredType.isCompatible(userType) || userType.isCompatible(requiredType);
                 if (!isCompatible && requiredType.getType().equalsIgnoreCase(userType.getType()))
{
                     // check if we have composite subtypes
-                    String[] subtypes1 = requiredType.getSubtype().split("\\+");
-                    String[] subtypes2 = userType.getSubtype().split("\\+");
-                    if (subtypes1.length == 2 && subtypes2.length == 2
-                        && subtypes1[1].equalsIgnoreCase(subtypes2[1])
-                        && (subtypes1[0].equals("*") || subtypes2[0].equals("*")))
{
+                    String subType1 = requiredType.getSubtype();
+                    String subTypeAfterPlus1 = splitMediaSubType(subType1); 
+                    String subType2 = userType.getSubtype();
+                    String subTypeAfterPlus2 = splitMediaSubType(subType2);
+                    
+                    if (subTypeAfterPlus1 != null && subTypeAfterPlus2 != null
+                        && subTypeAfterPlus1.equalsIgnoreCase(subTypeAfterPlus2)
+                        && (subType1.charAt(0) == '*' || subType2.charAt(0) == '*'))
{
                         isCompatible = true;
                     }
                 }
@@ -1086,10 +1089,10 @@ public final class JAXRSUtils {
                     if (!parametersMatched) {
                         continue;
                     }
-                    
+                   
                     String type = requiredType.getType().equals(MediaType.MEDIA_TYPE_WILDCARD)

                                       ? userType.getType() : requiredType.getType();
-                    String subtype = requiredType.getSubtype().equals(MediaType.MEDIA_TYPE_WILDCARD)

+                    String subtype = requiredType.getSubtype().startsWith(MediaType.MEDIA_TYPE_WILDCARD)

                                       ? userType.getSubtype() : requiredType.getSubtype();
                     Map<String, String> parameters = userType.getParameters();
                     if (addRequiredParamsIfPossible) {
@@ -1109,6 +1112,11 @@ public final class JAXRSUtils {
         
     }
     
+    static String splitMediaSubType(String type) {
+        int index = type.indexOf('+');
+        return index == -1 ? null : type.substring(index + 1);
+    }
+    
     public static List<MediaType> intersectMimeTypes(List<MediaType> mimeTypesA,

                                                      MediaType mimeTypeB) {
         return intersectMimeTypes(mimeTypesA, 

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=1063267&r1=1063266&r2=1063267&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
Tue Jan 25 13:25:10 2011
@@ -307,6 +307,33 @@ public class JAXRSUtilsTest extends Asse
     }
     
     @Test
+    public void testIntersectMimeTypesCompositeSubtype2() throws Exception {
+        List <MediaType> candidateList = 
+            JAXRSUtils.intersectMimeTypes("application/bar+xml", "application/bar+xml");
 
+
+        assertEquals(1, candidateList.size());
+        assertEquals("application/bar+xml", candidateList.get(0).toString());
+    }
+    
+    @Test
+    public void testIntersectMimeTypesCompositeSubtype3() throws Exception {
+        List <MediaType> candidateList = 
+            JAXRSUtils.intersectMimeTypes("application/*+xml", "application/bar+xml");  
+
+        assertEquals(1, candidateList.size());
+        assertEquals("application/bar+xml", candidateList.get(0).toString());
+    }
+    
+    @Test
+    public void testIntersectMimeTypesCompositeSubtype4() throws Exception {
+        List <MediaType> candidateList = 
+            JAXRSUtils.intersectMimeTypes("application/*+xml", "application/bar+json"); 

+
+        assertEquals(0, candidateList.size());
+        
+    }
+    
+    @Test
     public void testIntersectMimeTypes() throws Exception {
         //test basic
         List<MediaType> methodMimeTypes = new ArrayList<MediaType>(



Mime
View raw message