Linux 中 JbossTextMessage Unicode 转换失败

发布于 2024-09-14 08:47:02 字数 412 浏览 13 评论 0原文

我正在尝试上传 xml (UTF-8) 文件并将其发布到 Jboss MQ 上。从侦听器读取文件时,UTF-8 字符仅在 Linux 上运行的 Jboss (jboss-5.1.0.GA-3) 实例中格式不正确。

例如:BORÅS 在 Linux jboss 实例中转换为 BOR¿S

当我复制并配置相同的 jboss 实例以在 Windows (SP3) 上运行时,它工作得很好。

另外,我还通过在 .bashrc 和 run.sh 文件中包含 JAVA_OPTS=-Dfile.encoding=UTF-8 来更改 Linux 中的默认设置。

侦听器 JbossTextMessage.getText() 内部带有错误指定的字符。

有什么建议或解决方法吗?

I'm trying to upload a xml (UTF-8) file and post it on a Jboss MQ. When reading the file from the listener UTF-8 characters are not correctly formatted ONLY in the Jboss (jboss-5.1.0.GA-3) instance running on Linux.

For an instance: BORÅS is converted to BOR¿S at Linux jboss instance.

When I copy and configure the same jboss instance to run at Windows (SP3) it works perfectly.

Also I have change the default setting in Linux by including JAVA_OPTS=-Dfile.encoding=UTF-8 in .bashrc and run.sh files.

inside the Listener JbossTextMessage.getText() is coming with incorrectly specified character.

Any suggestions or workarounds ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘然心甜 2024-09-21 08:47:02

最后我找到了一个解决方案,但该解决方案仍然是一个黑匣子。如果有人知道为什么失败/成功的答案,请更新线程。

解决方案一览:
1.将文件内容捕获为字节数组,并使用 FileOutputStream 将其写入 jboss tmp 文件夹中的 xml 文件

  1. 当发布到 jboss 消息队列时,我使用显式写入的 xml 文件(第一步),使用 FileInputStream 作为字节数组,将其作为消息正文传递。

代码示例:

View:带有 FormFile

Controller Class 的 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 []
}

Foot 注意: 我认为这与 Linux 有关/Windows 默认文件保存类型。例如:Windows 默认:ANSI。

Finally I was able to find a solution, BUT the solution is still a blackbox. If anyone have the answer to WHY it has failed/successful please update the thread.

Solution at a glance :
1. Captured the file contents as a byte arry and wrote it to a xml file in jboss tmp folder using FileOutputStream

  1. When posting to the jboss Message queue, I used the explicitly wrote xml file (1st step) using a FileInputStream as a byte array and pass it as the Message body.

Code example:

View: JSP page with a FormFile

Controller Class :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 []
}

Foot Note: I think it is something to do with the Linux/Windows default file saving type. eg: Windows default : ANSI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文