IBM Worklight - Error charset/encoding in data response from webservice

China☆狼群 提交于 2019-12-12 00:28:08

问题


I use IBM worklight to develop a hybrid app. In the local development environment everything is OK.

I have an issue when I deploy to an external server (with oracle database). My app calls a webservice via an adapter, but the data in the response has an encoding problem: unicode characters do not display correctly. I changed the charset (in the adapter invoke function) to ISO-8859-1, and then unicode characters display correctly.

function invokeWebService(body, headers, soapAction) {
var input = {
    method : 'post',
    returnedContentType : 'xml',
    path : '/transaction/services/TransactionService.TransactionServiceHttpSoap11Endpoint/',
    body: {
        content : body.toString(),
        contentType : 'text/xml; charset=ISO-8859-1'
    }
};

//Adding custom HTTP headers if they were provided as parameter to the procedure call
//Always add header for SOAP action 
headers = headers || {};
if (soapAction != 'null')
    headers.SOAPAction = soapAction;
input['headers'] = headers;

return WL.Server.invokeHttp(input);
}

However the problem then happens again when I want to insert data to database (oracle with default charset UTF-8). The data has been inserted with error charset (because ISO-8859-1).

How can I get data response correct charset with UTF-8 without having to change the encoding from the webservice?

Or get data with ISO-8859-1 charset and insert data to database with UTF-8?


回答1:


@Idan Adar It's a solution for system use Liberty but I use tomcat. I have found solution for it. Just change Tomcat's default charset:

set "JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF8"

Change Tomcat's Charset.defaultCharset in windows




回答2:


This may be due to the encoding of what Andrew mentioned, but because you say this is working in the development server but failing in the remote server, you may want to attempt the following.

If the remote server is WebSphere Liberty, locate the jvm.options file and add the following:

-Dfile.encoding=UTF-8
-Duser.language=en
-Duser.country=US

If the remote server WebSphere ND, there is an Admin panel where you can set the encoding at. Consult with the WebShere documentation: http://www-01.ibm.com/support/knowledgecenter/SSEQTJ_8.5.5/com.ibm.websphere.nd.doc/ae/xrun_jvm.html

Of course, also revert any changes you did previously...



来源:https://stackoverflow.com/questions/32497199/ibm-worklight-error-charset-encoding-in-data-response-from-webservice

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