From 9f6c1ad11e6d6259a5c10aa95eca169b87c7c3b4 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 16 Jan 2021 10:52:19 +0300 Subject: ActivityPub: do not serialize context twice --- src/main/java/com/juick/SignatureManager.java | 2 +- src/main/java/com/juick/config/ActivityPubConfig.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/juick/SignatureManager.java b/src/main/java/com/juick/SignatureManager.java index fed6c368..35d6215f 100644 --- a/src/main/java/com/juick/SignatureManager.java +++ b/src/main/java/com/juick/SignatureManager.java @@ -87,7 +87,7 @@ public class SignatureManager { requestHeaders.add("Host", host); requestHeaders.add("Digest", digestHeader); requestHeaders.add("Signature", signatureString); - HttpEntity request = new HttpEntity<>(finalContext, requestHeaders); + HttpEntity request = new HttpEntity<>(payload, requestHeaders); logger.info("Sending context to {}: {}", to.getId(), payload); ResponseEntity response = apClient.postForEntity(inbox, request, Void.class); logger.info("Remote response: {}", response.getStatusCodeValue()); diff --git a/src/main/java/com/juick/config/ActivityPubConfig.java b/src/main/java/com/juick/config/ActivityPubConfig.java index e22946fb..661f6276 100644 --- a/src/main/java/com/juick/config/ActivityPubConfig.java +++ b/src/main/java/com/juick/config/ActivityPubConfig.java @@ -29,11 +29,13 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.client.RestTemplate; import javax.inject.Inject; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.util.Collections; @Configuration @@ -69,6 +71,7 @@ public class ActivityPubConfig { } }); restTemplate.getMessageConverters().add(0, mappingJacksonHttpMessageConverter()); + restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8)); restTemplate.setErrorHandler(activityPubClientErrorHandler); restTemplate.setInterceptors(Collections.singletonList( new HeaderRequestInterceptor("Accept", Activity.ACTIVITY_MEDIA_TYPE))); -- cgit v1.2.3