thiagolocatelli / parse4j

Java Library to deal with Parse (parse.com) REST API
http://thiagolocatelli.github.io/parse4j
143 stars 117 forks source link

UTF-8 Character error when deploy to tomcat 9 on CentOS #79

Open sang89vh opened 7 years ago

sang89vh commented 7 years ago

I see on class "ParseResponse" at method "getResponseAsString". It will be made a bug when convert data respond to UTF-8 String. My environment is CentOS 6, Tomcat 9, Java 8. And I changed it such as below then it's resolved Thanks!

private String getResponseAsString(HttpResponse httpResponse) {
        String jsonText = null;
        try {
            HttpEntity entity = httpResponse.getEntity();
            jsonText = EntityUtils.toString(entity, HTTP.UTF_8);

        } catch (org.apache.http.ParseException e) {
            LOGGER.error("Error while reading response entity", e);
            throw new IllegalArgumentException("Failed getting Parse Response", e);
        } catch (IOException e) {
            LOGGER.error("Error while reading response entity", e);
            throw new IllegalArgumentException("Failed getting Parse Response", e);
        }
        return jsonText;
        /*
        try {
            BufferedReader r = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
            StringBuilder total = new StringBuilder();
            String line = null;
            while ((line = r.readLine()) != null) {
               total.append(line);
            }
            //r.close();
            return total.toString();
        }
        catch(IOException e) {
            LOGGER.error("Error while reading response entity", e);
            throw new IllegalArgumentException("Failed getting Parse Response", e);
        }
        */

    }