You are right, the BufferedOutputStream from response.getOutputStream() is
UTF-8.
But StringRequestTarget creates its own StringBufferResourceStream. This
stream is copied to the BufferedOutputStream.
Unfortunately the CharSet of the StringBufferResourceStream is null until
you call AbstractResourceStream.setCharSet().
If you don't call setCharSet(), the CharSet of the data (as it goes over the
wire) is the same as the CharSet defined by the "file.encoding" system
property.
In short: if your system encoding is not UTF-8, you copy a non-UTF-8 stream
to into an UTF-8 stream and get garbage.
Btw, there seems to be a mixup of "content type" and "mime type":
/**
* Constructor.
*
* @param contentType
* The mime type of this resource, such as "image/jpeg"
or "text/html"
*/
public AbstractStringResourceStream(final String contentType)
{
...
}
Niels
-----Ursprüngliche Nachricht-----
Von: Johan Compagner [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 28. August 2008 10:27
An: [email protected]
Betreff: Re: Question regarding [WICKET-1420] - Allow to change charset
in St ringRequestTarget
Is the output stream really set to cp1252?
How is that possible?
Because we set as far as we know the encoding to UTF-8 (by default) or what
you have set in the settings
And StringRequestTarget gets the Wicket response.getOutputStream() which
really should be be configured in the WicketFilter
johan
On Wed, Aug 27, 2008 at 1:44 PM, <[EMAIL PROTECTED]> wrote:
> Hi,
>
> we ran into trouble with the StringRequestTarget on Wicket 1.4-m3, when
our
> system file.encoding was different from the encoding used for the
> communication between Wicket and the web browser. In short, we use UTF-8
> for
> our web pages and JSON. Java uses Cp1252 as file encoding on one of our
> machines, so the CharSet of the OutputStream used by StringRequestTarget
is
> set to Cp1252 as well.
>
> The StringRequestTarget sets the content type to "text/charset=utf-8" by
> default (possibly because the request is encoded in UTF-8 ?).
> Setting a the content type parameter of the StringRequestTarget to
> "application/json; charset=UTF-8" does not change the charset used by the
> OutputStream, so you will send corrupt data. I don't think that the
content
> type should be set to "...;charset:cp1252" - if the web pages and the
> request are UTF-8, the response should be UTF-8 as well.
>
> Right now we are overloading StringResourceTarget (= cutting and pasting
> the
> whole class, then applying our changes), so that we have a new
constructor:
> > public MyStringRequestTarget(String mimeType, String string, Charset
> charset) { ... }
>
> The charset is stored in a member variable and used in in onResponse():
>
> > MyStringRequestTarget.onResponse()
> > {
> > ...
> > stream.setCharset(charset);
> > response.setContentType(mimeType + ";charset=" + charset.name());
> > ...
> > }
>
> Could these changes be applied to Wicket / trunk 1.4?
> Or am I missing something obvious?
>
> Niels
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]