aXMLRPC
aXMLRPC copied to clipboard
encoding issue
Hi there..
I stumbled across a nasty encoding issue that could only be solved by using the vm parameter -Dfile.encoding=UTF-8
.
It seems your SimpleXMLCreator
is a little liar when it comes to the xml encoding.. The value used in "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
is not necessarily the same when de.timroes.axmlrpc.XMLRPCClient.Caller.call(String, Object[])
writes the xml to the http output stream.
Maybe you could replace
OutputStreamWriter stream = new OutputStreamWriter(http.getOutputStream());
by
OutputStreamWriter stream = new OutputStreamWriter(http.getOutputStream(), Charset.forName("UTF-8"));
in this line?
Hi,
if you're still interested in that bug, since you have the fix, could you please submit a pull request with both this fix, and consequent no reg test?
(Ideally, please submit the PR on https://github.com/gturri/aXMLRPC)
Hey gturri, sry for taking so long.. unfortunately I have no idea what you mean by "no reg test". I understand it's got something to do with android compatibility..!? But currently I'm neither into android development nor doing builds/tests/whatever with gradle. :( Sorry to let you down..
I'm also interested in having this fixed, especially since the fix - as shown - is quite trivial.
Hi @Frettman , Could you please give me more clue about when this fix is supposed to be useful? (I'm afraid I don't get it from the initial message). Is it when the server returns a response why has some unexpected encoding? Or when your code runs on some particular environment? Or something else?
The problem is that new OutputStreamWriter(http.getOutputStream())
uses the system's default encoding to write out the XML request. When the default encoding is not UTF-8
(like on Windows; at least until Java 18), this is in conflict with the static <?xml version="1.0" encoding="UTF-8"?>
from the generated request.
I suppose the default encoding on Android is already UTF-8, so it's never been an issue there.
By explicitly setting the encoding like in new OutputStreamWriter(http.getOutputStream(), StandardCharsets.UTF_8)
, this can be avoided. This would fix it for every platform where UTF-8
isn't the default and change nothing for every platform where UTF-8
already is the default.
Thanks for this information. The fix is merged. I'll try to release an updated version soon
The fix should be available in aXMLRPC v 1.12.1
that I just released.
However, I didn't do releases in a while and I encountered some weird error in the process. So even though I see that this version is available on maven central (https://central.sonatype.dev/artifact/fr.turri/aXMLRPC/1.12.1 ), I'm not 100% sure it was all successful.
Long story short: @Frettman I would appreciate if you can check on your side that using 1.12.1
indeed fixes the issue you observe
Thanks a lot for the quick response and fix. Much appreciated :) I'll test it next week.
I can confirm that the release has indeed fixed the issue :)
Cool! thanks for taking the time to test it
Thanks for taking the time to fix it :)