bitsbuffer
bitsbuffer

Reputation: 555

Apple Push Notification Service using Javapns

I'm using the following code to send notification to the 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();
        }
   }
}

I've included all the jars specified at the documentation of Javapns.
However when I execute this code, it is throwing following exception.

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

I've created the .p12 certificate and I've got the device identifier of 64 words length.

Please, suggest me the solution.
Any help will be appreciated.

Upvotes: 2

Views: 4056

Answers (1)

Bill
Bill

Reputation: 56

the key piece of information is:

java.net.ConnectException: Operation timed out

Are you sure the server running this code can connect to the apple apn server on the port you specified?

Hint: use telnet to verify.

Upvotes: 3

Related Questions