1

I have below annotation set on my controller but it is not able to receive AWS SNS messages,

@RequestMapping(method = RequestMethod.POST, headers = "Content-Type=text/plain; charset=UTF-8")

SNS message sample is here

I always get 415 Unsupported Media Type. Looks like I am missing some minor thing here.

User0911
  • 1,552
  • 5
  • 22
  • 33
  • I am afraid the problem is that you setup the contenttype as text/plan but aws is sending a different format, maybe JSON or XML probably – cralfaro Jul 10 '17 at 08:38

1 Answers1

2

This what worked for me:

The request body is actually a JSON string (text/plain) so you should accept it as a string and then parse it to a usable structure.

Here is an example.

@RequestMapping(method = RequestMethod.POST, consumes = "text/plain")
void subscribe(@RequestBody String paramsString) {
    Map<String, String> params = new Gson().fromJson(paramsString, new 
HashMap<String, String>().getClass());
    // Use params..
}