cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1063268 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Date Tue, 25 Jan 2011 13:27:09 GMT
Author: sergeyb
Date: Tue Jan 25 13:27:09 2011
New Revision: 1063268

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

........
  r1063267 | sergeyb | 2011-01-25 13:25:10 +0000 (Tue, 25 Jan 2011) | 1 line
  
  [CXF-3285] Avoiding explicit use of regular expressions in JAXRSUtils
........

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 25 13:27:09 2011
@@ -1 +1 @@
-/cxf/trunk:1063042,1063205
+/cxf/trunk:1063042,1063205,1063267

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

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1063268&r1=1063267&r2=1063268&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Tue Jan 25 13:27:09 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/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1063268&r1=1063267&r2=1063268&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Tue Jan 25 13:27:09 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