Error in Apple's Amazon SNS Release Tutorial Null Pointer exception

My goal goal is to send push notifications to the iOS app via SNS. I turn to this guide: http://docs.aws.amazon.com/sns/latest/dg/mobile-push-apns.html .

I added AWS to my credentials and added apns to my credentials for my development key, certificate, private key and current input token for my application. When I run the tutorial, I get:

Exception in thread "main" java.lang.NullPointerException at com.amazonaws.sns.samples.tools.AmazonSNSClientWrapper.getValidNotificationAttributes(AmazonSNSClientWrapper.java:162) at com.amazonaws.sns.samples.tools.AmazonSNSClientWrapper.publish(AmazonSNSClientWrapper.java:80) at com.amazonaws.sns.samples.tools.AmazonSNSClientWrapper.demoNotification(AmazonSNSClientWrapper.java:131) at com.amazonaws.sns.samples.mobilepush.SNSMobilePush.demoAppleSandboxAppNotification(SNSMobilePush.java:438) at com.amazonaws.sns.samples.mobilepush.SNSMobilePush.main(SNSMobilePush.java:68) 

At the top of SNSMobilePush.java there is a map called attributesMap. Initially, it has values ​​equal to zero for the Platform.APNS and Platform.APNS_SANDBOX keys. These values ​​never change anywhere during the code and are responsible for causing a null pointer exception. The workbook does not indicate a change in these values.

I have not done anything above or above the instructions for the textbook.

I know that my credentials are correct as I sent a message to my iOS application using the same credentials through the Amazon Management Console.

Can anyone point out

  • if the textbook is incomplete
  • what values ​​related to Platform.APNS_SANDBOX must be met in order to get this working.
  • any hint that will help me solve the problem with this

update I added a getValidNotificationAttributes () check to null, and now I can send push notifications using sns and apns using this tutorial.

+7
amazon-web-services amazon-sns push-notification apple-push-notifications javaapns
source share
1 answer

I managed to get a tutorial by adding null checking to getValidNotificationAttributes () in the AmazonSNSClientWrapper class. I am convinced that this is a flaw in the code that appears when using the APNS_SANDBOX and APNS platforms (and probably also ADM and GCM).

 public static Map<String, MessageAttributeValue> getValidNotificationAttributes( Map<String, MessageAttributeValue> notificationAttributes) { if (notificationAttributes != null) { Map<String, MessageAttributeValue> validAttributes = new HashMap<String, MessageAttributeValue>(); for (Map.Entry<String, MessageAttributeValue> entry : notificationAttributes.entrySet()) { if (!StringUtils.isBlank(entry.getValue().getStringValue())) { validAttributes.put(entry.getKey(), entry.getValue()); } } return validAttributes; } else { return new HashMap<String, MessageAttributeValue>(); } } 

I hope this helps anyone who works through this online tutorial.

+3
source share

All Articles