From 93590870e14413f9a10fc3e607b4eb2800c7eda3 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 23 Oct 2017 12:59:54 +0300 Subject: notifications: mpns encoding --- .../src/main/java/com/juick/components/MPNSClient.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'juick-notifications') diff --git a/juick-notifications/src/main/java/com/juick/components/MPNSClient.java b/juick-notifications/src/main/java/com/juick/components/MPNSClient.java index 646c7f93..21286258 100644 --- a/juick-notifications/src/main/java/com/juick/components/MPNSClient.java +++ b/juick-notifications/src/main/java/com/juick/components/MPNSClient.java @@ -8,6 +8,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.*; +import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.HttpClientErrorException; @@ -17,6 +18,7 @@ import org.springframework.web.util.UriComponentsBuilder; import javax.annotation.PostConstruct; import javax.inject.Inject; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.stream.Collectors; /** @@ -49,6 +51,7 @@ public class MPNSClient { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); wnsService = new RestTemplate(); + wnsService.getMessageConverters().add(new StringHttpMessageConverter(StandardCharsets.UTF_8)); HttpEntity> entity = new HttpEntity<>(form, httpHeaders); ResponseEntity response = wnsService.exchange(url, HttpMethod.POST, entity, String.class); String responseBody = response.getBody(); @@ -67,7 +70,7 @@ public class MPNSClient { void sendNotification(final String url, final String xml) throws IOException { HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.setContentType(MediaType.TEXT_XML); + httpHeaders.setContentType(new MediaType("text", "xml", StandardCharsets.UTF_8)); httpHeaders.set("Authorization", accessToken); httpHeaders.set("X-WNS-Type", "wns/toast"); HttpEntity requestEntity = new HttpEntity<>(xml, httpHeaders); -- cgit v1.2.3