camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: UTF-8 and Files Created by Camel
Date Wed, 07 Dec 2011 07:01:15 GMT
Hi

In Java code you must use the \u1234 notation to enter uni code
values, to enter the special symbols.

private String testString = "€ euro symbol, ® registered trade mark symbol";

Should be something alike

private String testString = "\u1234 euro symbol, \u1234 registered
trade mark symbol";
Where 1234 is the uni code number for the symbol.


On Tue, Dec 6, 2011 at 11:14 PM, Phil Public <public_phil@me.com> wrote:
> Hello,
>
>  I'm having difficulty creating files using Camel 2.8.0 that use the Euro
> character '€' and the registered trademark character '®'.  I've tried to set
> the encoding on the file URI to UTF-8, as well as on the Exchange via the
> property Exchange.CHARSET_NAME and each time the output data file is
> incorrect.
>
>  I've included a Camel test case below that demonstrates the issue.  When
> printing the string via Java, everything works properly.  When writing to
> the file, the content does not match the input string.
>
>  Could someone advise me as the best way to properly output the UTF-8
> character set via Camel?  Thanks!
>
> Phil
>
> ====
>
> /**
>  *
>  */
> package com.bglobal.etf.dixie.camel;
>
> import org.apache.camel.Exchange;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.test.junit4.CamelTestSupport;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.junit.Assert;
> import org.junit.Test;
>
> /**
>  * Apache Camel test case for UTF-8 characters
>  * A test file will be written to file:://c/tmp after this runs
>  * I'm expecting the text in the file to match that of the testString
>  * @author Philip Glebow
>  *
>  */
> public class CamelEncodingTest extends CamelTestSupport {
>
>        private Log log = LogFactory.getLog(CamelEncodingTest.class);
>
>        private String testString = "€ euro symbol, ® registered trade mark
> symbol";
>
>        private String fromURI = "direct:in";
>
>        private String toURI = "file://c:/tmp?charset=utf-8";
>
>        @Test
>        public void test() {
>                try {
>                        log.info(testString);
>                        template.sendBodyAndProperty(fromURI, testString,
Exchange.CHARSET_NAME,
> "utf-8");
>                } catch (Exception e) {
>                        log.error(e.getMessage(), e);
>                        Assert.fail(e.getMessage());
>                }
>        }
>
>        @Override
>        protected RouteBuilder createRouteBuilder() throws Exception {
>                return new RouteBuilder() {
>
>                        @Override
>                        public void configure() throws Exception {
>                                from(fromURI).to(toURI);
>                        }
>                };
>        }
>
> }
> =====
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/UTF-8-and-Files-Created-by-Camel-tp5053652p5053652.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Mime
View raw message