On Apr 13, 2010, at 12:37 PM, Patrick Sauts wrote:
> The original implementation was :
> @Produces("specialXml/xml; charset=UTF-16")
> @Provider
> public class SpecialXmlProvider extends JSONWithPaddingProvider {
> ...
> @Override
> public void writeTo(JSONWithPadding t, Class<?> type, Type
> genericType,
> Annotation[] annotations, MediaType mediaType, MultivaluedMap<String,
> Object> httpHeaders, OutputStream entityStream) throws IOException,
> WebApplicationException {
> ...
> Some JAXB mapping between standard xml and specialXML
> t = new JSONWithPadding(new
> GenericEntity<Object>(constructor.newInstance(specialXmlEntity)) {
> });
> super.writeTo(t, type, genericType, annotations, mediaType,
> httpHeaders,
> entityStream);
> ...
>
>
> Paul wrote :
> Your @Produces annotation on the resource method does not declare that
> JavaScript will be produced, so in effect the JSON padding will never
> occur.
>
> I'm not sure to understand, JSON is produced if we asked for
> "application/json" we only override response with the @Provider in
> case of
> "specialXml/xml; UTF-16".
>
JSONWithPadding supports the case when *JavaScript* may be requested
in addition to when something else may be requested. If a JavaScript
media type is requested then JSONWithPadding will serialize the
adapted entity as JSON and wrap that JSON in a JavaScript function.
If you do not require JavaScript being returned then you do not
require JSONWithPadding and you can just return the adapted object
directly.
Ideally you should be able to do the following:
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML,
"specialxml/xml; charset=UTF-16" })
public ResponseSpecialXml get() {
ResponseSpecialXml rsx = ..
return rsx.
}
if there was an appropriate message body writer for "specialxml/xml".
If you use "application/special+xml; charset=UTF-16" instead it should
just work with the existing JAXB support. That is preferably the
better way to define an XML-based media type.
If you require that the media type be "specialxml/xml" then i
recommend extending AbstractRootElementProvider.
@Produces("specialxml/xml")
public SpecialXmlProvider extends AbstractRootElementProvider {
public SpecialXmlProvider(@Context Providers ps) {
super(ps);
}
}
If you create a simple test case for what you have and send it to me i
can modify as appropriate (you can send it privately to me if there
are issues with public disclosure).
Paul.
>
> Patrick.
>
> -----Message d'origine-----
> De : Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
> Envoyé : mardi 13 avril 2010 12:12
> À : users_at_jersey.dev.java.net
> Cc : Guillaume Hiron
> Objet : Re: [Jersey] Response into UTF-16 encoding
>
>
> On Apr 13, 2010, at 11:55 AM, Patrick Sauts wrote:
>
>> The declaration on the resource is
>> @Produces( { MediaType.APPLICATION_JSON,
>> MediaType.APPLICATION_XML, "specialxml/xml; charset=UTF-16" })
>>
>>
>> In facts we change mediatype from "specialxml/mxl; charset=UTF-16" to
>> "application/xml; charset=UTF-16" in the writeTo method and that
>> made it
>> work fine.
>> If we leave it to "specialxml/mxl; charset=UTF-16" we have <?xml
>> version="1.0" encoding="UTF-8"> on top of the xml response.
>>
>> But maybe we were doing wrong at the first place.
>>
>
> I think it may be related to your original implementation of the
> provider supporting "specialxml/xml". What was that before you
> modified it to work?
>
> Note that for JAXB the following media types are only supported text/
> xml, application/xml and application/*+xml so "specialxml/xml"
> requires some adaption. Is that why you are overriding
> JSONWithPadding?
>
> Your @Produces annotation on the resource method does not declare that
> JavaScript will be produced, so in effect the JSON padding will never
> occur.
>
> Paul.
>
>> Pat.
>>
>> -----Message d'origine-----
>> De : Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
>> Envoyé : mardi 13 avril 2010 11:01
>> À : users_at_jersey.dev.java.net
>> Cc : Guillaume Hiron
>> Objet : Re: [Jersey] Response into UTF-16 encoding
>>
>>
>> On Apr 13, 2010, at 10:28 AM, Patrick Sauts wrote:
>>
>>> Hi Paul,
>>>
>>> Thanks to the code you sent us we’ve found a solution,
>>>
>>> @Produces("specialxlm/xml; charset=UTF-16")
>>> @Provider
>>> public class SpecialXMLProvider extends JSONWithPaddingProvider {
>>> …
>>> @Override
>>> public void writeTo(…){
>>> …
>>> super.writeTo(t, type, genericType, annotations,
>>> new MediaType("application", "xml", mediaType.getParameters()),
>>> httpHeaders, entityStream);
>>>
>>> …
>>> And it works fine that way.
>>>
>>
>> OK.
>>
>> I am still confused as to why the XML document, in your first email,
>> was encoded in UTF-16 and not UTF-8.
>>
>> Are you declaring an @Produces method on the resource method that
>> returns the JSON with padding?
>>
>> If you have the time to create a simple test case i can investigate
>> further, as it seems the work around you have implemented should not
>> be required i.e. it should just work as you expected.
>>
>> Paul.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>> Ce message entrant est certifié sans virus connu.
>> Analyse effectuée par AVG - www.avg.fr
>> Version: 9.0.801 / Base de données virale: 271.1.1/2805 - Date:
>> 04/12/10
>> 20:32:00
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
> Ce message entrant est certifié sans virus connu.
> Analyse effectuée par AVG - www.avg.fr
> Version: 9.0.801 / Base de données virale: 271.1.1/2805 - Date:
> 04/12/10
> 20:32:00
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>