You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Andreas Asmuss <an...@gmail.com> on 2010/07/07 10:23:17 UTC

Encoding acting odd.

Hi,

I want to operate in charset iso-8859-1 in my route because of some special
characters. Therefore I do <convertBodyTo type="String"
charset="iso-8859-1"> at the start of my routes. I also do
exchange.setProperty(Exchange.CHARSET_NAME, "iso-8859-1");

As long as JAXB is not involved this works fine. I can do
xslt-transformations etc. and the special characters are preserved. However
if I unmarshal/marshal with JAXB I get the error:
"Caused by: java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8
sequence."

Shouldn't JAXB expect encoding iso-8859-1 when I set
"exchange.setProperty(Exchange.CHARSET_NAME, "iso-8859-1");"?

If I make sure that the file coming in is encoded in UTF-8 I don't get this
error + the characters are preserved, eventhough I still do the
convertBodyTo and the CHARSET_NAME to iso-8859-1.

What could be wrong?
-- 
View this message in context: http://camel.465427.n5.nabble.com/Encoding-acting-odd-tp1037744p1037744.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Encoding acting odd.

Posted by Andreas Asmuss <an...@gmail.com>.
I'm using 2.3.

I thought setting CHARSET_NAME would instruct JAXB to use the encoding set
there?

"In Camel 1.6.1 and newer you can set the encoding option to use when
marshalling. Its the Marshaller.JAXB_ENCODING encoding property on the JAXB
Marshaller.
You can setup which encoding to use when you declare the JAXB data format.
You can also provide the encoding in the Exchange property
Exchange.CHARSET_NAME. This property will overrule the encoding set on the
JAXB data format."
http://camel.apache.org/jaxb.html

The phrasing is a bit weird in that paragraph so maybe I'm misunderstanding
it.
-- 
View this message in context: http://camel.465427.n5.nabble.com/Encoding-acting-odd-tp1037744p1041571.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Encoding acting odd.

Posted by Willem Jiang <wi...@gmail.com>.
Which version of Camel are you using?
xslt-transformation will use "UTF-8" the by default, and you can change 
it by setting the system property for it, but it relates to the Camel 
version that you are using.

Willem
----------------------------------
Apache Camel, Apache CXF committer
Open SOA http://www.fusesource.com
Blog http://willemjiang.blogspot.com
Tiwtter http://twitter.com/willemjiang

Andreas Asmuss wrote:
> Hi,
> 
> I want to operate in charset iso-8859-1 in my route because of some special
> characters. Therefore I do <convertBodyTo type="String"
> charset="iso-8859-1"> at the start of my routes. I also do
> exchange.setProperty(Exchange.CHARSET_NAME, "iso-8859-1");
> 
> As long as JAXB is not involved this works fine. I can do
> xslt-transformations etc. and the special characters are preserved. However
> if I unmarshal/marshal with JAXB I get the error:
> "Caused by: java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8
> sequence."
> 
> Shouldn't JAXB expect encoding iso-8859-1 when I set
> "exchange.setProperty(Exchange.CHARSET_NAME, "iso-8859-1");"?
> 
> If I make sure that the file coming in is encoded in UTF-8 I don't get this
> error + the characters are preserved, eventhough I still do the
> convertBodyTo and the CHARSET_NAME to iso-8859-1.
> 
> What could be wrong?


Re: Encoding acting odd.

Posted by Andreas Asmuss <an...@gmail.com>.
No matter what I do the marshaller complains about:
java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence.

I set these values:
System.setProperty("org.apache.camel.default.charset", "iso-8859-1");

exchange.setProperty(Exchange.CHARSET_NAME, "iso-8859-1");

<jaxb id="jaxbIntermediateIn" contextPath="jaxbmodel"
	prettyPrint="false" ignoreJAXBElement="true" encoding="iso-8859-1" />

And the marshaller still wants UTF-8?

Right now I have this working:

<route>
<from uri="file:data/in" />
<convertBodyTo type="String" charset="UTF-8" />
<unmarshal ref="jaxbIntermediateIn" />
<marshal ref="jaxbIntermediateOut" />
<convertBodyTo type="String" charset="iso-8859-1" />
<to uri="file:data/out" />
</route>

But that's not a very nice a solution.
-- 
View this message in context: http://camel.465427.n5.nabble.com/Encoding-acting-odd-tp1037744p1044712.html
Sent from the Camel - Users mailing list archive at Nabble.com.