近期碰到一个编码的问题,发现整个平台都是用的GB2312,因此导致webservice调用时有些字不能正常接受。
反编译中间件的源码如下:
public static final String node2String(Node node, booleanisPreserveSpace)
{if (node == null)return null;if (node.getNodeType() == 9) {
node=((Document)node).getDocumentElement();
}
OutputFormat format= newOutputFormat(node.getOwnerDocument());
String strEncoding= System.getProperty("xml.encoding");if (strEncoding != null) format.setEncoding(strEncoding); else{
format.setEncoding("GB2312");
}
format.setIndenting(false);
format.setPreserveSpace(isPreserveSpace);
StringWriter stringOut= newStringWriter();
XMLSerializer serial= newXMLSerializer(stringOut, format);try{
serial.asDOMSerializer();
serial.serialize((Element)node);
}catch(IOException ex) {throw newEOSFailure(ex);
}returnstringOut.toString();
}
由以上代码得知,如果属性xml.encoding为空,则平台编码默认为GB2312,所以得想办法设置该属性:
1、tomcat配置
编辑startTomcat.cmd,找到如下配置:
set JAVA_OPTS=-Xms128m -Xmx512m -DEOSCipherProvider=SunJCE
加上xml.ecoding的配置
set JAVA_OPTS=-Xms128m -Xmx512m -DEOSCipherProvider=SunJCE-Dxml.encoding=GBK
2、websphere6的配置,需要在websphere的管理控制台中配置
1)、选择安装了EOS应用的服务器
2)、选择进程定义
3)、选择JAVA虚拟机
4)、选择JAVA虚拟机的定制属性
5)、查看EOS的JVM环境变量配置
在这里添加一个xml.encoding=GBK的属性