You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/05/15 03:15:30 UTC

svn commit: r774979 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/helpers/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/

Author: dkulp
Date: Fri May 15 01:15:30 2009
New Revision: 774979

URL: http://svn.apache.org/viewvc?rev=774979&view=rev
Log:
[CXF-2215] Don't rely on getCharacterEncoding, parse from Content-Type.  May fix CXF-2215

Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java?rev=774979&r1=774978&r2=774979&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java Fri May 15 01:15:30 2009
@@ -74,6 +74,24 @@
         }
     }
     
+    public static String findCharset(String contentType) {
+        if (contentType == null) {
+            return null;
+        }
+        int idx = contentType.indexOf("charset=");
+        if (idx != -1) {
+            String charset = contentType.substring(idx + 8);
+            if (charset.indexOf(";") != -1) {
+                charset = charset.substring(0, charset.indexOf(";")).trim();
+            }
+            if (charset.charAt(0) == '\"') {
+                charset = charset.substring(1, charset.length() - 1);
+            }
+            return charset;
+        }
+        return null;
+    }
+    
     //helper to map the charsets that various things send in the http Content-Type header 
     //into something that is actually supported by Java and the Stax parsers and such.
     public static String mapCharset(String enc) {

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=774979&r1=774978&r2=774979&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java Fri May 15 01:15:30 2009
@@ -283,9 +283,13 @@
         }
         inMessage.put(Message.PATH_INFO, contextPath + req.getPathInfo());
         
+        String contentType = req.getContentType();
+        String enc = HttpHeaderHelper.findCharset(contentType);
+        if (enc == null) {
+            enc = req.getCharacterEncoding();
+        }
         // work around a bug with Jetty which results in the character
         // encoding not being trimmed correctly.
-        String enc = req.getCharacterEncoding();
         if (enc != null && enc.endsWith("\"")) {
             enc = enc.substring(0, enc.length() - 1);
         }
@@ -300,7 +304,7 @@
         inMessage.put(Message.ENCODING, normalizedEncoding);
         
         inMessage.put(Message.QUERY_STRING, req.getQueryString());
-        inMessage.put(Message.CONTENT_TYPE, req.getContentType());
+        inMessage.put(Message.CONTENT_TYPE, contentType);
         inMessage.put(Message.ACCEPT_CONTENT_TYPE, req.getHeader("Accept"));
         String basePath = getBasePath(contextPath);
         if (!StringUtils.isEmpty(basePath)) {

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=774979&r1=774978&r2=774979&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Fri May 15 01:15:30 2009
@@ -2097,14 +2097,7 @@
             inMessage.put(Message.RESPONSE_CODE, responseCode);
             String ct = connection.getContentType();
             inMessage.put(Message.CONTENT_TYPE, ct);
-            String charset = null;
-            if (ct != null 
-                && ct.indexOf("charset") != -1) {
-                charset = ct.substring(ct.indexOf("charset") + 8);
-                if (charset.indexOf(";") != -1) {
-                    charset = charset.substring(0, charset.indexOf(";"));
-                }
-            }
+            String charset = HttpHeaderHelper.findCharset(ct);
             String normalizedEncoding = HttpHeaderHelper.mapCharset(charset);
             if (normalizedEncoding == null) {
                 String m = new org.apache.cxf.common.i18n.Message("INVALID_ENCODING_MSG",