The code is as follow.Where I am checking the content type extracted from the header then I want to write the code and return the response from the same method.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_XML)
public Response addMessage(Message message , @Context UriInfo uriInfo,
@HeaderParam ("content-type") String contentType) throws
URISyntaxException
{
//Conditional check based on the content type.
if(contentType.equals("application/json")) {
return json;
}else {
return xml;
}
}
How a rest API will return both Json and XML response depending on the input header?