-
1. Re: Unicode convert problem with Jboss in Linux
jfclere Aug 12, 2010 5:24 AM (in response to isurux)Where does the problem happend?
When serving files (add an example)?
When in a servlet/application/database?
-
2. Re: Unicode convert problem with Jboss in Linux
isurux Aug 12, 2010 6:08 AM (in response to jfclere)Hello Clere,
Thank you for the prompt reply.I have exposed a jsp to upload a xml file using the post method. I will be obtaining the file as a FormFile using struts in the Action class as follwos:FormFile file = theForm.getFile();Secondly, I retrieve the file data as byte arraybyte[] buf = file.getFileData();
When I view the result of above buf variable at runtime or if I write it to a file using FileOutputStream it is clear that the unicode has been converted to a non recognized character. -
3. Re: Unicode convert problem with Jboss in Linux
jfclere Aug 13, 2010 2:13 AM (in response to isurux)JAVA_OPTS=-Dfile.encoding=UTF-8
Is probably the way to go. But you should try to check the encoding in windows.
public class Test { public static void main(String[] args) { System.out.println(sun.io.Converters.getDefaultEncodingName()); System.out.println(System.getProperty("file.encoding")); } }
Check the output in windows and in Linux. Recheck with -Dfile.encoding=windows_value on Linux.
-
4. Re: Unicode convert problem with Jboss in Linux
isurux Aug 13, 2010 4:57 AM (in response to jfclere)Hello Clere,
I have tired out that by passing the '-Dfile.encoding=UTF-8' to the run.sh file and check the
file.encoding
at runtime but same result.Now I have identified the problem is at the server side and not in the view.
I tried to save the byte array obtain from the File into an xml file in jboss tmp folder and it contains the correct Unicode.
In my scenario the uploaded file is straight away sent to a message queue to be processed by an MDB. So the flow is as follow:
Upload the XML ----> Obtain the byte[] from the file ---> put it on a JMS queue ---> picked by a MDB to process
When the posted Message is cast to a TextMessage and process, the Unicode is been incorrectly converted.
Is there is any specific configuration I have to do in the JMS queue in order to convert it to the correct Unicode?
-
5. Re: Unicode convert problem with Jboss in Linux
isurux Aug 13, 2010 10:42 AM (in response to isurux)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. Till it is solved I will let the thread open.
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 FileOutputStream2. 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 FormFileController Class :UploadAction.javapublic ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){...........writeInitFile(theForm.getFile().getFileData()); // Obtain the uploaded fileMessage msg = messageHelper.createMessage( readInitFile() ); // messageHelper is a customized factory method to create Message objects. Passing the newlywrote 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 folderFileOutputStream 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 folderFileInputStream 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. -
6. Re: Unicode convert problem with Jboss in Linux
jfclere Aug 13, 2010 11:19 AM (in response to isurux)return buyteArray.toString().getBytes(); // return the byte []
This is going to convert the String into a a Byte[] using the platform encoding... that is why it works.