Worklight Push异常:SocketException:远程主机关闭连接

时间:2013-04-10 16:05:34

标签: sockets exception push-notification apple-push-notifications ibm-mobilefirst

我做了Push的所有步骤,现在在调用Push时给出了以下异常。

我正在调用IBM的示例Push代码。我可以在数据库中看到设备ID,令牌,用户ID都存在,因为用户已成功订阅了Push。

[4/10/13 18:27:24:647 AST] 00000044 JavaScriptInt I com.worklight.integration.js.JavaScriptIntegrationLibraryImplementation log Push Called -----> userId:aahad notificationText:ThisismyPushMessage
[4/10/13 18:27:24:663 AST] 00000044 JavaScriptInt I com.worklight.integration.js.JavaScriptIntegrationLibraryImplementation log submitNotification >> userId :: aahad, text :: ThisismyPushMessage
[4/10/13 18:27:24:679 AST] 00000045 ApnsConnectio W com.notnoop.apns.internal.ApnsConnectionImpl sendMessage Failed to send message com.notnoop.apns.EnhancedApnsNotification@6acb1af9... trying again
                                 java.net.SocketException: Connection closed by remote host
    at com.ibm.jsse2.SSLSocketImpl.k(SSLSocketImpl.java:165)
    at com.ibm.jsse2.k.write(k.java:30)
    at java.io.OutputStream.write(OutputStream.java:69)
    at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:161)
    at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46)
    at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:52)
    at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)
    at com.worklight.integration.notification.apns.ApplicationConnection.sendNotification(ApplicationConnection.java:84)
    at com.worklight.integration.notification.apns.APNSMediator.sendNotification(APNSMediator.java:85)
    at com.worklight.integration.notification.Mediator$4.run(Mediator.java:174)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)

从WL服务器机器我可以telnet Apple服务器。

我还需要在网络上查看其他任何内容吗?因为我的客户有非常严格的证券。

这是我正在使用的推送适配器功能代码。

function testNotification(userId ,notificationText){
    WL.Logger.debug("Push Called -----> userId:" + userId + " notificationText:"+notificationText);
    var userSubscription = 
        WL.Server.getUserNotificationSubscription('PushAdapter.PushEventSource', userId);

    if (userSubscription==null){
        return { result: "No subscription found for user :: " + userId };
    }

    WL.Logger.debug("submitNotification >> userId :: " + userId + ", text :: " + notificationText);

    WL.Server.notifyAllDevices(userSubscription, {
        badge: 1,
        sound: "sound.mp3",
        activateButtonLabel: "ClickMe",
        alert: notificationText,
        payload: {
            foo : 'bar'
        }
    });

    return { result: "Notification sent to user :: " + userId };
}

我已经缩小了这个问题。

我在我的本地机器(Windows 7 lenovo笔记本电脑)WL使用码头的消费者工作室上做了演示,它运行良好。我收到了通知。

我发现我正在犯一个错误,即我正在使用带有分发配置文件的开发APNS证书....这意味着WL服务器将向错误的Apple服务器发送请求。

我在笔记本电脑上尝试上面的东西来测试Push演示,而且我也停止了我的防火墙&诺顿杀毒软件在我的个人笔记本电脑上,这样Push工作正常。

现在在客户端,我重新生成了另一个APNS证书,即生产APNS并使用分发配置文件,我正在努力实现这一目标。这次我收到了不同的例外。

[4/11/13 12:36:32:566 AST] 00000046 JavaScriptInt I com.worklight.integration.js.JavaScriptIntegrationLibraryImplementation log Push Called -----> userId:aahad notificationText:This is my First Push Message
[4/11/13 12:36:32:566 AST] 00000046 JavaScriptInt I com.worklight.integration.js.JavaScriptIntegrationLibraryImplementation log submitNotification >> userId :: aahad, text :: This is my First Push Message
[4/11/13 12:36:32:676 AST] 0000003b webcontainer  E com.ibm.ws.webcontainer.internal.WebContainer handleRequest SRVE0255E: A WebGroup/Virtual Host to handle /favicon.ico has not been defined.
[4/11/13 12:36:58:066 AST] 00000045 ApnsConnectio E com.notnoop.apns.internal.ApnsConnectionImpl socket Couldn't connect to APNS server
                                 java.net.ConnectException: Connection timed out: connect
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:381)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:243)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:230)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377)
    at java.net.Socket.connect(Socket.java:539)
    at com.ibm.jsse2.SSLSocketImpl.connect(SSLSocketImpl.java:284)
    at com.ibm.jsse2.SSLSocketImpl.<init>(SSLSocketImpl.java:712)
    at com.ibm.jsse2.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:15)
    at com.notnoop.apns.internal.ApnsConnectionImpl.socket(ApnsConnectionImpl.java:133)
    at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:160)
    at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46)
    at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:52)
    at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)
    at com.worklight.integration.notification.apns.ApplicationConnection.sendNotification(ApplicationConnection.java:84)
    at com.worklight.integration.notification.apns.APNSMediator.sendNotification(APNSMediator.java:85)
    at com.worklight.integration.notification.Mediator$4.run(Mediator.java:174)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:772)

[4/11/13 12:36:58:066 AST] 00000045 ApnsConnectio W com.notnoop.apns.internal.ApnsConnectionImpl sendMessage Failed to send message com.notnoop.apns.EnhancedApnsNotification@4fc0c1a1... trying again
                                 com.notnoop.exceptions.NetworkIOException: java.net.ConnectException: Connection timed out: connect
    at com.notnoop.apns.internal.ApnsConnectionImpl.socket(ApnsConnectionImpl.java:146)
    at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:160)
    at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46)
    at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:52)
    at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)
    at com.worklight.integration.notification.apns.ApplicationConnection.sendNotification(ApplicationConnection.java:84)
    at com.worklight.integration.notification.apns.APNSMediator.sendNotification(APNSMediator.java:85)
    at com.worklight.integration.notification.Mediator$4.run(Mediator.java:174)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:772)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:381)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:243)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:230)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377)
    at java.net.Socket.connect(Socket.java:539)
    at com.ibm.jsse2.SSLSocketImpl.connect(SSLSocketImpl.java:284)
    at com.ibm.jsse2.SSLSocketImpl.<init>(SSLSocketImpl.java:712)
    at com.ibm.jsse2.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:15)
    at com.notnoop.apns.internal.ApnsConnectionImpl.socket(ApnsConnectionImpl.java:133)
    ... 13 more

现在,我们必须了解两件事,请帮忙。

(1)通过查看日志,是否仍然意味着客户端某处存在网络堵塞?

(2)我看到Keychain在显示开发APNS和放大器时有所不同。生产APNS证书。两者都使用相同的私钥。开发apns证书显示App ID“us.com.abc.myApp”作为后期修复.....虽然生产apns证书没有显示它。 ........ 这样好吗?或者它会导致一些问题?.......我尝试重新生成生产APNS证书三次,但每次显示相同的数字而不是APP ID作为后期修复。

感谢

1 个答案:

答案 0 :(得分:1)

问题#1:请参阅此有关APNS和网络访问的Stackoverflow问题:Worklight error when sending push notification

来自Apple technote:

  

整个17.0.0.0/8地址块已分配给Apple,因此您可以   在防火墙规则中指定该范围。

问题2:熟悉APNS的主题see this blog post