users@jersey.java.net

Re: [Jersey] POST method on subresource

From: Suneel Marthi <suneel_marthi_at_yahoo.com>
Date: Wed, 10 Feb 2010 06:42:42 -0800 (PST)

----- 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?


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?
>
> 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