IBM Worklight 5.0.6 - / init vs WL.Client.connect()调用

时间:2013-11-13 15:16:35

标签: ibm-mobilefirst worklight-server worklight-runtime

我有一个简单的测试应用程序,我决定如何通过WL.Client.connect()处理服务器连接。

在应用程序启动期间,不会发生身份验证过程。只需使用initOptions.js(connectOnStartup:false)进行标准初始化,然后使用wlCommonInit()调用我已将调用放入服务器(WL.Client.connect())并使用正确的成功/失败处理程序。

当我使用移动浏览器模拟器测试应用程序时(例如:Android环境),我从浏览器控制台获得了以下堆栈跟踪:

WL.Client.init() passed! wlgap.android.js:1538
wlclient init started wlgap.android.js:1538
before: app init onSuccess wlgap.android.js:1538
Request [/apps/services/api/UnisTestAdapters/android/init] wlgap.android.js:1538
inside wlCommonInit wlgap.android.js:1538
after: app init onSuccess wlgap.android.js:1538
wlclient init success wlgap.android.js:1538
wlclient init started wlgap.android.js:1538
before: app init onSuccess wlgap.android.js:1538
Cannot invoke WL.Client.connect while it is already executing. wlgap.android.js:1544
inside wlCommonInit wlgap.android.js:1538
Cannot invoke WL.Client.connect while it is already executing. wlgap.android.js:1544
inside wlCommonInit wlgap.android.js:1538
after: app init onSuccess wlgap.android.js:1538
wlclient init success wlgap.android.js:1538
Failed to load resource: the server responded with a status of 401 (Unauthorized) http://<myhost>/apps/services/api/UnisTestAdapters/android/init
Request [/apps/services/api/UnisTestAdapters/android/init] wlgap.android.js:1538
response [/apps/services/api/UnisTestAdapters/android/init] success: /*-secure-
{"userPrefs":{},"WL-Authentication-Success":{"wl_remoteDisableRealm":{"userId":"null","attributes":{},"isUserAuthenticated":1,"displayName":"null"},"wl_antiXSRFRealm":{"userId":"2lpeuqgs32jqt15bkbu0hg19j","attributes":{},"isUserAuthenticated":1,"displayName":"2lpeuqgs32jqt15bkbu0hg19j"},"wl_deviceNoProvisioningRealm":{"userId":"previewDummyId","attributes":{"mobileClientData":"com.worklight.core.auth.impl.MobileClientData@15c4c586"},"isUserAuthenticated":1,"displayName":"previewDummyId"},"wl_anonymousUserRealm":{"userId":"a940a5a8-7506-4052-9445-87b8aeeb23f9","attributes":{},"isUserAuthenticated":1,"displayName":"a940a5a8-7506-4052-9445-87b8aeeb23f9"}},"notificationSubscriptionState":{},"gadgetProps":{"ENVIRONMENT":"android"},"userInfo":{"wl_authenticityRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"UnisaluteAuthRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"SampleAppRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_remoteDisableRealm":{"userId":"null","attributes":{},"isUserAuthenticated":1,"displayName":"null"},"wl_antiXSRFRealm":{"userId":"2lpeuqgs32jqt15bkbu0hg19j","attributes":{},"isUserAuthenticated":1,"displayName":"2lpeuqgs32jqt15bkbu0hg19j"},"WorklightConsole":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_deviceAutoProvisioningRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_deviceNoProvisioningRealm":{"userId":"previewDummyId","attributes":{"mobileClientData":"com.worklight.core.auth.impl.MobileClientData@15c4c586"},"isUserAuthenticated":1,"displayName":"previewDummyId"},"myserver":{"userId":"a940a5a8-7506-4052-9445-87b8aeeb23f9","attributes":{},"isUserAuthenticated":1,"displayName":"a940a5a8-7506-4052-9445-87b8aeeb23f9"},"wl_anonymousUserRealm":{"userId":"a940a5a8-7506-4052-9445-87b8aeeb23f9","attributes":{},"isUserAuthenticated":1,"displayName":"a940a5a8-7506-4052-9445-87b8aeeb23f9"}}}*/ wlgap.android.js:1538
wlclient connect success 
Request [/apps/services/api/UnisTestAdapters/android/heartbeat] wlgap.android.js:1538
response [/apps/services/api/UnisTestAdapters/android/heartbeat] success:  wlgap.android.js:1538
Request [/apps/services/api/UnisTestAdapters/android/heartbeat] wlgap.android.js:1538
response [/apps/services/api/UnisTestAdapters/android/heartbeat] success:  wlgap.android.js:1538
Request [/apps/services/api/UnisTestAdapters/android/heartbeat] wlgap.android.js:1538
response [/apps/services/api/UnisTestAdapters/android/heartbeat] success:  wlgap.android.js:1538
Request [/apps/services/api/UnisTestAdapters/android/heartbeat] wlgap.android.js:1538
response [/apps/services/api/UnisTestAdapters/android/heartbeat] success:  wlgap.android.js:1538 

结果是wlClientInit被调用3次,直到对/apps/services/api/UnisTestAdapters/android/init的调用从服务器获得响应。

同时,对WL.Client.connect()的调用因Cannot invoke WL.Client.connect while it is already executing而失败两次。然后在从/ init调用获得响应后,我也得到wlclient connect success

鉴于这种情况,我有一些问题:

  1. / init是否呼叫WL.Client.connect()无效呼叫?服务器调用是否在响应中携带相同的信息?换句话说,/ init调用是否充当WL.Client.connect(),确保所有需要connect()调用的功能同样可用?

  2. 我是否通过调用wlClientInit()的“重试机制”来保证,直到/ init调用终止,允许成功调用WL.Client.connect()?有没有办法阻止WL.Client.connect()调用在成功之前失败两次?

  3. 正如我在控制台中看到的那样,您是否可以确认是否设置了默认心跳以防止会话超时?什么是默认心跳间隔?


  4. @Daniel Gonzales:这里是wlCommonInit()代码及相关处理程序:

    function wlCommonInit(){
        // Common initialization code goes here
        busyind = new WL.BusyIndicator("content");
        $('#SubscribeButton').bind('click', subscribeButtonClicked);
        $('#UnsubscribeButton').bind('click', unsubscribeButtonClicked);    
    
        WL.Client.connect({ onSuccess: connected, 
                    onFailure: notconnected,
                    timeout: 1000
        });
    
        WL.Logger.debug("inside wlCommonInit");
    }
    
    function connected(response){
        alert("connected");
    }
    
    function notconnected(response){
        alert("not connected");
    }
    

1 个答案:

答案 0 :(得分:0)

请参阅这两个问题(以及他们的答案),以获得可能有用的一些解释。

至于Heartbeat,是的,它默认启用并且有a default of 20 minutes