JbossTextMessage Unicode转换在Linux中失败

JbossTextMessage Unicode转换在Linux中失败,unicode,jboss,jms,message-driven-bean,mq,Unicode,Jboss,Jms,Message Driven Bean,Mq,我正试图上传一个xml(UTF-8)文件并将其发布到JBossMQ上。从侦听器读取文件时,UTF-8字符的格式不正确,仅在Linux上运行的Jboss(Jboss-5.1.0.GA-3)实例中 例如,在Linux jboss实例中,BORÅS被转换为BORãS 当我复制并配置同一个jboss实例在Windows(SP3)上运行时,它工作得非常好 此外,我还通过在.bashrc和run.sh文件中包含JAVA_OPTS=-Dfile.encoding=UTF-8来更改Linux中的默认设置 侦听器

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

例如,在Linux jboss实例中,BORÅS被转换为BORãS

当我复制并配置同一个jboss实例在Windows(SP3)上运行时,它工作得非常好

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

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


有什么建议或解决办法吗

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

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

  • 在发布到jboss消息队列时,我使用了显式编写的xml文件(第一步),使用FileInputStream作为字节数组,并将其作为消息体传递
  • 代码示例:

    查看:带有表单文件的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。

    请提供有关如何上载文件的确切信息。我已经公开了一个jsp,使用post方法上载xml文件。我将使用Action类中的struts以FormFile的形式获取该文件,如下所示:FormFile file=theForm.getFile();其次,我以字节数组byte[]buf=file.getFileData()的形式检索文件数据;最后,我在Jboss(Jboss-5.1.0.GA-3)中的一个队列中发布了这篇文章。过程如下:(1)上传XML-->(2)从文件--->(3)获取字节[](3)将其放在MDB挑选的JMS队列--->(4)中进行处理。当从侦听器接收到发布的消息时,我尝试按如下方式强制转换它,但没有成功:((TextMessage)Message.getText().getBytes(“UTF-8”)