I Have a web application which is making a HEAD call before making actual GET call. The GET method produces application/json. When there is an error say (500) the content-type of the HEAD changes to text/html. For same error the content-type for GET remains application/json. Is there a way to override the content-type being returned in HEAD. This is how I am forming the response. This is a jersery implementation.
Response.status(errorStatus)entity( some json).build()
Manish.
I bet the org.apache.catalina.valves.ErrorReportValve is squashing your response.
Take a look at the "report" method of that class. If the response is 4xx or 5xx and it has no content (i.e. no entity - which a HEAD response does not have) (line 153) then...
set the content-type
to text/html
(line 283). Your response has just been squashed, but...
ErrorReportValve does not do anything to the response if it has already been committed (line 102).
So, maybe try creating a servlet filter that commits the response before the ErrorReportValve squashes it? Something like this https://gist.github.com/danmork/bf8c468141fa004298928a1ad9b31746, perhaps?