users@jersey.java.net

RE: [Jersey] Question about clients

From: Herak Sen <HSen_at_vertrax.com>
Date: Mon, 28 Sep 2009 13:28:53 -0400

I have two question, I would like to know how if I make a client using PHP or Java how can I send on the request body a XML file to my Resource Rest Class get the params?
For example :

Set the request content-type header to application/xml and then add @Consumes annotation on the resource class

@POST
@Consumes("application/xml")
public Response addUser(User user){
   user = userService.add(user);
   return Response.ok(user).build;
}


User Class

@XmlRootElement
public class User{
private String codUser;
private String name;
private String login;

/* setters and getter */
}

My question is if I have this situation how can I receive from the client a XML that is mapped to User class? how should be my Java client for example? Should I know the xml format that is defined on User Class?


Another question if I need to look for the user and I need a array of param using get?
for example:

Are you asking to how receive multi value parameters?
If that is the case then I would suggest using @QueryParams

@GET
public Response searchUser (@QueryParam("age") List<String> ageList )
{
    for (String age : ageList)
      System.out.println(age);

      return Response.ok().build();
}

Client
-------
?age=22&age=24

@GET
@Path({param1, param2}) or @Path({param1}/{param2})
//this param are like ages for example 22 and 24 or if i need to use 10 param
public Response searchUser(r){
   .
   .
   ....
}

--
Atenciosamente,
Roan Brasil Monteiro
http://roanbrasil.wordpress.com/
cheers,
Herak