17.3. JAXB and XML provider

RESTEasy provides the required JAXB provider support for XML. It has several additional annotations to make application coding simpler.

17.3.1. @XmlHeader and @Stylesheet

To set an XML header when you output XML documents, use the @org.jboss.resteasy.annotations.providers.jaxb.XmlHeader annotation.
@XmlRootElement
public static class Thing
{
   private String name;

   public String getName()
   {
      return name;
   }

   public void setName(String name)
   {
      this.name = name;
   }
}

@Path("/test")
public static class TestService
{

   @GET
   @Path("/header")
   @Produces("application/xml")
   @XmlHeader("<?xml-stylesheet type='text/xsl' href='${baseuri}foo.xsl' ?>")
   public Thing get()
   {
      Thing thing = new Thing();
      thing.setName("bill");
      return thing;
   }
}
Here, the @XmlHeader forces an xml-stylesheet header on the XML output. The same result can be obtained by placing the header on the Thing class. Read the JavaDocs for further information regarding the substitution values provided by RESTEasy.
RESTEasy also has a convenient annotation for stylesheet headers. For example:
@XmlRootElement
public static class Thing
{
   private String name;

   public String getName()
   {
      return name;
   }

   public void setName(String name)
   {
      this.name = name;
   }
}

@Path("/test")
public static class TestService
{

   @GET
   @Path("/stylesheet")
   @Produces("application/xml")
   @Stylesheet(type="text/css", href="${basepath}foo.xsl")
   @Junk
   public Thing getStyle()
   {
      Thing thing = new Thing();
      thing.setName("bill");
      return thing;
   }
}