cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r582888 - in /incubator/cxf/branches/2.0.x-fixes: ./ common/common/src/main/java/org/apache/cxf/helpers/ rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/ rt/transports/http/src/main/java/org/apache/cxf/transport/h...
Date Mon, 08 Oct 2007 17:07:45 GMT
Author: dkulp
Date: Mon Oct  8 10:07:44 2007
New Revision: 582888

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

........
  r578270 | dkulp | 2007-09-21 16:48:38 -0400 (Fri, 21 Sep 2007) | 2 lines
  
  Do some checking to make sure the charset encoding we are using is acually supported by
the JVM.
........

Modified:
    incubator/cxf/branches/2.0.x-fixes/   (props changed)
    incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java
    incubator/cxf/branches/2.0.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
    incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
    incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java
    incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java

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

Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java?rev=582888&r1=582887&r2=582888&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java
Mon Oct  8 10:07:44 2007
@@ -19,9 +19,11 @@
 
 package org.apache.cxf.helpers;
 
+import java.nio.charset.Charset;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 public final class HttpHeaderHelper {
     
@@ -37,6 +39,7 @@
 
     
     private static Map<String, String> internalHeaders = new HashMap<String, String>();
+    private static Map<String, String> encodings = new ConcurrentHashMap<String,
String>();
     
     static {
         internalHeaders.put("Content-Type", "content-type");
@@ -61,5 +64,23 @@
         } else {
             return key;
         }
+    }
+    
+    //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) {
+        if (enc == null) {
+            return null;
+        }
+        String newenc = encodings.get(enc);
+        if (newenc == null) {
+            try {
+                newenc = Charset.forName(enc).name();
+            } catch (Exception ex) {
+                //ignore
+            }
+            encodings.put(enc, newenc);
+        }
+        return newenc == null ? enc : newenc;
     }
 }

Modified: incubator/cxf/branches/2.0.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java?rev=582888&r1=582887&r2=582888&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
Mon Oct  8 10:07:44 2007
@@ -33,6 +33,7 @@
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.helpers.HttpHeaderHelper;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
@@ -239,7 +240,7 @@
             inMessage.put(HTTP_RESPONSE, resp);
             inMessage.put(Message.HTTP_REQUEST_METHOD, req.getMethod());
             inMessage.put(Message.PATH_INFO, req.getContextPath() + req.getPathInfo());
-            inMessage.put(Message.ENCODING, req.getCharacterEncoding());
+            inMessage.put(Message.ENCODING, HttpHeaderHelper.mapCharset(req.getCharacterEncoding()));
             inMessage.put(Message.QUERY_STRING, req.getQueryString());
             inMessage.put(Message.CONTENT_TYPE, req.getContentType());
             if (!StringUtils.isEmpty(endpointInfo.getAddress())) {

Modified: incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=582888&r1=582887&r2=582888&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
Mon Oct  8 10:07:44 2007
@@ -1908,10 +1908,21 @@
                 headers.put(HttpHeaderHelper.getHeaderKey(key), 
                         connection.getHeaderFields().get(key));
             }
+            
             inMessage.put(Message.PROTOCOL_HEADERS, headers);
             inMessage.put(Message.RESPONSE_CODE, responseCode);
-            inMessage.put(Message.CONTENT_TYPE, connection.getContentType());
-            inMessage.put(Message.ENCODING, connection.getContentEncoding());
+            String ct = connection.getContentType();
+            inMessage.put(Message.CONTENT_TYPE, ct);
+            String enc = connection.getContentEncoding();
+            if (enc == null 
+                && ct != null 
+                && ct.indexOf("charset") != -1) {
+                enc = ct.substring(ct.indexOf("charset") + 8);
+                if (enc.indexOf(";") != -1) {
+                    enc = enc.substring(0, enc.indexOf(";"));
+                }
+            }
+            inMessage.put(Message.ENCODING, HttpHeaderHelper.mapCharset(enc));
             
             if (maintainSession) {
                 String cookieStr = connection.getHeaderField("Set-Cookie");

Modified: incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java?rev=582888&r1=582887&r2=582888&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
Mon Oct  8 10:07:44 2007
@@ -34,6 +34,7 @@
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.helpers.HttpHeaderHelper;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
@@ -225,7 +226,7 @@
                 enc = enc.substring(0, enc.length() - 1);
             }
             
-            inMessage.put(Message.ENCODING, enc);
+            inMessage.put(Message.ENCODING, HttpHeaderHelper.mapCharset(enc));
             SSLUtils.propogateSecureSession(request, inMessage);
             
             ExchangeImpl exchange = new ExchangeImpl();

Modified: incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java?rev=582888&r1=582887&r2=582888&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java
Mon Oct  8 10:07:44 2007
@@ -68,7 +68,7 @@
         client.setExceptionsThrownOnErrorStatus(false);
 
         assertEquals("text/xml", response.getContentType());
-        assertEquals(encoding, response.getCharacterSet());
+        assertTrue(encoding.equalsIgnoreCase(response.getCharacterSet()));
 
         Document doc = DOMUtils.readXml(response.getInputStream());
         assertNotNull(doc);

Modified: incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java?rev=582888&r1=582887&r2=582888&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java
Mon Oct  8 10:07:44 2007
@@ -61,7 +61,7 @@
         
         WebResponse response = newClient().getResponse(req);
         assertEquals("text/xml", response.getContentType());
-        assertEquals("utf-8", response.getCharacterSet());
+        assertTrue("utf-8".equalsIgnoreCase(response.getCharacterSet()));
 
         Document doc = DOMUtils.readXml(response.getInputStream());
         assertNotNull(doc);



Mime
View raw message