@Test public void mailFeedback_bounce() throws Exception { request.addHeader("x-amz-sns-message-type", "Notification"); String message = q("{" + " 'notificationType':'Bounce'," + " 'bounce':{" + " 'bounceSubType':'General'," + " 'bounceType':'Permanent'," + " 'reportingMTA':'dsn; a8-26.smtp-out.amazonses.com'," + " 'bouncedRecipients':[" + " {" + " 'status':'5.1.1'," + " 'action':'failed'," + " 'diagnosticCode':'smtp; 550 5.1.1 user unknown'," + " 'emailAddress':'bounce@simulator.amazonses.com'" + " }" + " ]," + " 'timestamp':'2014-10-26T15:10:47.544Z'," + " 'feedbackId':'000001494d02704b-70c6bee9-bd31-4e2b-aeb3-2adcc5104d25-000000'" + " }," + " 'mail':{" + " 'timestamp':'2014-10-26T15:10:45.000Z'," + " 'source':'noreply@kaif.io'," + " 'messageId':'000001494d026e8c-49338317-a0e9-4b69-b351-cb2e368778ee-000000'," + " 'destination':[" + " 'bounce@simulator.amazonses.com'" + " ]" + " }" + "}"); request.setContent(toJsonBytes(ImmutableMap.of("Type", "Notification", "MessageId", "cb0b3e1f-01f0-531c-90f5-72d810c7f6a7", "Message", message))); controller.mailFeedback(request); verify(accountService).muteEmail(asList("bounce@simulator.amazonses.com")); }
@RequestMapping(value = "/mail-feedback", method = RequestMethod.POST) public void mailFeedback(HttpServletRequest request) throws IOException { String messageType = Optional.ofNullable(request.getHeader("x-amz-sns-message-type")) .map(Strings::emptyToNull) .orElse(NO_SUCH_FIELD); switch (messageType) { case "SubscriptionConfirmation": handleSubscriptionConfirmation(request); break; case "Notification": handleNotification(request); break; default: logger.warn("receive unknown sns, headers:\n" + dumpHeaders(request) + "\nbody:\n" + inputToString(request.getInputStream())); break; } }
AwsSnsRestController { @RequestMapping(value = "/mail-feedback", method = RequestMethod.POST) public void mailFeedback(HttpServletRequest request) throws IOException { String messageType = Optional.ofNullable(request.getHeader("x-amz-sns-message-type")) .map(Strings::emptyToNull) .orElse(NO_SUCH_FIELD); switch (messageType) { case "SubscriptionConfirmation": handleSubscriptionConfirmation(request); break; case "Notification": handleNotification(request); break; default: logger.warn("receive unknown sns, headers:\n" + dumpHeaders(request) + "\nbody:\n" + inputToString(request.getInputStream())); break; } } }
AwsSnsRestController { @RequestMapping(value = "/mail-feedback", method = RequestMethod.POST) public void mailFeedback(HttpServletRequest request) throws IOException { String messageType = Optional.ofNullable(request.getHeader("x-amz-sns-message-type")) .map(Strings::emptyToNull) .orElse(NO_SUCH_FIELD); switch (messageType) { case "SubscriptionConfirmation": handleSubscriptionConfirmation(request); break; case "Notification": handleNotification(request); break; default: logger.warn("receive unknown sns, headers:\n" + dumpHeaders(request) + "\nbody:\n" + inputToString(request.getInputStream())); break; } } AwsSnsRestController(); @VisibleForTesting  AwsSnsRestController(AccountService accountService); }
AwsSnsRestController { @RequestMapping(value = "/mail-feedback", method = RequestMethod.POST) public void mailFeedback(HttpServletRequest request) throws IOException { String messageType = Optional.ofNullable(request.getHeader("x-amz-sns-message-type")) .map(Strings::emptyToNull) .orElse(NO_SUCH_FIELD); switch (messageType) { case "SubscriptionConfirmation": handleSubscriptionConfirmation(request); break; case "Notification": handleNotification(request); break; default: logger.warn("receive unknown sns, headers:\n" + dumpHeaders(request) + "\nbody:\n" + inputToString(request.getInputStream())); break; } } AwsSnsRestController(); @VisibleForTesting  AwsSnsRestController(AccountService accountService); @RequestMapping(value = "/mail-feedback", method = RequestMethod.POST) void mailFeedback(HttpServletRequest request); }
AwsSnsRestController { @RequestMapping(value = "/mail-feedback", method = RequestMethod.POST) public void mailFeedback(HttpServletRequest request) throws IOException { String messageType = Optional.ofNullable(request.getHeader("x-amz-sns-message-type")) .map(Strings::emptyToNull) .orElse(NO_SUCH_FIELD); switch (messageType) { case "SubscriptionConfirmation": handleSubscriptionConfirmation(request); break; case "Notification": handleNotification(request); break; default: logger.warn("receive unknown sns, headers:\n" + dumpHeaders(request) + "\nbody:\n" + inputToString(request.getInputStream())); break; } } AwsSnsRestController(); @VisibleForTesting  AwsSnsRestController(AccountService accountService); @RequestMapping(value = "/mail-feedback", method = RequestMethod.POST) void mailFeedback(HttpServletRequest request);  }