我正在为苹果开发 Java 推送通知服务,为此我使用了 JavaPNS 2.2。我已使用此站点上提供的教程在 Apple 中创建我的证书并成功运行演示(在 PHP 中)。(我还转换了 .p12、.pem 文件中的证书)。
但是,当我尝试在我的测试类中运行 java 中的简单推送通知时(如 JavaPNS 教程中所述),
public class PushTest {
public static void main(String[] args) {
try {
List<PushedNotification> notifications = Push.alert("Hello World!", "<filename>.p12", "<password>", true, "<devicetoken>");
System.out.println("List of Device: "+notifications);
List<Device> inactiveDevices = Push.feedback("<filename>.p12", "<password>", true);
} catch (CommunicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeystoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我正进入(状态,
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.AppOutputStream.write(Unknown Source)
at java.io.OutputStream.write(Unknown Source)
at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:402)
at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:350)
at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:320)
at javapns.Push.sendPayload(Push.java:177)
at javapns.Push.test(Push.java:132)
at javapns.test.NotificationTest.pushTest(NotificationTest.java:83)
at javapns.test.NotificationTest.main(NotificationTest.java:46)
在eclipse中调试JavaPNS代码后,我知道错误是由于,
java.io.EOFException: SSL peer shut down incorrectly
现在我不明白问题出在哪里,因为我的证书(带有 .PEM 扩展名)适用于 PHP 示例。
如果它在 PHP 中而不是在 Java 中工作,我怀疑它的证书的错误,并且 JavaPNS 站点也没有指定天气,我必须通过keytool
或不导入生成的证书。
谁能帮我解决我的问题?仅供参考:我的系统配置,操作系统:Win 7 Java:jdk1.6.0_05 JavaPNS:2.2