0

I have a simple test application where I am deciding how to handle the server connection via WL.Client.connect().

During the application startup no authentication process takes place. Just the standard initialization with initOptions.js (connectOnStartup:false) and then the wlCommonInit() invocation where I have placed the call to the server (WL.Client.connect()) with proper success/failure handlers.

When I test the app with the Mobile Browser Simulator (e.g.: Android environment), I got the following stack trace from the browser console:

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 

It results that the wlClientInit is called 3 times, until the call to /apps/services/api/UnisTestAdapters/android/init gets a response from the server.

In the while, the call to WL.Client.connect() fails twice because Cannot invoke WL.Client.connect while it is already executing. Then after getting the response from the /init call I also get wlclient connect success.

Given this scenario, I have some questions:

  1. Is the /init call a WL.Client.connect() under-the-covers call? Do both the server invocations carry the same information in the response? In other words, does the /init call act as a WL.Client.connect() ensuring that all the features that need a connect() call are likewise available?

  2. Am I guaranteed by the "retry mechanism" that calls the wlClientInit() until the /init call is terminated allowing the successful call to WL.Client.connect()? Is there any way to prevent the WL.Client.connect() call to fail twice before being successful?

  3. Can you confirm, as I see in the console, that there's a default heartbeat set to prevent the session from timing out? What is that default heartbeat interval?


@Daniel Gonzales: here it is the wlCommonInit() code and related handlers:

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");
}
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
Quake
  • 83
  • 1
  • 9

1 Answers1

0

See these two questions (well, their answers) for some explanations that may help.

As for Heartbeat, yes, it is enabled by default and has a default of 20 minutes.

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • Idan, I already saw those posts but they doesn't explained me why I get twice the error "Cannot invoke WL.Client.connect while it is already executing" as if I was issuing several WL.Client.connect() calls. But in wlCommonInit() I only invoke once WL.Client.connect(), so I was wondering if that call went into conflict with the /init call possibly still on the fly. If this is the case, how can I avoid it? Wasn't wlCommonInit() supposed to be called AFTER WL.Client.init() had initialized the WL framework? I am assuming the /init request is related to the WL.Client.init() call, isn't it? Thanks. – Quake Nov 13 '13 at 22:27
  • Idan, I have a similar problem too. When I call InvokeProcedure I get the following `Failed to load resoure: The requested URL was not found on this server.` – satya on rails Apr 02 '14 at 04:49
  • @Quake, if you use connectOnStartup:true, that will account for an additional connect. – Idan Adar Aug 28 '14 at 02:40