File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JBoss/WildFly and the fly likes Unicode convert problem with Jboss in Linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Unicode convert problem with Jboss in Linux " Watch "Unicode convert problem with Jboss in Linux " New topic
Author

Unicode convert problem with Jboss in Linux

isuru chamarasinghe
Greenhorn

Joined: Aug 21, 2008
Posts: 12
Hello,

I have faced with an issue where 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.

Any suggestions or workarounds ?

Isuru Chamarasinghe.
BIT (C.Sturt), SCJP, SCWCD, SCBCD, A+, OCA
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Are your JSPs, HTMLs, property files etc. saved with the UTF-8 encoding ??


Regards, Rene Larsen
Dropbox Invite
isuru chamarasinghe
Greenhorn

Joined: Aug 21, 2008
Posts: 12
Hello Larsen,

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 array

byte[] buf = file.getFileData();

When I view the result of above buf variable at runtime it is clear that the unicode has been converted to a non recognized character.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Try put URIEncoding="UTF-8" in the HTTP connector - in the file JBOSS/server/default/deploy/jbossweb.sar/server.xml

Like this:
isuru chamarasinghe
Greenhorn

Joined: Aug 21, 2008
Posts: 12
I include the
URIEncoding="UTF-8"
attribute to HTTP Connector tag in jbossweb.sar/server.xml and restart the instance. No luck. same result.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

And you have tried all these steps too ??

1) struts-config:

2) included a jsp page directive:

3) included a meta tag within the html page itself:


What happens IF the uploaded file has the right encoding - UTF-8 ?? and not an unknown randomly type.
isuru chamarasinghe
Greenhorn

Joined: Aug 21, 2008
Posts: 12
Hello Larsen,

I have tired out all those but same result thank you very much for the guidance. Now I have identified the problem is on the server side and not in the view.

I realize that by trying 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?
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

On google I found this answer: http://stackoverflow.com/questions/2973576/encoding-a-jms-textmessage

Maybe it also works on JBoss (it should work there too)
isuru chamarasinghe
Greenhorn

Joined: Aug 21, 2008
Posts: 12
No Larsen,

It doesn't work with Jboss MQ.

I bedbug the Message Listener and found out that JBossTextMessage.getText() contains the file data with incorrect Unicode characters.

Any way of specifying the type of the Message before putting it to the Jboss MQ?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9327
    
110

JBoss AS-5 does not use JBoss MQ. It uses JBoss Messaging. Are you sure you are looking at the right classes?

[My Blog] [JavaRanch Journal]
isuru chamarasinghe
Greenhorn

Joined: Aug 21, 2008
Posts: 12
Yes it is Jboss Messaging as Jaikiran said but do you think this will have an effect on this Unicode issue ?
isuru chamarasinghe
Greenhorn

Joined: Aug 21, 2008
Posts: 12
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 FileOutputStream
2. 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



Foot Note: I think it is something to do with the Linux/Windows default file saving type. eg: Windows default : ANSI.
 
jQuery in Action, 2nd edition
 
subject: Unicode convert problem with Jboss in Linux
 
Similar Threads
Problem using Spanish characters in Ajax response.
ENV variables that determines encoding format
Spanish charset problem in Jboss
Spanish charset problem in Jboss in linux
MDB in EJB 3.0 and JBOSS AS 6.1 final