我正在为苹果开发 Java 推送通知服务,为此我使用了 JavaPNS 2.2 。我已经使用了此 site 上提供的教程在 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
最佳答案
我终于找到了问题的答案
这是证书。问题是,有 2 个证书具有相同的 URL (com.xxx.xxx),因此发生了混淆。
我已经删除了设备未使用的文件,并从设备中使用的文件创建了一个新的 .p12,宾果游戏,它起作用了。
关于JavaPN 抛出 SSLHandshakeException java.io.EOFException : SSL peer shut down incorrectly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11506357/