I'm implementing a web service, that is deployed on a Wildfly-15 application server. I'd like to have the Content-Type
HTTP response header to include charset=UTF-8
. This is necessary for the client to understand my response.
One of my clients always sends its request without specifying charset in Content-Type
. Wildfly's web service stack in this case uses the default charset=ISO-8859-1
in the response. See this behavior in undertow code, lines 602-611:
private String extractCharset(HeaderMap headers) {
String contentType = headers.getFirst(Headers.CONTENT_TYPE);
if (contentType != null) {
String value = Headers.extractQuotedValueFromHeader(contentType, "charset");
if (value != null) {
return value;
}
}
return ISO_8859_1;
}
Because my response is, in fact, UTF-8
-encoded (and its need to be), this causes trouble on the client side. See the header dumps in the undertow log:
----------------------------REQUEST---------------------------
header=Connection=Keep-Alive
header=SOAPAction=****
header=Accept-Encoding=gzip,deflate
header=Content-Type=text/xml
header=Content-Length=2137
header=User-Agent=Apache-HttpClient/4.1.1 (java 1.5)
header=Host=****
locale=[]
method=POST
....
--------------------------RESPONSE--------------------------
header=Connection=keep-alive
header=Content-Type=text/xml;charset=ISO-8859-1
header=Content-Length=1553
header=Date=Tue, 29 Jan 2019 16:19:38 GMT
status=200
This kind of response leads to the following exception in an IBM Websphere application:
org.springframework.ws.InvalidXmlException: Could not parse XML; nested exception is org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xffffffff) was found in the element content of the document.
Unfortunately, modifying the client is not an option.
My efforts so far went into trying to configure Widlfy's undertow via specifying filters to override HTTP Response headers. I was able to set Content-Encoding
only, with the help of Response Header filter. It seems, the Content-Type
header is overridden somewhere else along the line.
My second guess was to use Expression Filter with the expression
header(header=Content-Type, value='text/xml;charset=UTF-8')
Unfortunately, it didn't work also.
charset=UTF-8
?User contributions licensed under CC BY-SA 3.0