0

xml(UTF-8)ファイルをアップロードしてJbossMQに投稿しようとしています。リスナーからファイルを読み取る場合、UTF-8文字は、Linuxで実行されているJboss(jboss-5.1.0.GA-3)インスタンスでのみ正しくフォーマットされません。

たとえば、BORÅSはLinuxjbossインスタンスBOR¿Sに変換されます。

同じjbossインスタンスをコピーしてWindows(SP3)で実行するように設定すると、完全に機能します。

また、.bashrcファイルとrun.shファイルにJAVA_OPTS = -Dfile.encoding = UTF-8を含めることで、Linuxのデフォルト設定を変更しました。

リスナー内のJbossTextMessage.getText()には、誤って指定された文字が含まれています。

提案や回避策はありますか?

4

1 に答える 1

0

最終的に私は解決策を見つけることができましたが、解決策はまだブラックボックスです。失敗/成功した理由に対する答えが誰かにある場合は、スレッドを更新してください。

解決策の概要:1。ファイルの内容をバイトアリーとしてキャプチャし、FileOutputStreamを使用してjbosstmpフォルダー内のxmlファイルに書き込みました。

  1. 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。

于 2010-08-13T14:35:48.203 に答える