• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Input Stream

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
k mayank
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
k mayank
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,

Any Advises please....


Regards,
Mayank
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would guess that some part of the whole chain of processing does not handle encodings correctly. In particular, that it uses the platform default encoding instead of the encoding specified by the code.
 
k mayank
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

Is it possible for java to use platform default encoding instead of its own file.encoding.
In what scenarios will that be done.

Regards,
Mayank
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java *always* uses the platform default encoding -which is the system property "file.encoding"- unless you specifically tell it to do otherwise.

I can't tell from your earlier posts whether you change that property at JVM startup -in which case it becomes the default encoding- or if you set it later during runtime (which could easily lead to compatibility problems, I would imagine).

Either set the property as a JVM parameter, or make sure that ALL your I/O handling specifies the encoding explicitly.
 
k mayank
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry to be asking stupid question, but by JVM startup do you mean when I call public static void main.
In that case I have set it there. This little multi threaded application is sitting on a different machine from the servlet.
Regards,
Mayank
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I meant as a JVM parameter. But upon examining this JVM bug report it seems that not all (any?) JVMs support changing that property. The preferred way of influencing the platform default encoding is thus to do what you did before - set the OS locale accordingly.
 
k mayank
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

Thanks a lot for your reply and time. This was really helpful.

Thanks and Regards,
Mayank
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic