user2144555
user2144555

Reputation: 1313

Consume a String sent via PUT method

I'm developing REST services using Jersey. In a PUT method, I want to consume a String, and then use it in another method.

Something like: I enter a String in the "Content" field (of TEST REST WEB SERVICES page) and then I use that String in a logout method:

@PUT
@Path("logout")
@Produces({"application/json", "text/plain"})
@Consumes(**xxxxx**)
public String logout(**xxxxx**) throws Exception
{
     String reponse = null;
     reponse = new UserManager().logout(**xxxxx**);
     return reponse;
}

So, I want to know what to put in the ** xxxxx ** fields.

Thanks!

Upvotes: 0

Views: 1032

Answers (1)

Perception
Perception

Reputation: 80603

Just use a String argument. The JAX-RS runtime will marshall the request body into it.

@PUT
@Path("logout")
@Produces({"application/json", "text/plain"})
public String logout(String data) throws Exception {
     String response = null;
     reponse = new UserManager().logout(data);
     return response;
}

You should define @Consumes to be whatever content type(s) you want to allow the client to be able to send, or leave it out altogether to accept any content type.

Upvotes: 2

Related Questions