title: Changing content type in jax-rs REST service
body: <p>Forgive me, but I may not be familiar with all the lingo necessary to ask this question properly. </p>
  
  <p>I'm working on a fairly simple REST web service in Java using the <code>org.apache.cxf.jaxrs.ext</code> implementation of jax-rs.  The method header is like this:</p>
  
  <pre><code>@GET
  @Path("json/{fullAlias}")
  @Produces({"application/json"})
  public String json(@PathParam("fullAlias") String fullAlias, @Context MessageContext req)
  </code></pre>
  
  <p>where MessageContext is <code>org.apache.cxf.jaxrs.ext.MessageContext</code>.  </p>
  
  <p>There are two things I'm trying to accomplish that I can't seem to figure out:</p>
  
  <ol>
  <li>Change the content-type if certain conditions are met (e.g. for an error)</li>
  <li>Change the status code of the response</li>
  </ol>
  
  <p>I've tried using changing the response by accessing it through the MessageContext:</p>
  
  <pre><code>HttpServletResponse response = req.getHttpServletResponse();
  response.setContentType("text/plain")
  response.setStatus("HttpServletResponse.SC_BAD_REQUEST);
  </code></pre>
  
  <p>But these changes have no bearing on the response sent; with or without the @Produces annotation, setting the content type inside the method doesn't affect the actual content type (With the annotation, it of course returns "application/json", without it defaults to "text/html").  </p>
  
  <p>I am returning a simple String as the body.  I've entertained trying to return a javax.ws.rs.core.Response object to do what I want, but I don't know much about it.</p>
  
  <p>How would I change the content type and/or the status codes from inside this method?</p>