Worklight push不适用于生产环境

时间:2014-10-17 18:43:42

标签: push-notification ibm-mobilefirst worklight-adapters worklight-server

我使用Push on Dev服务器开发了应用程序。当我在生产环境中部署项目并从应用程序触发推送发送事件时,我收到错误

"An error was encountered while processing the request from the application.".

请帮我解决这个问题。

PushAdapter.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wl:adapter xmlns:wl="http://www.worklight.com/integration" xmlns:http="http://www.worklight.com/integration/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PushAdapter">

    <displayName>PushAdapter</displayName>
    <description>PushAdapter</description>
    <connectivity>
        <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>http</protocol>
            <domain>cnn.com</domain>
            <port>80</port>         
        </connectionPolicy>
        <loadConstraints maxConcurrentConnectionsPerNode="2"/>
    </connectivity>
    <procedure name="submitNotification" securityTest="wl_unprotected"/>
</wl:adapter>

PushAdapter-impl.js

WL.Server.createEventSource({
    name: 'PushEventSource',
    onDeviceSubscribe: 'deviceSubscribeFunc',
    onDeviceUnsubscribe: 'deviceUnsubscribeFunc',
    securityTest: 'AngularStarter-strong-mobile-securityTest'
});

function deviceSubscribeFunc(userSubscription, deviceSubscription){
    WL.Logger.debug(">> deviceSubscribeFunc");
    WL.Logger.debug(userSubscription);
    WL.Logger.debug(deviceSubscription);
}

function deviceUnsubscribeFunc(userSubscription, deviceSubscription){
    WL.Logger.debug(">> deviceUnsubscribeFunc");
    WL.Logger.debug(userSubscription);
    WL.Logger.debug(deviceSubscription);
}

function submitNotification(userId, notificationText) {
    var userSubscription = WL.Server.getUserNotificationSubscription('PushAdapter.PushEventSource', userId);

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

    var badgeDigit = 1,
        notification = WL.Server.createDefaultNotification(notificationText, badgeDigit, {custom: "data"});

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

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

LogCat信息

10-18 20:52:41.550: D/NONE(1819): Request [http://server/context/apps/services/../../invoke]
10-18 20:52:41.601: D/HttpPostRequestSender(1819): HttpPostRequestSender.run in HttpPostRequestSender.java:46 :: Sending request http://server/context/invoke
10-18 20:52:41.661: D/dalvikvm(1819): GC_FOR_ALLOC freed 674K, 27% free 10121K/13800K, paused 18ms, total 18ms

10-18 20:52:41.711: D/NONE(1819): Request [http://server/context/apps/services/api/ProjectName/android/notifications]
10-18 20:52:41.751: D/HttpPostRequestSender(1819): HttpPostRequestSender.run in HttpPostRequestSender.java:46 :: Sending request http://server/context/apps/services/api/ProjectName/android/notifications
10-18 20:52:41.771: D/push(1819): Push.dispatch in Push.java:350 :: Push.dispatch(): method=WL.Client.Push.__onmessage
10-18 20:52:41.771: D/push(1819): Push.dispatch in Push.java:359 :: Javascript script requests dispatching to WL.Client.Push.__onmessage
10-18 20:52:41.791: D/dalvikvm(1819): GC_FOR_ALLOC freed 510K, 27% free 10116K/13800K, paused 18ms, total 18ms
10-18 20:52:41.801: D/NONE(1819): Request [http://server/context/apps/services/api/ProjectName/android/login]

10-18 20:52:41.831: D/HttpPostRequestSender(1819): HttpPostRequestSender.run in HttpPostRequestSender.java:46 :: Sending request http://server/context/apps/services/api/ProjectName/android/login
10-18 20:52:41.851: D/NONE(1819): Request [http://server/context/apps/services/api/ProjectName/android/query]
10-18 20:52:41.881: D/dalvikvm(1819): GC_FOR_ALLOC freed 496K, 27% free 10130K/13800K, paused 18ms, total 18ms

10-18 20:52:41.901: D/NONE(1819): Clearing notification subscriptions.
10-18 20:52:41.921: D/dalvikvm(1819): GC_FOR_ALLOC freed 162K, 25% free 10474K/13800K, paused 19ms, total 19ms
10-18 20:52:41.921: D/GCMRegistrar(1819): resetting backoff for com.ProjectName
10-18 20:52:41.921: V/GCMRegistrar(1819): Registering app com.ProjectName of senders 1010830861176

10-18 20:52:41.921: D/NONE(1819): Clearing tag notification subscriptions.
10-18 20:52:41.931: D/NONE(1819): Send new server notification token id.
10-18 20:52:41.931: D/NONE(1819): Updating tag notification subscriptions.
10-18 20:52:41.941: D/NONE(1819): response [http://server/context/apps/services/api/ProjectName/android/login] success: /*-secure-
10-18 20:52:41.941: D/NONE(1819): {"wl_directUpdateRealm":{"userId":"null","attributes":{},"isUserAuthenticated":1,"displayName":"null"},"wl_authenticityRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"AdapterAuthRealm":{"userId":"demo","isUserAuthenticated":1,"displayName":"demo"},"WL-Authentication-Success":{"AdapterAuthRealm":{"userId":"demo","isUserAuthenticated":1,"displayName":"demo"}},"wl_remoteDisableRealm":{"userId":"null","attributes":{},"isUserAuthenticated":1,"displayName":"null"},"notificationSubscriptionState":{"tags":["Push.ALL"],"eventSources":[],"token":"APA91bFNbZIblAxjd1ls6ldN_LbwU77-nM3R9LtP7cxAXcU1q4WCM1tthy6p6v7YLWmHqDwC3nNg4TNDkCm9ZVOtJCQGIRySBMf1gWq3nUdLFmX9BSIItxas5l7cYcGMvycPF1cxt58M_s29XxVY9uD7FbDM3IJNGA"},"wl_antiXSRFRealm":{"userId":"nbtk4iv001kpt5rvl5dra6q07v","attributes":{},"isUserAuthenticated":1,"displayName":"nbtk4iv001kpt5rvl5dra6q07v"},"wl_deviceAutoProvisioningRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_deviceNoProvisioningRealm":{"userId":"52318dd3-900b-3a85-8752-fbf53cfec056","attributes":{"mobileClientData":"com.worklight.core.auth.ext.MobileClientData@2a92dd52"},"isUserAuthenticated":1,"displayName":"52318dd3-900b-3a85-8752-fbf53cfec056"},"myserver":{"userId":"a20252a0-954f-46ae-bb55-2984c8fae7b6","attributes":{},"isUserAuthenticated":1,"displayName":"a20252a0-954f-46ae-bb55-2984c8fae7b6"},"wl_anonymousUserRealm":{"userId":"a20252a0-954f-46ae-bb55-2984c8fae7b6","attributes":{},"isUserAuthenticated":1,"displayName":"a20252a0-954f-46ae-bb55-2984c8fae7b6"}}*/

10-18 20:52:41.941: D/NONE(1819): defaultOptions:onSuccess
10-18 20:52:41.981: D/HttpPostRequestSender(1819): HttpPostRequestSender.run in HttpPostRequestSender.java:46 :: Sending request http://server/context/apps/services/api/ProjectName/android/query
10-18 20:52:42.031: D/dalvikvm(1819): GC_FOR_ALLOC freed 401K, 24% free 10584K/13800K, paused 18ms, total 19ms

10-18 20:52:42.171: V/GCMBroadcastReceiver(1819): onReceive: com.google.android.c2dm.intent.REGISTRATION
10-18 20:52:42.171: V/GCMBroadcastReceiver(1819): GCM IntentService class: com.ProjectName.GCMIntentService
10-18 20:52:42.171: V/GCMBaseIntentService(1819): Acquiring wakelock
10-18 20:52:42.181: V/GCMBaseIntentService(1819): Intent service name: GCMIntentService-DynamicSenderIds-2
10-18 20:52:42.181: D/GCMBaseIntentService(1819): handleRegistration: registrationId = APA91bFNbZIblAxjd1ls6ldN_LbwU77-nM3R9LtP7cxAXcU1q4WCM1tthy6p6v7YLWmHqDwC3nNg4TNDkCm9ZVOtJCQGIRySBMf1gWq3nUdLFmX9BSIItxas5l7cYcGMvycPF1cxt58M_s29XxVY9uD7FbDM3IJNGA, error = null, unregistered = null
10-18 20:52:42.181: D/GCMRegistrar(1819): resetting backoff for com.ProjectName
10-18 20:52:42.181: V/GCMRegistrar(1819): Saving regId on app version 20
10-18 20:52:42.191: D/GCMIntentService(1819): GCMIntentService.onRegistered in GCMIntentService.java:75 :: WLGCMIntentService: Registered at the GCM server with registration id APA91bFNbZIblAxjd1ls6ldN_LbwU77-nM3R9LtP7cxAXcU1q4WCM1tthy6p6v7YLWmHqDwC3nNg4TNDkCm9ZVOtJCQGIRySBMf1gWq3nUdLFmX9BSIItxas5l7cYcGMvycPF1cxt58M_s29XxVY9uD7FbDM3IJNGA
10-18 20:52:42.191: V/GCMBaseIntentService(1819): Releasing wakelock

10-18 20:52:42.251: D/CordovaWebViewClient(1819): onPageFinished(file:///android_asset/www/default/index.html#/inbox/index)
10-18 20:52:42.251: D/CordovaActivity(1819): onMessage(onPageFinished,file:///android_asset/www/default/index.html#/inbox/index)
10-18 20:52:42.321: D/NONE(1819): response [http://server/context/apps/services/api/ProjectName/android/query] success: /*-secure-
10-18 20:52:42.321: D/NONE(1819): {"isSuccessful":true,"result":"No subscription found for user :: null"}*/
10-18 20:52:42.321: W/NONE(1819): Event source callback is already registered with alias: myPush
10-18 20:52:44.323: D/NONE(1819): Piggybacking event transmission
10-18 20:52:44.333: D/NONE(1819): Flush called

服务器日志

https://www.dropbox.com/s/2j0efjcxmbw0mfg/52318dd3-900b-3a85-8752-fbf53cfec056-logs-3.json?dl=0

1 个答案:

答案 0 :(得分:0)

在PushAdapter-impl.js / submitNotification中,您向订阅用户发送通知,该用户的userId作为参数传递给适配器(userId)。

检查logcat日志 - 该用户的订阅在Worklight中不存在 - 您可能从未从应用程序调用过WL.Client.subscribe()。