Archer
Archer

Reputation: 5147

Camel: how to predict HTTP charchester encoding when doing conversion

Doing this way:

from("direct:foo").
to("http://foo.com/bar.html").
convertBodyTo(String.class, "cp1251").
to("file:///tmp/bar.html")

However some pages I crawl could have encoding different from cp1251. How to determine encoding (either using Content-Type HTTP header or meta/@http-equiv' charset) and call convertBodyTo() using appropriate charset? May be Camel HTTP component could do that? What's Exchange.HTTP_CHARACTER_ENCODING?

Upvotes: 2

Views: 2293

Answers (1)

Willem Jiang
Willem Jiang

Reputation: 3291

You can add processor to set the exchange property with the header Exchange.CHARSET_NAME, the value could be information you get from the Http header content-type. At this point, camel can know the encoding it can use.

Upvotes: 1

Related Questions