Mule+CXF struggle with quoted encodings

1 Comment

After upgrading Java to version our CXF based webservices running on Mule ESB did not work anymore.

Caused by: "utf-8"
	at com.ctc.wstx.stax.WstxOutputFactory.createSW(
	at com.ctc.wstx.stax.WstxOutputFactory.createXMLStreamWriter(
	at org.apache.cxf.interceptor.StaxOutInterceptor.handleMessage(
	... 25 more
Caused by: "utf-8"
	at sun.nio.cs.StreamEncoder.forOutputStreamWriter(
	at com.ctc.wstx.stax.WstxOutputFactory.createSW(
	... 27 more

That looks strange, because utf-8 should be a supported encoding. But a closer look reveals that the encoding passed contains the quotes. And that does not work. According to the specification quotes are allowed around the charset, but that is not very common.
The quotes were introduced in JAX-WS 2.1.2.

luckily the problem is easy to patch when you know this:

if (encoding != null && encoding.startsWith("\"") && encoding.endsWith("\"")) {
  encoding = encoding.substring(1, encoding.length() - 1);

insert this code at two places:

String encoding = (String)message.get(Message.ENCODING);
return encoding;

The patched class needs to be on the classpath before the original one. When doing so, the webservices worked again. A small unit test verifies this behavior and ensures that after a potential Mule/CXF upgrade the quoted encodings work.



  • John Prystash

    2. March 2012 von John Prystash

    Thanks a lot for this info! This did the trick for me. We were using Mule 2.2.6 which pulls in CXF 2.1.9. I re-built cxf-rt-core from source, updated the version number, and depended on the new version, things work great.


Your email address will not be published.