users@jersey.java.net

Re: [Jersey] POST method on subresource

From: George <george.news_at_gmx.net>
Date: Wed, 10 Feb 2010 16:44:27 +0100

On 10/02/2010 15:42, Suneel Marthi wrote:
>
>
> ----- Original Message ----
> From: George<george.news_at_gmx.net>
> To: users_at_jersey.dev.java.net
> Cc: Paul Sandoz<Paul.Sandoz_at_Sun.COM>
> Sent: Wed, February 10, 2010 10:21:32 AM
> Subject: Re: [Jersey] POST method on subresource
>
> Hi,
>
> I have just discovered the problem. The issue is that I was also getting
> some parameter from the URL.
>
> After serveral tries I have realized that the first method parameter has
> to be the ones annotatted, or at least now it works.
>
> // Previous
> public void post(JAXBElement<Whatever> whatever, @PathParam("id") String
> id) {
> }
>
> // Current
> public void post(@PathParam("id") String id, JAXBElement<Whatever>
> whatever) {
> }
>
> Am I correct?
>
> What is the URI you are invoking for this POST?


I'm posting to http://locahost:8084/resources/card/{id}

And I'm posting something from the class Whatever.

BTW now it seems that it is working.


> On 10/02/2010 15:00, Paul Sandoz wrote:
>> Hi George,
>>
>> So you are saying that the following does not work for you?
>>
>>> @POST
>>> public void post(JAXBElement<Whatever> whatever) {
>>> }
>>
>> What error do you get when you perform
>>
>> POST /card/{d}
>>
>> ?
>>
>> What version of Jersey and what client are you using?

Jersey 1.1.4 I think, the one inside Netbeans 6.8.

And as the client I'm using firefox ;) I'm now starting developing the
client using jersey, but I get some error on class unmarshalling and Lists.

See you

>> Also enabling logging on the server-side will help debug issues:
>>
>> https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/LoggingFilter.html
>>
>>
>> Paul.
>>
>>
>> On Feb 9, 2010, at 12:49 PM, George wrote:
>>
>>> Hi,
>>>
>>> I would like to perform a post on a subresource but although defined
>>> in code, the post is not exported.
>>>
>>> I have /card/{id} and I want to make a post to /card/{id} as it will
>>> add stuff to the id subresource. However I'm not able to do that. Only
>>> put is exported.
>>>
>>> POST /card/{id} --> /card/{id}/whatever and modify status of card
>>>
>>>
>>> Code (I have remove some parts of the code):
>>>
>>> public class CardResource {
>>>
>>> @Context
>>> private UriInfo context;
>>>
>>> /** Creates a new instance of CardResource */
>>> public CardResource(UriInfo context, String id) {
>>> this.context = context;
>>> this.card = CardsDB.getInstance().findById(id);
>>> }
>>>
>>> @GET
>>> @Produces("application/xml")
>>> public Card getXml() {
>>> return card;
>>> }
>>>
>>> @PUT
>>> @Consumes("application/xml")
>>> public void putXml(@PathParam("id") String id, String content) {
>>> // I don't use it
>>> }
>>>
>>> @DELETE
>>> public void delete(@PathParam("id") String id) {
>>> }
>>>
>>> @POST
>>> public void post(JAXBElement<Whatever> whatever) {
>>> }
>>> }
>>>
>>> public class CardsResource {
>>>
>>> @Context
>>> private UriInfo context;
>>>
>>> /** Creates a new instance of CardsResource */
>>> public CardsResource() {
>>> }
>>>
>>> @GET
>>> @Produces({"application/xml", "application/json"})
>>> public Cards getXml() {
>>> //TODO return proper representation object
>>> Cards a = new Cards();
>>> a.addAll(CardsDB.getInstance().getCards());
>>>
>>> return a;
>>> }
>>>
>>> @POST
>>> @Consumes({"application/xml", "application/json"})
>>> @Produces({"application/xml", "application/json"})
>>> public Response postXml(JAXBElement<Card> card) {
>>> CardsDB.getInstance().addCard(card.getValue());
>>> URI carUri = context.getAbsolutePathBuilder().
>>> path(card.getValue().getId().toString()).
>>> build();
>>>
>>> ResponseBuilder resp = Response.ok(card);
>>> resp.location(carUri);
>>> return resp.build();
>>> //return Response.created(carUri).build();
>>> }
>>>
>>>
>>> @Path("{id}")
>>> public CardResource getCardResource(@PathParam("id") String id) {
>>> return new CardResource(context, id);
>>> }
>>> }
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>