You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Dennis Kieselhorst <ma...@dekies.de> on 2016/10/25 12:28:48 UTC

JAX-RS response encoding

Hi,

what is the best practice to specify the encoding for a JAX-RS response?

If found something like this: @Produces(MediaType.APPLICATION_JSON + ";"
+ CharEncoding.UTF_8)

However it fails with:

Caused by: java.lang.IllegalArgumentException: Wrong media type
parameter, separator is missing
    at
org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider.addParameter(MediaTypeHeaderProvider.java:121)
    at
org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider.internalValueOf(MediaTypeHeaderProvider.java:108)
    at
org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider.valueOf(MediaTypeHeaderProvider.java:65)
    at
org.apache.cxf.jaxrs.utils.JAXRSUtils.toMediaType(JAXRSUtils.java:1715)
    at
org.apache.cxf.jaxrs.utils.JAXRSUtils.parseMediaTypes(JAXRSUtils.java:1445)
    at
org.apache.cxf.jaxrs.utils.JAXRSUtils.getMediaTypes(JAXRSUtils.java:233)
    at
org.apache.cxf.jaxrs.model.OperationResourceInfo.checkMediaTypes(OperationResourceInfo.java:249)
    at
org.apache.cxf.jaxrs.model.OperationResourceInfo.<init>(OperationResourceInfo.java:89)


Regards

Dennis


Re: JAX-RS response encoding

Posted by Jose MarĂ­a Zaragoza <de...@gmail.com>.
2016-10-27 10:18 GMT+02:00 Dennis Kieselhorst <ma...@dekies.de>:
> Thanks for the hints, added charset= and error is no longer thrown but it
> doesn't have any effect either, probably because default is UTF-8.
>
> I was confused because browsers (tested Chrome and Firefox) interpret the
> response as windows-1252. But obviously this is a bug:
> https://bugs.chromium.org/p/chromium/issues/detail?id=438464


What version of CXF are you using ?

i had problems with JSON encoding in CXF 2.7.8, solved in later releases


>
> Cheers
> Dennis
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-response-encoding-tp5774335p5774403.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: JAX-RS response encoding

Posted by Dennis Kieselhorst <ma...@dekies.de>.
Thanks for the hints, added charset= and error is no longer thrown but it
doesn't have any effect either, probably because default is UTF-8.

I was confused because browsers (tested Chrome and Firefox) interpret the
response as windows-1252. But obviously this is a bug:
https://bugs.chromium.org/p/chromium/issues/detail?id=438464

Cheers
Dennis



--
View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-response-encoding-tp5774335p5774403.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: JAX-RS response encoding

Posted by Sergey Beryozkin <sb...@gmail.com>.
The actual error was caused by a missing "charset="

Sergey
On 25/10/16 13:34, Benson Margulies wrote:
> Adding a charset to the json mime type is not permitted. Json as a MIME
> type must be UTF-8, period, the modifier is not permitted by the relevant
> RFC / IANA specs.
>
>
> On Tue, Oct 25, 2016 at 8:28 AM, Dennis Kieselhorst <ma...@dekies.de> wrote:
>
>> Hi,
>>
>> what is the best practice to specify the encoding for a JAX-RS response?
>>
>> If found something like this: @Produces(MediaType.APPLICATION_JSON + ";"
>> + CharEncoding.UTF_8)
>>
>> However it fails with:
>>
>> Caused by: java.lang.IllegalArgumentException: Wrong media type
>> parameter, separator is missing
>>     at
>> org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider.addParameter(
>> MediaTypeHeaderProvider.java:121)
>>     at
>> org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider.internalValueOf(
>> MediaTypeHeaderProvider.java:108)
>>     at
>> org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider.valueOf(
>> MediaTypeHeaderProvider.java:65)
>>     at
>> org.apache.cxf.jaxrs.utils.JAXRSUtils.toMediaType(JAXRSUtils.java:1715)
>>     at
>> org.apache.cxf.jaxrs.utils.JAXRSUtils.parseMediaTypes(
>> JAXRSUtils.java:1445)
>>     at
>> org.apache.cxf.jaxrs.utils.JAXRSUtils.getMediaTypes(JAXRSUtils.java:233)
>>     at
>> org.apache.cxf.jaxrs.model.OperationResourceInfo.checkMediaTypes(
>> OperationResourceInfo.java:249)
>>     at
>> org.apache.cxf.jaxrs.model.OperationResourceInfo.<init>(
>> OperationResourceInfo.java:89)
>>
>>
>> Regards
>>
>> Dennis
>>
>>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Re: JAX-RS response encoding

Posted by Benson Margulies <be...@basistech.com>.
Adding a charset to the json mime type is not permitted. Json as a MIME
type must be UTF-8, period, the modifier is not permitted by the relevant
RFC / IANA specs.


On Tue, Oct 25, 2016 at 8:28 AM, Dennis Kieselhorst <ma...@dekies.de> wrote:

> Hi,
>
> what is the best practice to specify the encoding for a JAX-RS response?
>
> If found something like this: @Produces(MediaType.APPLICATION_JSON + ";"
> + CharEncoding.UTF_8)
>
> However it fails with:
>
> Caused by: java.lang.IllegalArgumentException: Wrong media type
> parameter, separator is missing
>     at
> org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider.addParameter(
> MediaTypeHeaderProvider.java:121)
>     at
> org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider.internalValueOf(
> MediaTypeHeaderProvider.java:108)
>     at
> org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider.valueOf(
> MediaTypeHeaderProvider.java:65)
>     at
> org.apache.cxf.jaxrs.utils.JAXRSUtils.toMediaType(JAXRSUtils.java:1715)
>     at
> org.apache.cxf.jaxrs.utils.JAXRSUtils.parseMediaTypes(
> JAXRSUtils.java:1445)
>     at
> org.apache.cxf.jaxrs.utils.JAXRSUtils.getMediaTypes(JAXRSUtils.java:233)
>     at
> org.apache.cxf.jaxrs.model.OperationResourceInfo.checkMediaTypes(
> OperationResourceInfo.java:249)
>     at
> org.apache.cxf.jaxrs.model.OperationResourceInfo.<init>(
> OperationResourceInfo.java:89)
>
>
> Regards
>
> Dennis
>
>