You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Benjamin Heiskell <be...@gmail.com> on 2012/11/30 15:55:33 UTC

Resources used as an API

Hi,

I needed to implement a dynamic JSON API for programmatic consumption
by another application. I ended up implementing AbstractResource to
accomplish this task (using Wicket 6.2.0.).

First question, does this violate the intent of resources? If so, is
there a good way to do this within Wicket? Or, would you strongly
suggest I use a more traditional API framework (e.g., Jersey)?

If resources should be able to perform this task, I ran into some
weird behavior. When I explicitly setStatusCode on ResourceResponse to
200, the HTTP body of the response came back empty. I'm pretty sure
this is due to the following check in AbstractResource#respond:

if (!data.dataNeedsToBeWritten(attributes) || data.getErrorCode() !=
null || data.getStatusCode() != null) { return; }

My use case is trivial (200 on success, 500 on error). So, it was easy
enough to remove the explicit declaration of a 200 and let it default
to OK. However there are many other status codes that are not errors
that might warrant a HTTP body. This seems like a bug to me. Is this
by design?

Thanks in advance!
Ben

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Resources used as an API

Posted by Benjamin Heiskell <be...@gmail.com>.
Thanks! For posterity: https://issues.apache.org/jira/browse/WICKET-4900

On Fri, Nov 30, 2012 at 10:13 AM, Martin Grigorov <mg...@apache.org> wrote:
> Please file a ticket.
>
>
> On Fri, Nov 30, 2012 at 3:55 PM, Benjamin Heiskell
> <be...@gmail.com>wrote:
>
>> Hi,
>>
>> I needed to implement a dynamic JSON API for programmatic consumption
>> by another application. I ended up implementing AbstractResource to
>> accomplish this task (using Wicket 6.2.0.).
>>
>> First question, does this violate the intent of resources? If so, is
>> there a good way to do this within Wicket? Or, would you strongly
>> suggest I use a more traditional API framework (e.g., Jersey)?
>>
>> If resources should be able to perform this task, I ran into some
>> weird behavior. When I explicitly setStatusCode on ResourceResponse to
>> 200, the HTTP body of the response came back empty. I'm pretty sure
>> this is due to the following check in AbstractResource#respond:
>>
>> if (!data.dataNeedsToBeWritten(attributes) || data.getErrorCode() !=
>> null || data.getStatusCode() != null) { return; }
>>
>> My use case is trivial (200 on success, 500 on error). So, it was easy
>> enough to remove the explicit declaration of a 200 and let it default
>> to OK. However there are many other status codes that are not errors
>> that might warrant a HTTP body. This seems like a bug to me. Is this
>> by design?
>>
>> Thanks in advance!
>> Ben
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com <http://jweekend.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Resources used as an API

Posted by Martin Grigorov <mg...@apache.org>.
Please file a ticket.


On Fri, Nov 30, 2012 at 3:55 PM, Benjamin Heiskell
<be...@gmail.com>wrote:

> Hi,
>
> I needed to implement a dynamic JSON API for programmatic consumption
> by another application. I ended up implementing AbstractResource to
> accomplish this task (using Wicket 6.2.0.).
>
> First question, does this violate the intent of resources? If so, is
> there a good way to do this within Wicket? Or, would you strongly
> suggest I use a more traditional API framework (e.g., Jersey)?
>
> If resources should be able to perform this task, I ran into some
> weird behavior. When I explicitly setStatusCode on ResourceResponse to
> 200, the HTTP body of the response came back empty. I'm pretty sure
> this is due to the following check in AbstractResource#respond:
>
> if (!data.dataNeedsToBeWritten(attributes) || data.getErrorCode() !=
> null || data.getStatusCode() != null) { return; }
>
> My use case is trivial (200 on success, 500 on error). So, it was easy
> enough to remove the explicit declaration of a 200 and let it default
> to OK. However there are many other status codes that are not errors
> that might warrant a HTTP body. This seems like a bug to me. Is this
> by design?
>
> Thanks in advance!
> Ben
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>