I’m developing a rest web service on GAE. I’m using Jersey framework to implement the services. It is a POST service where I have to pass also parameters. I tried to use 2 types of annotation but I can’t get the parameters:
@Context
@POST
@Path("add")
@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Notification addUser(@Context UriInfo uriInfo){
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
String nickname = queryParams.getFirst("nickname");
String name = queryParams.getFirst("name");
String surname = queryParams.getFirst("surname");
String telephone = queryParams.getFirst("telephone");
String email = queryParams.getFirst("email");
User =createUser(nickname, name, surname, telephone, email);
.......
}
@QueryParam
@POST
@Path("add")
@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Notification addUser(@QueryParam("nickname") String nickname, @QueryParam("name") String name, @QueryParam("surname") String surname, @QueryParam("telephone") String telephone, @QueryParam("email") String email) {
User =createUser(nickname, name, surname, telephone, email);
......
}
But in both cases I can not get the parameters all of them are null values.
this is an example of my http request:
Request URL: http://windyser.appspot.com/rest/users/add
Request Method: POST
Params: {"nickname":"prova","name":"danilo","surname":"delizia","email":"prova@yahoo.it","telephone":"123"}
Sent Headers
Accept: */*
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept-Language: en
Anybody know if I’m missing something?
Thanks in advance for your help
Danilo
Jetty 8.x supports Java EE 6 and Jetty 7.x supports only Java EE 5.
I see from your first code snippet that you use “@Produces” annotation from Java EE 6. It must be the problem.
To fix:
[EDIT]
Let the service know that you need to consume String parameters. Try to use @Consumes runtime annotation:
next if you need to access the service:
Hope this helps.