2

In RESTful web services written using Jersey, I know I can access path parameters and query string parameters using @PathParam and @QueryParam annotaions. But in a web service written by someone else I saw a method like below.

@POST
@Path("/sms/receive")
@Consumes("application/json")
@Produces("application/json")
public Response smsReceive(String jsonBody) {
    //Code here...
}

There is no @PathParam or @QueryParamannotation before the argument jsonBody.

  1. Can anybody explaing what this argument means and how to set value for it when calling this service.
  2. Can I use multiple parameters without annotations?

Thanks.

prageeth
  • 7,159
  • 7
  • 44
  • 72

1 Answers1

3

The service above does not handle query or path parameters at all.

It @Consumes JSON input. That's what the method's parameter jsonBody is referring to.

If someone would want to instruct this service he would add a json payload to the http request which the service (in this case) receives as a simple String. The String then needs to be parsed.

Of course you can combine Path/Query Parameters with JSON Payloads.

Doe Johnson
  • 1,374
  • 13
  • 34
  • Thanks. It makes sense. As I understood it means I can't use two arguments without annotations. For an example `public Response smsReceive(String jsonBody1, String jsonBody2)` is invalid. Am I correct? – prageeth Nov 10 '14 at 12:35
  • Look here: http://stackoverflow.com/questions/5553218/jax-rs-post-multiple-objects You don't need to have several parameters. You can send mostly everything inside that json message. – Doe Johnson Nov 10 '14 at 12:44
  • Sorry I did not pay enough attention when I read it the first time. The link doe not fit exactly. You asked if you can't use two arguments without annotations. You're right. You would need to use something like `public Response smsReceive(String jsonBody, @PathParamm("foo") String foo)` – Doe Johnson Nov 10 '14 at 13:02