As there was no encoded defined by the returned XML string, Spring used the default StringHttpMessageConverter
which encodes everything as ISO-8859-1 as that is the default for HTTP responses when no other is specified.
It looks like the StringHttpMessageConverter
class can be instantiated with a provided character set. This can then be set on the overall gateway for the service so that all of the end points use the desired character set.
The solution derived was to create one in the Spring Context like this:
<bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg index="0" ref="utf8Charset"/>
</bean>
<bean id="utf8CharsetFactory" class="CharsetFactory"/>
<bean id="utf8Charset" factory-bean="utf8CharsetFactory" factory-method="createUTF8Charset" />
Then use it within the gateway, as such:
<http:outbound-gateway request-channel="requestChannel"
url-expression="'${bir.xml.url}' + payload.toString()" http-method="GET"
extract-request-payload="true" expected-response-type="java.lang.String"
charset="UTF-8" reply-timeout="30000" reply-channel="dtdRemovingTransformerChannel"
message-converters="stringHttpMessageConverter"
mapped-response-headers="Date, Server, Pragma, Cache-Control, SVRID, last-modified">
</http:outbound-gateway>
Obviously, this applies the UTF-8 encoding everywhere that just a String is being returned, but that is acceptable within the application.