views:

10

answers:

1

Hello,

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 ?

A: 

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.

isurux