7
votes

My goal end goal is to send push notifications to an iOS app via SNS. I am stepping through this tutorial: http://docs.aws.amazon.com/sns/latest/dg/mobile-push-apns.html.

I have added in my AWS credentials, and added in the corresponding apns credentials for my development key, certificate, private key, and a current push token for my app. 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. It originally has values set to null for keys Platform.APNS and Platform.APNS_SANDBOX. These values never get changed anywhere during the code and are responsible for causing the null pointer exception. The tutorial does not indicate to change these values.

I did not do anything above or beyond the tutorial instructions.

I know that my credentials are correct as I did send a message to my iOS app using these same credentials via Amazon Management Console.

Can anyone indicated

  • if the tutorial is incomplete
  • what the values associated with Platform.APNS_SANDBOX should be in order to get this working
  • any hint to help me trouble shoot this

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

1
So, part of the problem is that their "getValidNotificationAttributes" method in AmazonSNSClientWrapper.java doesn't do a null check when it starts.CasualT
hi, i have certificate.pem and private key for sending apns notifications to my application. should these be verified before it can be used cos i am unable to send notifications. I followed the aws tutorial. can u help me.Ejaz Ahmed

1 Answers

3
votes

I was able to get the tutorial working by adding a null check in to the getValidNotificationAttributes() in the AmazonSNSClientWrapper class. I am convinced that this is a flaw in the code that is exposed when using Platform APNS_SANDBOX and APNS (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 else who is working through this online tutorial.