I wanna use the same restful webservice path to produce xml or json, or a xml with xsl header.
Is it possible using any framework(jersey or resteasy) in java?
Eg:
@Path("/person")
public class PersonService {
@GET
@Path("/find")
public Person find(@QueryParam("name") String name, @QueryParam("outputformat") String outputformat) {
// do some magic to change output format
return dao.findPerson(name);
}
}
Maybe you can write a servlet filter that takes the query string and uses it to set the request’s accept header accordingly, then jersey should dispatch to whatever method is annotated with @Consumes that matches.
For example, servlet filter intercepts request “?outputFormat=xml” and sets the Accept header to “application/xml”. Then, jersey should dispatch to whichever method in your resource is annotated with:
@Consumes("application/xml")This question might help: REST. Jersey. How to programmatically choose what type to return: JSON or XML?