Am new to RESTful web services. I wrote a web service method and am currently returning an XML by using @Produces(MediaType.TEXT_XML)
. But the requirement is that m
Use @Produces(MediaType.TEXT_PLAIN)
instead of @Produces(MediaType.TEXT_XML)
It will be text as you are using RESTful Webservices which is a pure HTTP implementation(Hyper TEXT Transfer Protocol).
To get an integer you can either cast at Client side manually.
Actually you have two options you may either return String or int, both will do. By returning int, a smart Client like Jersey Http client will automatically cast the String to int for you.
Example
@Path("{type}/{token}")
@GET
@Produces(MediaType.TEXT_PLAIN)
public int setToken(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("type") String type, @PathParam("token") String token) throws ServletException, IOException {
return 1;
}