2010-08-13 51 views
0

我試圖上傳一個xml(UTF-8)文件並將其發佈到Jboss MQ上。從偵聽器讀取文件時UTF-8字符在Linux上運行的Jboss(jboss-5.1.0.GA-3)實例中的格式不正確。JbossTextMessage在Linux中的Unicode轉換失敗

對於實例:BORAS在Linux的JBoss的實例被轉換爲BOR¿S

當我複製並配置相同的jboss實例以在Windows(SP3)上運行時,它完美地工作。

另外,我通過在.bashrc和run.sh文件中包含JAVA_OPTS = -Dfile.encoding = UTF-8來更改Linux中的默認設置。

裏面的監聽器JbossTextMessage.getText()與未正確指定的字符。

任何建議或解決方法?

+0

請提供有關如何上傳文件的確切信息。 – sorin 2010-08-13 11:11:44

+0

我已經公開了使用post方法上傳xml文件的jsp。我將使用Action類中的struts作爲FormFile獲取文件,如下所示: FormFile file = theForm.getFile();其次,我檢索文件數據作爲字節數組 byte [] buf = file.getFileData(); 最後,我把它放在Jboss隊列中(jboss-5.1.0.GA-3)。 – isurux 2010-08-13 12:15:56

+0

處理過程如下: (1)上傳XML --->(2)從文件中獲取byte [] --->(3)將它放在JMS隊列中--->(4) MDB進行處理。 當收到來自監聽器的發佈消息時,我嘗試按如下方式進行投射,但沒有發揮作用: ((TextMessage)message).getText()。getBytes(「UTF-8」) – isurux 2010-08-13 12:18:07

回答

0

最後我能找到解決方案,但解決方案仍然是一個黑匣子。如果任何人有答案,爲什麼它已失敗/成功,請更新線程。

解一覽: 1.捕捉該文件的內容作爲字節ARRY並將其寫於使用FileOutputStream中

在JBoss的TMP文件夾中的XML文件
  • 當張貼到jboss消息隊列,我使用明確寫入的xml文件(第1步),使用FileInputStream作爲字節數組並將其作爲消息正文傳遞。
  • 代碼示例:

    查看: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 [] 
    } 
    

    腳註:用FormFile

    控制器類 JSP頁面我認爲這是與Linux/Windows默認文件保存類型有關。例如:Windows默認:ANSI。