cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1365557 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
Date Wed, 25 Jul 2012 12:34:17 GMT
Author: sergeyb
Date: Wed Jul 25 12:34:17 2012
New Revision: 1365557

URL: http://svn.apache.org/viewvc?rev=1365557&view=rev
Log:
Merged revisions 1365551 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes

................
  r1365551 | sergeyb | 2012-07-25 13:25:07 +0100 (Wed, 25 Jul 2012) | 16 lines
  
  Merged revisions 1365540 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
  
  ................
    r1365540 | sergeyb | 2012-07-25 12:51:27 +0100 (Wed, 25 Jul 2012) | 9 lines
    
    Merged revisions 1365536 via svnmerge from 
    https://svn.apache.org/repos/asf/cxf/trunk
    
    ........
      r1365536 | sergeyb | 2012-07-25 12:47:51 +0100 (Wed, 25 Jul 2012) | 1 line
      
      [CXF-4443] Relaxing the control of malformed media types
    ........
  ................
................

Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Wed Jul 25 12:34:17 2012
@@ -0,0 +1,3 @@
+/cxf/branches/2.5.x-fixes:1365551
+/cxf/branches/2.6.x-fixes:1365540
+/cxf/trunk:1365536

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

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java?rev=1365557&r1=1365556&r2=1365557&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
Wed Jul 25 12:34:17 2012
@@ -24,14 +24,22 @@ import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.StringTokenizer;
+import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
 
-public class MediaTypeHeaderProvider implements HeaderDelegate<MediaType> {
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
+import org.apache.cxf.phase.PhaseInterceptorChain;
 
+public class MediaTypeHeaderProvider implements HeaderDelegate<MediaType> {
+    private static final Logger LOG = LogUtils.getL7dLogger(MediaTypeHeaderProvider.class);
+    private static final String STRICT_MEDIA_TYPE_CHECK = 
+        "org.apache.cxf.jaxrs.mediaTypeCheck.strict";
     private static final Pattern COMPLEX_PARAMETERS = 
         Pattern.compile("(([\\w-]+=\"[^\"]*\")|([\\w-]+=[\\w-/]+))");
     
@@ -43,14 +51,7 @@ public class MediaTypeHeaderProvider imp
         
         int i = mType.indexOf('/');
         if (i == -1) {
-            mType = mType.trim();
-            if (mType.startsWith(MediaType.MEDIA_TYPE_WILDCARD)) {
-                char next = mType.length() == 1 ? ' ' : mType.charAt(1);
-                if (next == ' ' || next == ';') {
-                    return new MediaType("*", "*");
-                }
-            }
-            throw new IllegalArgumentException("Media type separator is missing");
+            return handleMediaTypeWithoutSubtype(mType.trim());
         }
         
         int paramsStart = mType.indexOf(';', i + 1);
@@ -109,5 +110,28 @@ public class MediaTypeHeaderProvider imp
         return sb.toString();
     }
 
-    
+    private MediaType handleMediaTypeWithoutSubtype(String mType) {
+        if (mType.startsWith(MediaType.MEDIA_TYPE_WILDCARD)) {
+            char next = mType.length() == 1 ? ' ' : mType.charAt(1);
+            if (next == ' ' || next == ';') {
+                return MediaType.WILDCARD_TYPE;
+            }
+        }
+        Message message = PhaseInterceptorChain.getCurrentMessage();
+        if (message != null 
+            && !MessageUtils.isTrue(message.getContextualProperty(STRICT_MEDIA_TYPE_CHECK)))
{
+            MediaType mt = null;
+            if (mType.equals(MediaType.TEXT_PLAIN_TYPE.getType())) {
+                mt = MediaType.TEXT_PLAIN_TYPE;
+            } else if (mType.equals(MediaType.APPLICATION_XML_TYPE.getSubtype())) {
+                mt = MediaType.APPLICATION_XML_TYPE;
+            } else {
+                mt = MediaType.WILDCARD_TYPE;
+            }
+            LOG.fine("Converting a malformed media type '" + mType + "' to '" + mt.toString()
+ "'");
+            return mt;
+        } else {
+            throw new IllegalArgumentException("Media type separator is missing");
+        }
+    }
 }



Mime
View raw message