Change the response character set on CXF web service

一个人想着一个人 提交于 2019-12-13 06:13:29

问题


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?


回答1:


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"); 



回答2:


You can set the encoding in your returned Response:

MyResponse response = new MyResponse();
//.... some code here
return Response.ok(response).encoding("Cp1252").build();


来源:https://stackoverflow.com/questions/15528709/change-the-response-character-set-on-cxf-web-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!