aXMLRPC icon indicating copy to clipboard operation
aXMLRPC copied to clipboard

encoding issue

Open flohmueller opened this issue 9 years ago • 2 comments

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?

flohmueller avatar Mar 26 '15 15:03 flohmueller

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)

gturri avatar Jan 30 '16 15:01 gturri

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..

flohmueller avatar Feb 12 '16 06:02 flohmueller

I'm also interested in having this fixed, especially since the fix - as shown - is quite trivial.

Frettman avatar Nov 04 '22 14:11 Frettman

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?

gturri avatar Nov 04 '22 16:11 gturri

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.

Frettman avatar Nov 04 '22 16:11 Frettman

Thanks for this information. The fix is merged. I'll try to release an updated version soon

gturri avatar Nov 04 '22 18:11 gturri

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

gturri avatar Nov 04 '22 21:11 gturri

Thanks a lot for the quick response and fix. Much appreciated :) I'll test it next week.

Frettman avatar Nov 04 '22 21:11 Frettman

I can confirm that the release has indeed fixed the issue :)

Frettman avatar Nov 07 '22 16:11 Frettman

Cool! thanks for taking the time to test it

gturri avatar Nov 07 '22 17:11 gturri

Thanks for taking the time to fix it :)

Frettman avatar Nov 07 '22 21:11 Frettman