title: ContainerRequestFilter returns wrong content type for entity
body: <p>I want to make a global check for every request. Therefore, I use a <a href="https://docs.oracle.com/javaee/7/api/javax/ws/rs/container/ContainerRequestFilter.html" rel="nofollow"><code>ContainerRequestFilter</code></a> (without <a href="https://docs.oracle.com/javaee/7/api/javax/ws/rs/container/PreMatching.html" rel="nofollow"><code>@PreMatching</code></a>) and throw a <a href="http://docs.oracle.com/javaee/7/api/javax/ws/rs/WebApplicationException.html" rel="nofollow"><code>WebApplicationException</code></a> with a response containing an error entity, if the check is not passed. </p>
  
  <p>My problem is, that the content type of the response is not matching the <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1" rel="nofollow"><code>Accept</code></a> header of the request. But if I throw the same exception in my resource, the response contains the right content type. </p>
  
  <p><strong>Code:</strong></p>
  
  <p>My entity:</p>
  
  <pre class="lang-java prettyprint-override"><code>@XmlRootElement(namespace = "http://www.mycompany.com/test")
  @XmlAccessorType(value = XmlAccessType.FIELD)
  public class TestEntity {
  
      public TestEntity() {
          this.key = "error";
      }
  
      @XmlElement
      private String key;
  }
  </code></pre>
  
  <p>My filter: </p>
  
  <pre class="lang-java prettyprint-override"><code>@Named
  public class TestFilter implements ContainerRequestFilter {
      private boolean globalError = true;
  
      public void filter(final ContainerRequestContext requestContext) throws IOException {
          if (globalError) {
              throw new WebApplicationException(Response.status(422).entity(new TestEntity()).build());
          }
      } 
  }
  </code></pre>
  
  <p>My resource:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Named
  public class TestResource {
  
      @GET
      @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
      public void find() {
          throw new WebApplicationException(Response.status(422).entity(new TestEntity()).build());
      }
  }
  </code></pre>
  
  <p>My CXF configuration:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;jaxrs:server address="/rest/v1" id="test"&gt;
      &lt;jaxrs:serviceBeans&gt;
          &lt;ref bean="testResource" /&gt;
      &lt;/jaxrs:serviceBeans&gt;
      &lt;jaxrs:providers&gt;
          &lt;bean class="org.apache.cxf.jaxrs.provider.JAXBElementProvider" /&gt;
          &lt;bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider" /&gt;
          &lt;ref bean="testFilter" /&gt;
      &lt;/jaxrs:providers&gt;
  &lt;/jaxrs:server&gt;
  </code></pre>
  
  <p><strong>Test:</strong></p>
  
  <p>Request:</p>
  
  <pre class="lang-none prettyprint-override"><code>GET http://localhost:8080/test-webapp/services/rest/v1/ HTTP/1.1
  Accept-Encoding: gzip,deflate
  Accept: application/json
  Host: localhost:8080
  Connection: Keep-Alive
  User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
  </code></pre>
  
  <p>Response with <code>globalError=true</code>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;ns2:testEntity xmlns:ns2="http://www.mycompany.com/test"&gt;
        &lt;key&gt;error&lt;/key&gt;
  &lt;/ns2:testEntity&gt;
  </code></pre>
  
  <p>Response with <code>globalError=false</code>:</p>
  
  <pre><code>{"key":"error"}
  </code></pre>
  
  <p><strong>Questions:</strong></p>
  
  <p>Why is the response different? How can I fix it? </p>