You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by smallufo <sm...@gmail.com> on 2008/10/06 14:04:14 UTC

JAX-RS : How to change encoding or charset ?

I am using cxf 2.1.2 to publish my service to json objects.
But all Chinese/Japanese characters are all truncated.
I tried to find something @charset or @encoding annotation , want to
change the encoding to "UTF-8"
But cannot find an answer ...


Can somebody tell me how to accomplish this ? Thanks a lot.

Re: JAX-RS : How to change encoding or charset ?

Posted by Édouard Mercier <re...@edouardmercier.fr>.
Hello to all.

I'm currently facing the same problem as smallufo: I have a simple JAX-RS
implementation with a class that uses the
"@ProduceMime("text/plain;charset=UTF-8") and one of its methods "@GET
@Path("/getActions") public String getActions() { return "é"; }". Everytime
I open a browser on the corresponding method, the plain text is not properly
encoded in the browser. My HTTP trace from a sniffer is:

http://localhost:9999/act/test

GET /act/test HTTP/1.1
Host: localhost:9999
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; fr; rv:1.9.0.3)
Gecko/2008092414 Firefox/3.0.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

HTTP/1.x 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 3
Server: Jetty(6.1.9)



I must also indicate that my Java source file encoded is "ISO-8859-1" and
that I've set the javac compiler accordingly. I'm using the jetty built-in
web server via spring via a

<jaxrs:server
    id="cxf.server.ApplicationConfigurationService"
    address="http://localhost:9999/"
>
  ...
</jaxrs:server>

and that I'm on CFX v2.1.2. I'm wondering whether the problem would not come
from the jetty configuration itself... Did I miss something, please? What
else should I do in order to have the returned string properly encoded (I've
tried the implementation of the method "new String(new
String("é").getBytes("UTF-8"), "UTF-8")")?

Thank you for your help.
Regards,
Édouard


smallufo wrote:
> 
> Thank you for replying so soon
> It works , thanks a lot.
> 
> 
> 2008/10/6 Sergey Beryozkin <se...@iona.com>:
>> Hi,
>>
>> Try @ProduceMime("application/json;charset=UTF-8")
>>
>> Cheers, Sergey
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/JAX-RS-%3A-How-to-change-encoding-or-charset---tp19836607p20175177.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: JAX-RS : How to change encoding or charset ?

Posted by smallufo <sm...@gmail.com>.
Thank you for replying so soon
It works , thanks a lot.


2008/10/6 Sergey Beryozkin <se...@iona.com>:
> Hi,
>
> Try @ProduceMime("application/json;charset=UTF-8")
>
> Cheers, Sergey
>

Re: JAX-RS : How to change encoding or charset ?

Posted by Sergey Beryozkin <se...@iona.com>.
Hi,

Try @ProduceMime("application/json;charset=UTF-8")

Cheers, Sergey

----- Original Message ----- 
From: "smallufo" <sm...@gmail.com>
To: <us...@cxf.apache.org>
Sent: Monday, October 06, 2008 1:04 PM
Subject: JAX-RS : How to change encoding or charset ?


>I am using cxf 2.1.2 to publish my service to json objects.
> But all Chinese/Japanese characters are all truncated.
> I tried to find something @charset or @encoding annotation , want to
> change the encoding to "UTF-8"
> But cannot find an answer ...
> 
> 
> Can somebody tell me how to accomplish this ? Thanks a lot.

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland