Skip to content

Wrong encoding when emitting events with Apache's HttpClient #181

@gaelrenoux

Description

I've had problems with encoding : non-ASCII characters in events were not encoded correctly on the receiving side. After some investigation, I think there's a problem in the ApacheHttpClientAdapter (in com.snowplowanalytics.snowplow.tracker.http):

    public int doPost(String url, String payload) {
        try {
            HttpPost httpPost = new HttpPost(url);
            httpPost.addHeader("Content-Type", Constants.POST_CONTENT_TYPE);
            StringEntity params = new StringEntity(payload);
            httpPost.setEntity(params);

where Constants.POST_CONTENT_TYPE is "application/json; charset=utf-8"

I did some checking in the Apache HTTP Client. When an entity is defined passing only a String (such as here: new StringEntity(payload)), the default encoding used to convert the String into a bytes array is ISO-8859-1, which contradicts the Content-Type header.

I'll do a PR later today.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:defectBugs or weaknesses. The issue has to contain steps to reproduce.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions