3

I am trying to send use Ext.Ajax.request method to delete some data on server. My request method looks as below :

Ext.Ajax.request({
      url: '/myserver/restful/service/delete',
      method: 'DELETE',
      headers: {
        'Content-Type': 'application/json'
      },
      params: {
        userId: 12345
      }
});

On my jersey server I have written which looks like as below :

@Path("/delete")
  @DELETE
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response deleteUser(final String userId) {
    System.out.println("user id = " + userId);
    return Response.ok().entity("success").build();
  }

This method prints out user id in following format :

user id = userId=12345

So my expected value for userId is 12345 but it is giving me userId=12345. As I am newbie to jersey thing, I am not able to decide what to do now.

Can anyone please tell what is going wrong?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Shekhar
  • 11,438
  • 36
  • 130
  • 186
  • 1
    I solved my problem by appending userId to url itself. Now my url part looks like '/myserver/restful/service/delete?userId=12345' – Shekhar Dec 19 '12 at 14:14

2 Answers2

5

Not sure about what's going wrong in Jersey, but... if you are trying to use DELETE with a request body you're on the wrong track anyway. Don't. The only relevant parameter for DELETE should be the request URI it's being applied to.

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
2

@Julian is correct you really shouldn't have params with an HTTP DELETE verb.

Try this:

@Path("/delete/{userId} 

Then inside of your method:

@PathParam("userId") String userId

And then when you call your service change your url to : delete/(userId) (without the parens) and remove the params.

El Guapo
  • 5,581
  • 7
  • 54
  • 82