2

我正在使用以下代码向 Apple Notification Server 发送通知。

import javapns.Push;
import javapns.communication.exceptions.CommunicationException;
import javapns.communication.exceptions.KeystoreException;

public class APN 
{
   public static void main(String[] args) {
        try {
            Push.alert("Hello World!", "keystore.p12", "mypassword", false, "myDeviceIdentifier");
        } 
        catch (CommunicationException e) {
           e.printStackTrace();
        } 
        catch (KeystoreException e) {
            e.printStackTrace();
        }
   }
}

我已经包含了文档中指定的所有 jars Javapns
但是,当我执行此代码时,它会引发以下异常。

log4j:WARN No appenders could be found for logger (javapns.notification.Payload).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
javapns.communication.exceptions.CommunicationException: Communication exception:
java.net.ConnectException: Operation timed out
at javapns.communication.ConnectionToAppleServer.getSSLSocket(ConnectionToAppleServer.java:158)
at javapns.notification.PushNotificationManager.initializeConnection(PushNotificationManager.java:106)
at javapns.Push.sendPayload(Push.java:171)
at javapns.Push.alert(Push.java:47)
at com.mydomain.myapp.APN.main(APN.java:12)
Caused by: java.net.ConnectException: Operation timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:570)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:371)
at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:71)
at javapns.communication.ConnectionToAppleServer.getSSLSocket(ConnectionToAppleServer.java:155)
... 4 more

我已经创建了 .p12 证书,并且获得了 64 个字长的设备标识符。

请给我建议解决方案。
任何帮助将不胜感激。

4

1 回答 1

3

关键信息是:

java.net.ConnectException:操作超时

您确定运行此代码的服务器可以在您指定的端口上连接到苹果 apn 服务器吗?

提示:使用 telnet 进行验证。

于 2012-12-19T00:18:58.077 回答