Reputation: 13
We inherited a web service that was written with Apache CXF. A text field in the response contains characters such as single quotes and "en" dashes (ascii 150). These show up in the response as squares (using SoapUI) or question marks.
The text is coming from an Oracle db which is set to WE8MSWIN1252 charset. I am thinking I need to set the encoding/charset of the web service response to be match (i.e. Windows-1252) but can't find a place to do that.
I could XML-encode the text (e.g. so those dashes show up as –). But if it's possible to use a character set that supports those characters natively that seems preferable, right?
Any idea how I can alter the encoding on the SOAP response?
Upvotes: 0
Views: 4789
Reputation: 848
You can set the encoding in your returned Response:
MyResponse response = new MyResponse();
//.... some code here
return Response.ok(response).encoding("Cp1252").build();
Upvotes: 0
Reputation: 6660
Please try to add the below code to your Apache CXF web service method.
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptorChain;
Message message = PhaseInterceptorChain.getCurrentMessage();
message.put(Message.ENCODING, "Cp1252");
Upvotes: 2