JavaPNS - 从笔记本电脑而不是从服务器工作得很好?

时间:2012-04-06 15:51:47

标签: java apple-push-notifications

我一直在冲我的脑袋一段时间,我希望有人可以帮忙吗? 我有一些JavaPNS代码在从我的本地机器运行时可以很好地推送到我的设备,但是,当我将代码复制到我的服务器时,一切运行正常,没有错误,但我从未在设备上收到警报? 检查我的服务器上的日志与我的本地方框相比,我发现我从未在服务器上收到刷新消息,我正在使用带有30个线程的JavaPNS队列。在这两种情况下,本地机箱和服务器,我发送的警报少于30个。

public class PushWorker 
{
private PushQueue queue = null;

public PushWorker(File keystore, String password, boolean production) throws KeystoreException
{
    BasicConfigurator.configure();
    int threads = 30;
    this.queue = Push.queue(keystore, password, production, threads);
    queue.start();
}

public void push(String message, String sound, String token, String eventId) throws JSONException
{
    BasicDevice bd = new BasicDevice();
    bd.setToken(token);

    PushNotificationPayload payload = PushNotificationPayload.complex();
    payload.addAlert(message);
    payload.addSound(sound);
    payload.addCustomDictionary("eid", eventId);

    push(payload, bd);
}

private void push(Payload payload, Device device)
{
    queue.add(payload, device);
}
}

---- BELOW是我本地方框中的同步消息--------------

4872 [JavaPNS grouped notification thread in QUEUE mode] DEBUG javapns.notification.PushNotificationManager  - Flushing
4872 [JavaPNS grouped notification thread in QUEUE mode] DEBUG javapns.notification.PushNotificationManager  - At this point, the entire 139-bytes message has been streamed out successfully through the SSL connection
4872 [JavaPNS grouped notification thread in QUEUE mode] DEBUG javapns.notification.PushNotificationManager  - Notification sent on first attempt

我可以以某种方式从队列强制刷新吗?

----------------------下面是服务器JavaPNS日志记录------------------- ----

0 [JavaPNS grouped notification thread in QUEUE mode] DEBUG javapns.communication.ConnectionToAppleServer  - Creating SSLSocketFactory
16 [JavaPNS grouped notification thread in QUEUE mode] DEBUG javapns.communication.ConnectionToAppleServer  - Creating SSLSocketFactory
49 [JavaPNS grouped notification thread in QUEUE mode] DEBUG javapns.communication.ConnectionToAppleServer  - Creating SSLSocket to gateway.sandbox.push.apple.com:2195
49 [JavaPNS grouped notification thread in QUEUE mode] DEBUG javapns.communication.ConnectionToAppleServer  - Creating SSLSocket to gateway.sandbox.push.apple.com:2195
177 [JavaPNS grouped notification thread in QUEUE mode] DEBUG javapns.notification.PushNotificationManager  - Initialized Connection to Host: [gateway.sandbox.push.apple.com] Port: [2195]: 5117f31e[SSL_NULL_WITH_NULL_NULL: Socket[addr=gateway.sandbox.push.apple.com/17.172.233.65,port=2195,localport=56015]]
...
...

DEBUG javapns.notification.Payload  - Adding alert [blah, blah my alert]
14767 [main] DEBUG javapns.notification.Payload  - Adding sound [default]
14767 [main] DEBUG javapns.notification.Payload  - Adding custom Dictionary [eid] = [193790]
14776 [JavaPNS grouped notification thread in QUEUE mode] DEBUG javapns.notification.PushNotificationManager  - Building Raw message from deviceToken and payload
14776 [JavaPNS grouped notification thread in QUEUE mode] DEBUG javapns.notification.PushNotificationManager  - Built raw message ID 16777217 of total length 135
14777 [JavaPNS grouped notification thread in QUEUE mode] DEBUG javapns.notification.PushNotificationManager  - Attempting to send notification: {"aps":{"sound":"default","alert":"blah, blah my alert"},"eid":"193790"}
14777 [JavaPNS grouped notification thread in QUEUE mode] DEBUG javapns.notification.PushNotificationManager  -   to device: [my device number]

就是这样,没有冲洗......

1 个答案:

答案 0 :(得分:0)

您是否在服务器或其他防火墙设备上配置了iptables?

  • 可能需要允许端口2195。

尝试使用telnet进行测试:

$ telnet gateway.sandbox.push.apple.com 2195

您是否启用了SELinux?检查以下设置:

$ getsebool -a | grep httpd

httpd_can_network_connect - > ?

确保它已开启。

您是否查看过javapns repo网站上的文档?

让我们知道它是怎么回事。

比尔