Beliebte Suchanfragen

Cloud Native



Agile Methoden



Mule+CXF struggle with quoted encodings

25.11.2009 | 1 minutes of reading time

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

1Caused by: "utf-8"
2    at com.ctc.wstx.stax.WstxOutputFactory.createSW(
3    at com.ctc.wstx.stax.WstxOutputFactory.createXMLStreamWriter(
4    at org.apache.cxf.interceptor.StaxOutInterceptor.handleMessage(
5    ... 25 more
6Caused by: "utf-8"
7    at sun.nio.cs.StreamEncoder.forOutputStreamWriter(
8    at<init>(
9    at com.ctc.wstx.stax.WstxOutputFactory.createSW(
10    ... 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:

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

insert this code at two places:

3String encoding = (String)message.get(Message.ENCODING);
8return 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.


share post




More articles in this subject area

Discover exciting further topics and let the codecentric world inspire you.


Gemeinsam bessere Projekte umsetzen.

Wir helfen deinem Unternehmen.

Du stehst vor einer großen IT-Herausforderung? Wir sorgen für eine maßgeschneiderte Unterstützung. Informiere dich jetzt.

Hilf uns, noch besser zu werden.

Wir sind immer auf der Suche nach neuen Talenten. Auch für dich ist die passende Stelle dabei.