users@jersey.java.net

Re: [Jersey] Question about clients

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 28 Sep 2009 20:49:53 +0200

On Sep 28, 2009, at 6:02 PM, Roan Brasil Monteiro wrote:

> 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 :
>
> @POST
> 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?
>

In this respect yes. You could use a media type like application/
vnd.com.foo.user+xml instead of application/xml to be more
descriptive. But, you still need to know that you are dealing with the
"user" representation for that resource.

The Jersey client can be used as follows:

  Client c = ...
  WebResource r = c.resoruce(...);
  User u = r.type("application/xml").get(User.class);


> Another question if I need to look for the user and I need a array
> of param using get?
> for example:
>
> @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){
> .
> .
> ....
> }
>

Some developers prefer path parameters but query parameters may be
better as they are easier to utilize with HTML forms.

Paul.