cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1468402 - in /cxf/branches/2.7.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, 16 Apr 2013 13:04:42 GMT
Author: sergeyb
Date: Tue Apr 16 13:04:42 2013
New Revision: 1468402

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

........
  r1468231 | sergeyb | 2013-04-15 22:29:26 +0100 (Mon, 15 Apr 2013) | 1 line
  
  [CXF-4959] Optional support for the partial comparison of subtypes when checking the compatibility
of media types
........

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/utils/JAXRSUtils.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1468231

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/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1468402&r1=1468401&r2=1468402&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Tue Apr 16 13:04:42 2013
@@ -142,6 +142,7 @@ import org.apache.cxf.jaxrs.utils.multip
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
+import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
 
 public final class JAXRSUtils {
@@ -151,6 +152,8 @@ public final class JAXRSUtils {
     public static final String IGNORE_MESSAGE_WRITERS = "ignore.message.writers";
     public static final String ROOT_INSTANCE = "service.root.instance";
     public static final String ROOT_PROVIDER = "service.root.provider";
+    public static final String PARTIAL_HIERARCHICAL_MEDIA_SUBTYPE_CHECK = 
+        "partial.hierarchical.media.subtype.check"; 
     public static final String DOC_LOCATION = "wadl.location";
     public static final String DEFAULT_PROVIDERS_FOR_SIMPLE_TYPES = "defaultProviders.for.simpleTypes";
     public static final String MEDIA_TYPE_Q_PARAM = "q";
@@ -1441,16 +1444,54 @@ public final class JAXRSUtils {
     
     private static boolean isMediaTypeCompatible(MediaType requiredType, MediaType userType)
{
         boolean isCompatible = requiredType.isCompatible(userType);
-        if (!isCompatible && requiredType.getType().equalsIgnoreCase(userType.getType()))
{
-            // check if we have composite subtypes
-            String subType1 = requiredType.getSubtype();
-            String subType2 = userType.getSubtype();
-            
-            String subTypeAfterPlus1 = splitMediaSubType(subType1, true); 
-            String subTypeAfterPlus2 = splitMediaSubType(subType2, true);
-            
+        if (!requiredType.isCompatible(userType) && requiredType.getType().equalsIgnoreCase(userType.getType()))
{
+            isCompatible = compareCompositeSubtypes(requiredType, userType,
+                                                    PhaseInterceptorChain.getCurrentMessage());
+        }
+        return isCompatible;
+    }
+    
+    static boolean compareCompositeSubtypes(String requiredType, String userType,
+                                            Message message) {
+        return compareCompositeSubtypes(toMediaType(requiredType), toMediaType(userType),
message);
+    }
+    
+    private static boolean compareCompositeSubtypes(MediaType requiredType, MediaType userType,
+                                            Message message) {
+        boolean isCompatible = false;
+        // check if we have composite subtypes
+        String subType1 = requiredType.getSubtype();
+        String subType2 = userType.getSubtype();
+        
+        String subTypeAfterPlus1 = splitMediaSubType(subType1, true); 
+        String subTypeAfterPlus2 = splitMediaSubType(subType2, true);
+        if (message != null && MessageUtils.isTrue(
+            message.getContextualProperty(PARTIAL_HIERARCHICAL_MEDIA_SUBTYPE_CHECK))) { 
   
+            if (subTypeAfterPlus1 != null || subTypeAfterPlus2 != null) {
+                boolean nullPossible = subTypeAfterPlus1 == null || subTypeAfterPlus2 ==
null;
+                isCompatible = subTypeAfterPlus1 == null && subTypeAfterPlus2.equals(subType1)
+                    || subTypeAfterPlus2 == null && subTypeAfterPlus1.equals(subType2);
+                if (!isCompatible && !nullPossible) {
+                    isCompatible = subTypeAfterPlus1.equalsIgnoreCase(subTypeAfterPlus2)
+                        && (subType1.charAt(0) == '*' || subType2.charAt(0) == '*');
+                }
+                
+                if (!isCompatible) {
+                    String subTypeBeforePlus1 = splitMediaSubType(subType1, false);
+                    String subTypeBeforePlus2 = splitMediaSubType(subType2, false);
+                    nullPossible = subTypeBeforePlus1 == null || subTypeBeforePlus2 == null;
+                    isCompatible = subTypeBeforePlus1 == null && subTypeBeforePlus2.equals(subType1)
+                        || subTypeBeforePlus2 == null && subTypeBeforePlus1.equals(subType2);
+                    if (!isCompatible && !nullPossible) {
+                        isCompatible = subTypeBeforePlus1.equalsIgnoreCase(subTypeBeforePlus2)
+                            && (subType1.charAt(subType1.length() - 1) == '*' 
+                                || subType2.charAt(subType2.length() - 1) == '*');
+                    }
+                }
+            }
+        } else {
             if (subTypeAfterPlus1 != null && subTypeAfterPlus2 != null) {
-            
+                
                 isCompatible = subTypeAfterPlus1.equalsIgnoreCase(subTypeAfterPlus2)
                     && (subType1.charAt(0) == '*' || subType2.charAt(0) == '*');
                 

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1468402&r1=1468401&r2=1468402&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Tue Apr 16 13:04:42 2013
@@ -514,6 +514,48 @@ public class JAXRSUtilsTest extends Asse
     }
     
     @Test
+    public void testIntersectMimeTypesCompositeSubtype6() throws Exception {
+        Message m = new MessageImpl();
+        m.put(JAXRSUtils.PARTIAL_HIERARCHICAL_MEDIA_SUBTYPE_CHECK, true);
+        assertTrue(JAXRSUtils.compareCompositeSubtypes("application/bar+xml", "application/xml",
m));  
+    }
+    
+    @Test
+    public void testIntersectMimeTypesCompositeSubtype7() throws Exception {
+        Message m = new MessageImpl();
+        m.put(JAXRSUtils.PARTIAL_HIERARCHICAL_MEDIA_SUBTYPE_CHECK, true);
+        assertTrue(JAXRSUtils.compareCompositeSubtypes("application/xml", "application/bar+xml",
m));
+    }
+    
+    @Test
+    public void testIntersectMimeTypesCompositeSubtype8() throws Exception {
+        Message m = new MessageImpl();
+        m.put(JAXRSUtils.PARTIAL_HIERARCHICAL_MEDIA_SUBTYPE_CHECK, true);
+        assertTrue(JAXRSUtils.compareCompositeSubtypes("application/xml+bar", "application/xml",
m));  
+    }
+    
+    @Test
+    public void testIntersectMimeTypesCompositeSubtype9() throws Exception {
+        Message m = new MessageImpl();
+        m.put(JAXRSUtils.PARTIAL_HIERARCHICAL_MEDIA_SUBTYPE_CHECK, true);
+        assertTrue(JAXRSUtils.compareCompositeSubtypes("application/xml", "application/xml+bar",
m));  
+    }
+    
+    @Test
+    public void testIntersectMimeTypesCompositeSubtype10() throws Exception {
+        Message m = new MessageImpl();
+        m.put(JAXRSUtils.PARTIAL_HIERARCHICAL_MEDIA_SUBTYPE_CHECK, true);
+        assertFalse(JAXRSUtils.compareCompositeSubtypes("application/v1+xml", "application/v2+xml",
m));  
+    }
+
+    @Test
+    public void testIntersectMimeTypesCompositeSubtype11() throws Exception {
+        Message m = new MessageImpl();
+        m.put(JAXRSUtils.PARTIAL_HIERARCHICAL_MEDIA_SUBTYPE_CHECK, true);
+        assertFalse(JAXRSUtils.compareCompositeSubtypes("application/v1+xml", "application/json",
m));  
+    }
+    
+    @Test
     public void testIntersectMimeTypes() throws Exception {
         //test basic
         List<MediaType> methodMimeTypes = new ArrayList<MediaType>(



Mime
View raw message