我有一个简单的测试应用程序,我正在决定如何通过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
.
鉴于这种情况,我有一些问题:
/init 调用是
WL.Client.connect()
幕后调用吗?两个服务器调用是否在响应中携带相同的信息?换句话说,/init 调用是否充当 WL.Client.connect() 以确保所有需要 connect() 调用的功能同样可用?我是否由调用 wlClientInit() 直到 /init 调用被终止允许成功调用的“重试机制”来保证
WL.Client.connect()
?有什么方法可以防止 WL.Client.connect() 调用在成功之前失败两次?正如我在控制台中看到的那样,您能否确认设置了默认心跳以防止会话超时?默认的心跳间隔是多少?
@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");
}