GH-39: Allow text/plain for SNS Inbound
Fixes GH-39 (https://github.com/spring-projects/spring-integration-aws/issues/39) Amazon SNS HTTP notifications are sent with the `content-type` header as `text/plain`, not `application/json` as it is expected by the `MappingJackson2HttpMessageConverter` by default. *Added `text/plain` as supported content type for SNS inbound notification * Corrections after review
This commit is contained in:
committed by
Artem Bilan
parent
0d52b9d352
commit
97988bdec5
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.aws.inbound;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -28,6 +29,7 @@ import org.springframework.expression.Expression;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.integration.aws.support.AwsHeaders;
|
||||
@@ -64,7 +66,9 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
* <p>
|
||||
* For the convenience on the underlying message flow routing a {@link AwsHeaders#SNS_MESSAGE_TYPE}
|
||||
* header is present.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Kamil Przerwa
|
||||
*/
|
||||
public class SnsInboundChannelAdapter extends HttpRequestHandlingMessagingGateway {
|
||||
|
||||
@@ -89,6 +93,8 @@ public class SnsInboundChannelAdapter extends HttpRequestHandlingMessagingGatewa
|
||||
requestMapping.setMethods(HttpMethod.POST);
|
||||
requestMapping.setHeaders("x-amz-sns-message-type");
|
||||
requestMapping.setPathPatterns(path);
|
||||
this.jackson2HttpMessageConverter.setSupportedMediaTypes(
|
||||
Arrays.asList(MediaType.APPLICATION_JSON_UTF8, MediaType.TEXT_PLAIN));
|
||||
super.setRequestMapping(requestMapping);
|
||||
super.setStatusCodeExpression(new ValueExpression<>(HttpStatus.NO_CONTENT));
|
||||
super.setMessageConverters(
|
||||
|
||||
@@ -54,6 +54,7 @@ import com.amazonaws.services.sns.AmazonSNS;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Kamil Przerwa
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@@ -116,7 +117,7 @@ public class SnsInboundChannelAdapterTests {
|
||||
this.mockMvc.perform(
|
||||
post("/mySampleTopic")
|
||||
.header("x-amz-sns-message-type", "Notification")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.TEXT_PLAIN)
|
||||
.content(StreamUtils.copyToByteArray(this.notificationMessage.getInputStream())))
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
@@ -133,7 +134,7 @@ public class SnsInboundChannelAdapterTests {
|
||||
this.mockMvc.perform(
|
||||
post("/mySampleTopic")
|
||||
.header("x-amz-sns-message-type", "UnsubscribeConfirmation")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.TEXT_PLAIN)
|
||||
.content(StreamUtils.copyToByteArray(this.unsubscribeConfirmation.getInputStream())))
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user