users@jersey.java.net

RE: [Jersey] Integrated jsonp how to set JSONWithPadding http headers

From: saturon <gsaturon_at_gmail.com>
Date: Mon, 5 Oct 2009 17:43:09 +0200

Aahhh ,


I knew this couldn't be...

Ok thanks and sorry for the confusion ;)

-----Original Message-----
From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
Sent: Montag, 5. Oktober 2009 17:40
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] Integrated jsonp how to set JSONWithPadding http
headers



On Oct 5, 2009, at 5:34 PM, saturon wrote:

> Actually I would't mind the headers to be sent for json with padding,
> but in the JSONWithPadidng object there's no such header setting
> method
> ... Only in the Response object, that's the problem.
>
> I would have liked if JSONWithPadding was just a subclass of
> Response.
> Is there anything speaking against this?
>
>

Ah! an instance of JSONWithPading is an entity, and can be set as the
entity of the Response i.e. it is no different from another other
entity you want to return.

For example,

         JSONWithPadding p = new JSONWithPadding(data);
        Response.ResponseBuilder r = Response.ok(p);
        r.expires(mDate);
        r.lastModified(now);
        r.build();
        return r;

Paul.

>
> Otherwise I guess I just have to craft my own JSONWithPadding as you
> say.
>
> -----Original Message-----
> From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
> Sent: Montag, 5. Oktober 2009 17:18
> To: users_at_jersey.dev.java.net
> Subject: Re: [Jersey] Integrated jsonp how to set JSONWithPadding http
> headers
>
>
> HI,
>
> OK, i understand now, sort of... :-) but why would you not want those
> headers to be sent when JSONP is used?
>
> Currently the optional setting of such headers for different media
> types is not supported. I think the only way you could do this is to
> check the media type of the response in the resource method e.g.
> inject HttpContext and then do:
>
> MediaType contentType = httpContext.getResponse().getMediaType();
>
> or create your own version of a JSONWithPadding and a corresponding
> message body writer.
>
> Paul.
>
> On Oct 5, 2009, at 4:36 PM, saturon wrote:
>
>> Hi Paul,
>>
>> Yes I've seen those.
>>
>> Example:
>>
>> From this:
>> @GET
>> @Produces({"application/xml;charset=UTF-8", "application/json"})
>> public Response get( ...) {
>> ....
>> if (entities == null || entities.size() == 0) {
>> throw new NotFoundException();
>> }
>> Response.ResponseBuilder r = Response.ok(data);
>> r.expires(mDate);
>> r.lastModified(now);
>> r.build();
>> return r;
>> }
>>
>> To this: The same method supporting jsonp
>> @GET
>>
>> @Produces({"application/x-javascript","application/
>> xml;charset=UTF-8",
>> "application/json"})
>> public JSONWithPadding get(
>> @QueryParam("jsonp_callback") String callback,
>> ...) {
>> ....
>> if (entities == null || entities.size() == 0) {
>> throw new NotFoundException();
>> }
>> // switch on media type
>> if jsonp {
>> return new JSONWithPadding (... );
>> }
>>
>> //Question: how to set those header etc in case its not a jsonp
>> request...
>> Response.ResponseBuilder r = Response.ok(data);
>> r.expires(mDate);
>> r.lastModified(now);
>> r.build();
>> return r;
>> }
>>
>>
>> -----Original Message-----
>> From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
>> Sent: Montag, 5. Oktober 2009 16:09
>> To: users_at_jersey.dev.java.net
>> Subject: Re: [Jersey] Integrated jsonp how to set JSONWithPadding
>> http
>
>> headers
>>
>>
>> Hi,
>>
>> Can you give an example of how you want to use JSONWithPadding and
>> why
>
>> you want to set the media type and/or response codes?
>>
>> Have you seen the sample:
>>
>>
>> http://download.java.net/maven/2/com/sun/jersey/samples/jsonp/1.1.2-
>> ea
>> /j
>> sonp-1.1.2-ea-project.zip
>>
>> ?
>>
>> Paul.
>>
>> On Oct 5, 2009, at 3:26 PM, saturon wrote:
>>
>>> I am right to assume that json with padding is not fully integrated
>>> into jersey media types at the moment?
>>>
>>> I just would like not to miss something existing before I start
>>> writing propetarity code.
>>>
>>> Thanks ;)
>>>
>>> -----Original Message-----
>>> From: saturon [mailto:gsaturon_at_gmail.com]
>>> Sent: Sonntag, 4. Oktober 2009 03:47
>>> To: users_at_jersey.dev.java.net
>>> Subject: [Jersey] Integrated jsonp how to set JSONWithPadding http
>>> headers
>>>
>>>
>>> Hi all,
>>>
>>> I am in process of integrating jsonp media type and would like to
>>> have
>>
>>> this with my already supported types xml and json to be a
>>> transparent
>
>>> process.
>>>
>>>
>>> Right now JSONWithPadding is missing http header setting / response
>>> code methods... I am using jersey 1.1.2
>>>
>>> Solutions?
>>>
>>> Thanks, Ben
>>>
>>>
>>>
---------------------------------------------------------------------
>>> 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
>>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>>
>
>
> ---------------------------------------------------------------------
> 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
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
For additional commands, e-mail: users-help_at_jersey.dev.java.net