jbosstextmessage unicode转换在linux中失败
-
28-09-2019 - |
题
我正在尝试上传XML(UTF-8)文件,然后将其发布在JBOSS MQ上。从Linux上运行的JBOSS(JBOSS-5.1.0.GA-3)实例中,从侦听器UTF-8字符中读取文件时。
对于一个实例: borås 被转换为 鲍 在Linux JBOSS实例上。
当我复制并配置相同的JBOSS实例以在Windows(SP3)运行时,它可以很好地工作。
另外,我还通过包括java_opts = -dfile.encoding = utf-8在.bashrc和run.sh文件中更改Linux中的默认设置。
在侦听器中,JBoSstextMessage.getText()带有错误指定的字符。
有什么建议或解决方法吗?
解决方案
最后,我能够找到解决方案,但该解决方案仍然是黑框。如果有人可以解决为什么失败/成功的答案,请更新线程。
一眼解决方案:1。使用FileOutputStream将文件内容捕获为字节Arry,并将其写入JBOSS TMP文件夹中的XML文件
- 发布到JBOSS消息队列时,我使用FileInputStream作为字节数组使用了明确编写的XML文件(第一步),并将其作为消息正文传递。
代码示例:
看法: :带有formfile的JSP页面
控制器类 :uploadaction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
...........
writeInitFile(theForm.getFile().getFileData()); // Obtain the uploaded file
Message msg = messageHelper.createMessage( readInitFile() ); // messageHelper is a customized factory method to create Message objects. Passing the newly
wrote file's byte array.
messageHelper.sendMsg(msg); // posting in the queue
...........
}
private void writeInitFile(byte[] fileData) throws Exception{
File someFile = new File("/jboss-5.1.0.GA-3/test/server/default/tmp/UploadTmp.xml"); // Write the uploaded file into a temporary file in jboss/tmp folder
FileOutputStream fos = new FileOutputStream(someFile);
fos.write( fileData );
fos.flush();
fos.close();
}
private byte[] readInitFile() throws Exception{
StringBuilder buyteArray=new StringBuilder();
File someFile = new File("/jboss-5.1.0.GA-3/test/server/default/tmp/UploadTmp.xml"); // Read the Newly created file in jboss/tmp folder
FileInputStream fstream = new FileInputStream(someFile);
int ch;
while( (ch = fstream.read()) != -1){
buyteArray.append((char)ch);
}
fstream.close();
return buyteArray.toString().getBytes(); // return the byte []
}
脚注: 我认为这与Linux/Windows默认文件保存类型有关。例如:Windows默认值:ANSI。
不隶属于 StackOverflow