Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========

1.1.1 (2016-10-12)
------------------

* Non-ASCII characters are now correctly encoded as UTF-8 in the request body.
Reported by Julien Guery. GitHub #17.

1.1.0 (2016-10-10)
------------------

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/maxmind/minfraud/WebServiceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.net.*;
import java.util.*;

import static org.apache.http.entity.ContentType.APPLICATION_JSON;

/**
* Client for MaxMind minFraud Score, Insights, and Factors
*/
Expand Down Expand Up @@ -309,8 +311,7 @@ private HttpPost requestFor(Transaction transaction, URL url)

String requestBody = transaction.toJson();

StringEntity input = new StringEntity(requestBody);
input.setContentType("application/json");
StringEntity input = new StringEntity(requestBody, APPLICATION_JSON);

request.setEntity(input);
return request;
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/maxmind/minfraud/WebServiceClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.maxmind.minfraud.exception.*;
import com.maxmind.minfraud.request.Device;
import com.maxmind.minfraud.request.Shipping;
import com.maxmind.minfraud.request.Transaction;
import com.maxmind.minfraud.response.FactorsResponse;
import com.maxmind.minfraud.response.InsightsResponse;
Expand All @@ -14,6 +16,8 @@
import org.junit.runner.RunWith;
import org.skyscreamer.jsonassert.JSONAssert;

import java.net.InetAddress;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.jcabi.matchers.RegexMatchers.matchesPattern;
import static com.maxmind.minfraud.request.RequestTestHelper.*;
Expand Down Expand Up @@ -70,6 +74,23 @@ public void testFullFactorsTransaction() throws Exception {
}
}

@Test
public void testRequestEncoding() throws Exception {
try (WebServiceClient client = createSuccessClient("insights", "{}")) {
Transaction request = new Transaction.Builder(
new Device.Builder(InetAddress.getByName("1.1.1.1")).build()
).shipping(
new Shipping.Builder()
.firstName("Allan dias á s maia")
.build()
).build();
client.insights(request);

verify(postRequestedFor(urlMatching("/minfraud/v2.0/insights"))
.withRequestBody(equalToJson("{\"device\":{\"ip_address\":\"1.1.1.1\"},\"shipping\":{\"first_name\":\"Allan dias á s maia\"}}")));
}
}

@Test
public void test200WithNoBody() throws Exception {
try (WebServiceClient client = createSuccessClient("insights", "")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ public static void verifyRequestFor(String service) throws IOException, URISynta

verify(postRequestedFor(urlMatching("/minfraud/v2.0/" + service))
.withRequestBody(equalToJson(requestBody))
.withHeader("Content-Type", matching("application/json")));
.withHeader("Content-Type", matching("application/json; charset=UTF-8")));
}
}