After further research, I assume that this is rather a misbehavior in the default Connector
that uses a HttpURLConnection
. As I explained in this other self-answered question of mine, the documentation states:
Whereas filters are primarily intended to manipulate request and response parameters like HTTP headers, URIs and/or HTTP methods, interceptors are intended to manipulate entities, via manipulating entity input/output streams
A WriterInterceptor
is not supposed to manipulate the header values while a {Client,Server}RequestFilter
is not supposed to manipulate the entity stream. If you need to use both, both components should be bundled within a javax.ws.rs.core.Feature
or within the same class that implements two interfaces. (This can be problematic if you need to set two different Priority
s though.)
All this is very unfortunate though, since JerseyTest
uses the Connector
that uses a HttpURLConnection
such that all my unit tests succeeded while the real life application misbehaved since it was configured with an ApacheConnector
. Also, rather than suppressing changes, I wished, Jersey would throw me some exceptions. (This is a general issue I have with Jersey. When I for example used a too new version of the ClientConnectionManager
where the interface was renamed to HttpClientConnectionManager
I simply was informed in a one line log statement that all my configuration efforts were ignored. I did not discover this log statement til very late in development.)