问题描述
我们继承了使用Apache CXF编写的Web服务。响应中的文本字段包含单引号和 en破折号(ASCII 150)之类的字符。这些在响应中显示为正方形(使用SoapUI)或问号。
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.
文本来自设置为WE8MSWIN1252字符集的Oracle数据库。我想我需要将网络服务响应的编码/字符集设置为匹配(例如Windows-1252),但是找不到合适的位置。
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.
我可以对文本进行XML编码(例如,这些破折号显示为–)。但是,如果有可能使用一种字符集来支持这些字符的话,那似乎是更好的选择,对吧?
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?
有人知道如何更改SOAP响应的编码吗?
Any idea how I can alter the encoding on the SOAP response?
推荐答案
请尝试将以下代码添加到Apache CXF Web服务方法中。
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");
这篇关于更改CXF Web服务上的响应字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!