Ecwid / ecwid-mailchimp

MailChimp API Wrapper for Java
Apache License 2.0
86 stars 83 forks source link

Allow gzip responses from MailChimp through DecompressingHttpClient #33

Open snappieT opened 8 years ago

snappieT commented 8 years ago

I've started to get gzipped responses from MailChimp in certain error cases, but the Apache HttpClient doesn't decompress the response before calling EntityUtils.toString. This resulted in a garbage string that later caused JSON parsing errors:

Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 2 column 2
    at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1505) ~[LeadinJobs-executable.jar:na]
    at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1386) ~[LeadinJobs-executable.jar:na]
    at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:531) ~[LeadinJobs-executable.jar:na]
    at com.google.gson.stream.JsonReader.peek(JsonReader.java:414) ~[LeadinJobs-executable.jar:na]
    at com.google.gson.JsonParser.parse(JsonParser.java:60) ~[LeadinJobs-executable.jar:na]
    ... 16 common frames omitted

This change ensures that GZipped responses are properly decompressed before reading the response content. I've verified this change no longer causes the above exception.

@basiliscus