In the web service I’ve been working on, I’ve been displaying text to the screen through methods like so in HTML:
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello()
{
/**Do some stuff
return "<html> " + "<title>" + "Hello" + "</title>"
+ "<body><h1>" + "Hello World" + "</h1></body></html>";
}
which displays to the screen quite nicely. In order to fit the project description of the project I’m working on, I’ve been working on moving toward an XML output by building a document, transforming it to a string, and returning the string. Using @Produces(MediaType.TEXT_XML) shows the XML tree like I would expect.
My question comes here: I need to be able to pass this XML data on using what the project description calls a Response Content-Type Header of application/xml;charset=UTF-8. So what would I need to do to accomodate using @Produces(MediaType.APPLICATION_XML) instead of @Produces(MediaType.TEXT_XML)?
application/xmlis generally the preferred mime type. Fortext/xmlit appears the encoding will generally be treated asus asciiregardless of what is specified in the XML document header (unless otherwise specified in the HTTP headers).For More Information: