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/06/09 21:11:30 UTC
svn commit: r783097 - in /cxf/trunk:
common/common/src/main/java/org/apache/cxf/helpers/
common/common/src/test/java/org/apache/cxf/helpers/
rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/
rt/javascript/src/test/java/org/apache/cxf/j...
Author: dkulp
Date: Tue Jun 9 19:11:25 2009
New Revision: 783097
URL: http://svn.apache.org/viewvc?rev=783097&view=rev
Log:
[CXF-2274] Make sure we default to ISO-8859-1 if charset is not
specified for http
Modified:
cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java
cxf/trunk/common/common/src/test/java/org/apache/cxf/helpers/HttpHeaderHelperTest.java
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java
cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java
cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsXMLHttpRequest.java
cxf/trunk/rt/javascript/src/test/resources/XMLHttpRequestTestBeans.xml
cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XMLHttpRequestTests.js
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.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=783097&r1=783096&r2=783097&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 Tue Jun 9 19:11:25 2009
@@ -39,8 +39,7 @@
public static final String CONNECTION = "Connection";
public static final String CLOSE = "close";
public static final String AUTHORIZATION = "Authorization";
- private static final Charset UTF8 = Charset.forName("utf-8");
-
+ private static final String ISO88591 = Charset.forName("ISO-8859-1").name();
private static Map<String, String> internalHeaders = new HashMap<String, String>();
private static Map<String, String> encodings = new ConcurrentHashMap<String, String>();
@@ -91,12 +90,15 @@
}
return null;
}
+ public static String mapCharset(String enc) {
+ return mapCharset(enc, ISO88591);
+ }
//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) {
+ public static String mapCharset(String enc, String deflt) {
if (enc == null) {
- return UTF8.name();
+ return deflt;
}
//older versions of tomcat don't properly parse ContentType headers with stuff
//after charset="UTF-8"
@@ -109,7 +111,7 @@
enc = enc.replace("\"", "").trim();
enc = enc.replace("'", "");
if ("".equals(enc)) {
- return UTF8.name();
+ return deflt;
}
String newenc = encodings.get(enc);
if (newenc == null) {
Modified: cxf/trunk/common/common/src/test/java/org/apache/cxf/helpers/HttpHeaderHelperTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/test/java/org/apache/cxf/helpers/HttpHeaderHelperTest.java?rev=783097&r1=783096&r2=783097&view=diff
==============================================================================
--- cxf/trunk/common/common/src/test/java/org/apache/cxf/helpers/HttpHeaderHelperTest.java (original)
+++ cxf/trunk/common/common/src/test/java/org/apache/cxf/helpers/HttpHeaderHelperTest.java Tue Jun 9 19:11:25 2009
@@ -33,7 +33,7 @@
String cs = HttpHeaderHelper.mapCharset("utf-8");
assertEquals(Charset.forName("utf-8").name(), cs);
cs = HttpHeaderHelper.mapCharset(null);
- assertEquals("UTF-8", cs);
+ assertEquals("ISO-8859-1", cs);
cs = HttpHeaderHelper.mapCharset("\"utf-8\"");
assertEquals(Charset.forName("utf-8").name(), cs);
cs = HttpHeaderHelper.mapCharset("'utf-8'");
Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java?rev=783097&r1=783096&r2=783097&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java Tue Jun 9 19:11:25 2009
@@ -70,7 +70,7 @@
charset = charset.substring(0, charset.indexOf(";"));
}
}
- String normalizedEncoding = HttpHeaderHelper.mapCharset(charset);
+ String normalizedEncoding = HttpHeaderHelper.mapCharset(charset, "UTF-8");
try {
String stringData = new String(bareBytes, normalizedEncoding);
return new DataHandler(stringData, contentType);
Modified: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java?rev=783097&r1=783096&r2=783097&view=diff
==============================================================================
--- cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java (original)
+++ cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsHttpRequestTest.java Tue Jun 9 19:11:25 2009
@@ -61,7 +61,8 @@
properties.setProperty("staticResourceURL", getStaticResourceURL());
cfg.setProperties(properties);
// now actually do the replacement
- cfg.postProcessBeanFactory(applicationContext.getBeanFactory());
+ cfg.postProcessBeanFactory(applicationContext.getBeanFactory());
+
}
@Override
@@ -88,7 +89,7 @@
testUtilities.rhinoCallInContext("testStateNotificationSync");
Notifier notifier = testUtilities.rhinoCallConvert("testAsyncHttpFetch1", Notifier.class);
testUtilities.rhinoCallInContext("testAsyncHttpFetch2");
- boolean notified = notifier.waitForJavascript(100);
+ boolean notified = notifier.waitForJavascript(10000);
assertTrue(notified);
assertEquals("HEADERS_RECEIVED", Boolean.TRUE,
testUtilities.rhinoEvaluateConvert("asyncGotHeadersReceived", Boolean.class));
@@ -129,7 +130,7 @@
testUtilities.addNamespace("t", "http://apache.org/hello_world_xml_http/wrapped/types");
XPath textPath = XPathAssert.createXPath(testUtilities.getNamespaces());
String nodeText = (String)textPath.evaluate("//t:responseType/text()", doc, XPathConstants.STRING);
- assertEquals(nodeText, "Hello \u05e9\u05dc\u05d5\u05dd");
+ assertEquals("Hello \u05e9\u05dc\u05d5\u05dd", nodeText);
}
public String getStaticResourceURL() throws Exception {
Modified: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsXMLHttpRequest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsXMLHttpRequest.java?rev=783097&r1=783096&r2=783097&view=diff
==============================================================================
--- cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsXMLHttpRequest.java (original)
+++ cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JsXMLHttpRequest.java Tue Jun 9 19:11:25 2009
@@ -60,6 +60,7 @@
import org.xml.sax.SAXException;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.HttpHeaderHelper;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.Function;
@@ -367,19 +368,20 @@
baos.write(buffer, 0, read);
}
is.close();
- // convert bytes to text.
- String contentEncoding = connection.getContentEncoding();
- if (contentEncoding == null || contentEncoding.length() == 0) {
- contentEncoding = "utf-8";
- }
// For a one-way message or whatever, there may not be a content type.
// throw away any encoding modifier.
String contentType = "";
String connectionContentType = connection.getContentType();
+ String contentEncoding = null;
if (connectionContentType != null) {
+ contentEncoding = HttpHeaderHelper
+ .mapCharset(HttpHeaderHelper.findCharset(connectionContentType));
contentType = connectionContentType.split(";")[0];
}
+ if (contentEncoding == null || contentEncoding.length() == 0) {
+ contentEncoding = "iso-8859-1";
+ }
byte[] responseBytes = baos.toByteArray();
Modified: cxf/trunk/rt/javascript/src/test/resources/XMLHttpRequestTestBeans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/resources/XMLHttpRequestTestBeans.xml?rev=783097&r1=783096&r2=783097&view=diff
==============================================================================
--- cxf/trunk/rt/javascript/src/test/resources/XMLHttpRequestTestBeans.xml (original)
+++ cxf/trunk/rt/javascript/src/test/resources/XMLHttpRequestTestBeans.xml Tue Jun 9 19:11:25 2009
@@ -1,29 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
+ <!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to you under the Apache License, Version
+ 2.0 (the "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+ applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ CONDITIONS OF ANY KIND, either express or implied. See the License for
+ the specific language governing permissions and limitations under the
+ License.
+ -->
<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:sec="http://cxf.apache.org/configuration/security"
- xmlns:http="http://cxf.apache.org/transports/http/configuration"
- xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
- xmlns:jaxws="http://cxf.apache.org/jaxws"
- xsi:schemaLocation="
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sec="http://cxf.apache.org/configuration/security"
+ xmlns:http="http://cxf.apache.org/transports/http/configuration"
+ xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
+ xmlns:jaxws="http://cxf.apache.org/jaxws"
+ xsi:schemaLocation="
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/configuration/security
@@ -34,37 +30,46 @@
http://cxf.apache.org/schemas/configuration/http-jetty.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
-
- <import resource="classpath:META-INF/cxf/cxf.xml" />
- <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
- <import resource="classpath:META-INF/cxf/cxf-extension-xml.xml" />
- <import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
- <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
- <import resource="classpath:META-INF/cxf/cxf-extension-local.xml" />
-
- <httpj:engine-factory bus="cxf">
- <httpj:engine port="8808">
- <httpj:handlers>
- <bean class="org.mortbay.jetty.handler.ContextHandler">
- <property name="contextPath" value="/" />
- <property name="handler">
- <bean class="org.mortbay.jetty.handler.ResourceHandler">
- <property name="baseResource">
- <bean class="org.mortbay.resource.FileResource">
- <constructor-arg value="${staticResourceURL}" />
- </bean>
- </property>
- </bean>
- </property>
- </bean>
- <bean class="org.mortbay.jetty.handler.DefaultHandler"/>
- </httpj:handlers>
- </httpj:engine>
- </httpj:engine-factory>
-
- <jaxws:endpoint id="greeter-service-endpoint"
- implementor="org.apache.hello_world_xml_http.wrapped.GreeterImpl"
- address="http://localhost:8808/Greeter" >
- </jaxws:endpoint>
-
- </beans>
\ No newline at end of file
+
+ <import resource="classpath:META-INF/cxf/cxf.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-extension-xml.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-extension-local.xml" />
+
+ <httpj:engine-factory bus="cxf">
+ <httpj:engine port="8808">
+ <httpj:handlers>
+ <bean class="org.mortbay.jetty.handler.ContextHandler">
+ <property name="contextPath" value="/" />
+ <property name="handler">
+ <bean class="org.mortbay.jetty.handler.ResourceHandler">
+ <property name="baseResource">
+ <bean class="org.mortbay.resource.FileResource">
+ <constructor-arg value="${staticResourceURL}" />
+ </bean>
+ </property>
+ <property name="mimeTypes">
+ <bean class="org.mortbay.jetty.MimeTypes">
+ <property name="mimeMap">
+ <map>
+ <entry key="html"><value>text/html; charset="utf-8"</value></entry>
+ </map>
+ </property>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean>
+ <bean class="org.mortbay.jetty.handler.DefaultHandler" />
+ </httpj:handlers>
+ </httpj:engine>
+ </httpj:engine-factory>
+
+ <jaxws:endpoint id="greeter-service-endpoint"
+ implementor="org.apache.hello_world_xml_http.wrapped.GreeterImpl"
+ address="http://localhost:8808/Greeter">
+ </jaxws:endpoint>
+
+</beans>
\ No newline at end of file
Modified: cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XMLHttpRequestTests.js
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XMLHttpRequestTests.js?rev=783097&r1=783096&r2=783097&view=diff
==============================================================================
--- cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XMLHttpRequestTests.js (original)
+++ cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/XMLHttpRequestTests.js Tue Jun 9 19:11:25 2009
@@ -49,6 +49,7 @@
function testSyncHttpFetch() {
var r = new XMLHttpRequest();
+
r.open("GET", "http://localhost:8808/test.html", false);
if (r.readyState != r.OPENED) {
assertionFailed("state not OPENED after OPEN");
@@ -159,6 +160,7 @@
assertionFailed("state not OPENED after OPEN");
}
// just send it as text (or, really, whatever the Java code set up for us).
+ r.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
r.send(request);
if (r.readyState != r.DONE) {
assertionFailed("state not DONE after sync send.")
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=783097&r1=783096&r2=783097&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 Tue Jun 9 19:11:25 2009
@@ -293,16 +293,18 @@
if (enc != null && enc.endsWith("\"")) {
enc = enc.substring(0, enc.length() - 1);
}
- String normalizedEncoding = HttpHeaderHelper.mapCharset(enc);
- if (normalizedEncoding == null) {
- String m = new org.apache.cxf.common.i18n.Message("INVALID_ENCODING_MSG",
- LOG, enc).toString();
- LOG.log(Level.WARNING, m);
- throw new IOException(m);
+ if (enc != null || "POST".equals(req.getMethod()) || "PUT".equals(req.getMethod())) {
+ //allow gets/deletes/options to not specify an encoding
+ String normalizedEncoding = HttpHeaderHelper.mapCharset(enc);
+ if (normalizedEncoding == null) {
+ String m = new org.apache.cxf.common.i18n.Message("INVALID_ENCODING_MSG",
+ LOG, enc).toString();
+ LOG.log(Level.WARNING, m);
+ throw new IOException(m);
+ }
+ inMessage.put(Message.ENCODING, normalizedEncoding);
}
- inMessage.put(Message.ENCODING, normalizedEncoding);
-
inMessage.put(Message.QUERY_STRING, req.getQueryString());
inMessage.put(Message.CONTENT_TYPE, contentType);
inMessage.put(Message.ACCEPT_CONTENT_TYPE, req.getHeader("Accept"));
Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java?rev=783097&r1=783096&r2=783097&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java (original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java Tue Jun 9 19:11:25 2009
@@ -227,7 +227,7 @@
}
}
- String normalizedEncoding = HttpHeaderHelper.mapCharset(enc);
+ String normalizedEncoding = HttpHeaderHelper.mapCharset(enc, "UTF-8");
if (normalizedEncoding == null) {
String m = new org.apache.cxf.common.i18n.Message("INVALID_ENCODING_MSG", LOG, new Object[] {
enc