Hi Friends,
After going through many forums and not able to find the answer I am posting it to the advanced forum. Please go through the below info and help me understand the solution. Hope to find the right direction from here.
Regards,
Mayank
==============================================================================================
Hi friends,
I'm facing a strange problem over here. I'm trying to post a request to HttpServlet.
In between I have a small
JAVA application which reads the request body from imputStream and streams the same(along with headers) to the
servlet.
Due to legacy reasons we are using BufferedReader and thus read in achar array instead of byte.
This all works fine till I post a request containing Hebrew characters, in which case when I stream the request to servlet, the Hebrew charactes are changed and thus take more bytes than original Content-Length header.
I have tried System.setProperty("file.encoding", "UTF-8") and also setProperty("sun.jnu.encoding", "UTF-8") without any luck.
One thing which blows me off is if I set LANG variable in Linux to have UTF-8 as character encoding(ex en_US.UTF-8 ), this all works fine and characters are not converted. Any encoding apart from UTF-8 fails, but I dont understand the dependency on OS level Lang parameter given that many sites quote that streams in java are converted from file.encoding to unicode and viceverca
Any suggestions and help in this is highly appreciated.
Regards,
Mayank[/color]
--------------------------------------------------------------------------------
mayank
omar al kababji
Ranch Hand
Joined: Jan 13, 2009
Messages: 196
posted Tuesday, February 10, 2009 5:09:47 PM
Hi have you tried to add a header to the request saying that its contents are UTF-8 encoded ? another solution would be calculaing the size of your contents and change the original Content-Length in the header.
--------------------------------------------------------------------------------
SCJP 1.5 90%
SCWCD in progress...
k mayank
Greenhorn
Joined: Feb 09, 2009
Messages: 3
posted Wednesday, February 18, 2009 11:25:14 AM
Hi All,
Sorry for comming back late on this... was out of town(without internet access) for some emergency.
I have read both the options given below.
The problem scenario is that we intercept the request to servlet in between and validate it against certain rules.
I case all the rules are satisfied then the request is forwarded to the servlet else, it is not.
In the entire process we are not allowed to change the request header or doby even by a bit.
Please help me understand that how can Java depend on Linux LANG setting instead of its own file.encoding property.
I was setting the file.encoding in the constructor of the class as well as at startup of application in my main method.
Any link which shall provide some information on this is highly appretiable.
Regards,
Mayank
--------------------------------------------------------------------------------
mayank
k mayank
Greenhorn
Joined: Feb 09, 2009
Messages: 3
posted Yesterday 4:45:32 PM
Hi Friends,
Any Advises please....
Regards,
Mayank