Apple Push Notification, PKCS12 in java-apns
I try to send a push notification from a java application to an iphone. there is the source code : PayLoad payLoad = new PayLoad();
payLoad.addAlert("My alert message");
payLoad.addBadge(45);
payLoad.ad开发者_如何学CdSound("default");
PushNotificationManager pushManager = PushNotificationManager.getInstance();
pushManager.addDevice("iPhone", "f4201f5d8278fe39545349d0868a24a3b60ed732");
log.warn("Initializing connectiong with APNS...");
// Connect to APNs
pushManager.initializeConnection(HOST, PORT,
"/etc/Certificates.p12", "password",
SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
Device client = pushManager.getDevice("iPhone");
// Send Push
log.warn("Sending push notification...");
PushNotificationManager.getInstance().sendNotification(client, payLoad);
I receive an exception in the line :
pushManager.initializeConnection(HOST, PORT,
"/etc/Certificates.p12", "password",
SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
Here is the exception :
java.io.IOException: failed to decrypt safe contents entry: java.io.IOException: getSecretKey failed: PBE SecretKeyFactory not available
at com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.engineLoad(Unknown Source)
at java.security.KeyStore.load(Unknown Source)
at com.anthil.apns.service.ExtractFile.main(ExtractFile.java)
Caused by: java.io.IOException: getSecretKey failed: PBE SecretKeyFactory not available at com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.getPBEKey(Unknown Source) ... 3 more Caused by: java.security.NoSuchAlgorithmException: PBE SecretKeyFactory not available at javax.crypto.SecretKeyFactory.(DashoA13*..) at javax.crypto.SecretKeyFactory.getInstance(DashoA13*..) ... 4 more
can any one help me with this ?
I have recently encountered the same exception. It turned out to occur only when I ran my code through Eclipse (version 3.7.0 Indigo), using the new Sun JDK 1.7.0. Running the code either outside of Eclipse, or using a JDK 1.6.x fixed the problem for me.
I had a similar problem that was resolved by removing the '-Djava.ext.dirs' flag from my java command. See: http://www.scottmcmaster365.com/2009/03/perils-of-abusing-javaextdirs-property.html
Btw, from the code you provided, you seem to be using an old version of JavaPNS (1.6?). You might want to upgrade to the latest version (2.0 public, or even the latest 2.1-level build) from http://code.google.com/p/javapns/, as you will get MANY reliability improvements and you will be able to push notifications with a single line of code instead of all these "complicated" steps.
精彩评论