1

I am working on an AWS SNS integration in Java using spring-aws library and I have a simple notification mapper like this:

@NotificationMessageMapping
public void handleNotificationMessage(@NotificationSubject String subject,
                                      @NotificationMessage SimplePojo message) throws IOException {
    log.info("Received message {}", message);
}

The problem is that it does not work and I get following exception:

Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Error converting notification message with payload:{"name":"simpleName"}

I can change SimplePojo to String and then do the conversion manually and it will work but the question is whether this is possible to avoid manual conversion and have it done like with SqsListeners where spring handles it under the hood.

What is weird is that when I use local-stack then it works.

Luke
  • 1,236
  • 2
  • 11
  • 16
  • What do you mean by `when I use local-stack then it works.` ? – Neeraj Jain May 11 '18 at 08:16
  • local-stack is a toolkit which allows to simulate aws services like sns. What I meant by this is that publishing to topic on local-stack and receiving a message on a consumer works with automatic deserialization but with aws sns it doesn't – Luke May 11 '18 at 08:40

2 Answers2

1

So the thing was that the message pushed from amazon topic had content-type set to text/plain. Automatic conversion will work when a message have content-type set to application/json

Luke
  • 1,236
  • 2
  • 11
  • 16
0

The answer here from Luke https://stackoverflow.com/a/50345827/4281312 worked for me. If you use command line tool aws-cli, just add this attribute to console command

--message-attributes '{"contentType":{"DataType":"String","StringValue":"application/json"}}' 
Georgee
  • 17
  • 2