Here I am calling a REST webservice using CamelCxf rsClient. The webservice returns a JSON response with encoding : ISO-8859-1. And CamelCxf is trying to read it in that encoding which is changing the French characters in json string.
I wanted to change the charset encoding to UTF-8 to read both English and French characters.
I have tried to read the cxfrs client response as
<convertBodyTo type="String"/>
Which changed the French character è to é
I have also tried to convert the response into byte[] and then created a UTF-8 string from the byte[]
<convertBodyTo type="byte[]"/>
and in the processor
byte[] body =(byte[]) exchange.getIn().getBody();
String convertedString = new String(body, "utf8");
This attempt also failed to read french characters properly.
Response headers from external webservice
Content-Type: application/json
Encoding: ISO-8859-1
How do we make camel Cxf rsClient to ignore the encoding coming with json response and change to
Content-Type: application/json;charset=UTF-8
Encoding: UTF-8
Can we use an interceptor to do so?
Update :
Tried
<convertBodyTo type="java.lang.String" charset=UTF-8"/>
It works in local windows server but NOT in remote redhat Linux servers.
You can instruct Camel to use a particular charset encoding when performing an HTTP request over CXF by setting the
Content-Type
exchange property to the desired value as below (given that upstream service would support content negotiation properly and provide the desired encoding:For sure, you need to find a proper way of injecting this harder into your route given you haven't described how it is all plugged together. This may resolve your issue if requested resource is sent properly encoded.
Alternative solution
This translation goes against what you described in your main topic. Having the è characters translate to é means that the input was encoded initially in
UTF-8
then it has been evaluated as being encoded inISO-8859-1
standard.As you haven't described how your route declaration, here down a generic solution where you can declare a
bean
/processor
translating your incomingMessage
body from latin1 to UTF-8 encoded strings:Additional notes
First you may need to check the default charset (aka encoding scheme) used in your application as its behavior varies between environments. You can inspect the default
Charset
used across CamelExchange
s by inspecting the below expression value: