4

I have a Worklight Application with an HTTP adapter which connects to another application in order to retrieve data to be displayed on a mobile device (testing with Android 4.0.4 at the moment).

When the application starts, I invoke three procedures from my HTTP Adapter and display the results from all three procedures.

When I run my application in the browser and Preview it as Common, everything works fine.
The problem occurs when I run the application on an actual phone. Most of the time 1 or 2 of my procedure calls fail and the data does not display, but it seems like one of them (the first one) always seems to work. On rare occasion all 3 procedure calls will retrieve the data, but I am unable to consistently reproduce this scenario.

When a procedure fails, I receive an error in the Worklight Development Server console:

[ERROR ] FWLSE4007E: Received bad token from client. Server token:'null', client token:'b3fuqgdid2701hu855n89pldpk'. [project trunk]

Sometimes, I receive this error instead, but it is much less common:

[ERROR ] FWLSE0203E: Received bad instance Id from client. Server instance Id:'3f9eveddc7br5mq3ll0nq89miu', client instance Id:'ut5m5f01i3bkq5l78m54uq137o'. [project trunk]

The application always attempts to WL.Client.invokeProcedure all procedures, and when the invoke succeeds, my onSuccess function runs, but when the other procedures fail to load their data, the onFailure function never occurs.

My adapter looks like this:

<displayName>Adapter</displayName>
<description>Adapter</description>
<connectivity>
    <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
        <protocol>http</protocol>
        <domain>10.50.22.161</domain>
        <port>9000</port>   
    </connectionPolicy>
    <loadConstraints maxConcurrentConnectionsPerNode="5"/>
</connectivity>

<procedure name="getProcesses" securityTest="securityTest" />
<procedure name="getTasks" securityTest="securityTest" />
<procedure name="metricsList" securityTest="securityTest" />
<procedure name="getMetric" securityTest="securityTest" />
<procedure name="getAllHashTags" securityTest="securityTest" />
<procedure name="getMessages" securityTest="securityTest" />
<procedure name="getMentions" securityTest="securityTest" />
<procedure name="getConversations" securityTest="securityTest" />
<procedure name="getServerTime" securityTest="securityTest" />

When I remove the securityTests from the procedures, the error seems to occur less frequently, but still occurs.

What is the problem here? Or how can I debug the Worklight Server in order to determine the cause?

I am using the Eclipse Worklight plug-in with version 6.0.0.20130701-1413.

Idan Adar
  • 44,156
  • 13
  • 50
  • 89

2 Answers2

2

This sounds very similar to a race condition defect identified not too long ago.

Several possible workarounds:

  1. Make sure to WL.Client.connect before you invoke the adapter procedures
  2. Allow for some delay after the application launches and only then invoke the adapter procedures
  3. You can also try adding this to your JavaScript:

    wl_noDeviceProvisioningChallengeHandler.handleFailure = function() {
        WL.Client.connect();
    };
    
  4. Same as 3 above, but with WL.Client.reloadApp()

Question: in initOptions.js, have you set connectOnStartup to "true" or "false"?

Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • Thanks for replying. I tried the second solution, it did not work, but here is what I found: - When all 3 procedures succeeded the method was not called (obviously) - In some scenarios, the method was only called once, seemingly successfully, but my data still does not fully load - In some other scenarios, the method was called 3 times, the second and third had "Cannot invoke WL.Client.connect while it is already executing." error when attempting to connect. I added a !WL.Client.isConnected() around the connect, but it did not help. I will try the delay now, thank you. – Jonathan Sweetman Jul 19 '13 at 17:23
  • I tried putting a 10 second delay before all my procedure calls, but it also did not work. – Jonathan Sweetman Jul 19 '13 at 19:19
  • Why does one app connects to another app to retrieve data? how do adapters come to play then? adapters request data via the worklight server. – Idan Adar Jul 19 '13 at 19:48
  • @JonathanSweetman, I have added another option (number 1 in the list of workarounds). Please try it. – Idan Adar Jul 21 '13 at 08:08
  • 1
    I solved the problem. The issue was that I had connectOnStartup equal to false in the init, once I changed it to true everything worked. Thanks for your help! – Jonathan Sweetman Jul 22 '13 at 14:35
  • I got the same issue and I changed the option `connectOnStartup=true`but the problem persist, I tried even the solutions provided by Idan Adar but doest fix the issue, any other suggestion ? – ghost rider3 Dec 24 '13 at 16:28
  • Can you please let us know what is the dependency of connectOnStartup with bad token, i do have similar issues and we are able to see this only once a while, can you please eloborate the scenario or behaviour of your app when this issues occurs. – Max Nov 10 '14 at 15:14
1

You must call WL.Client.connect() and wait for it's success callback before invoking your procedures.

Anton
  • 3,166
  • 1
  • 13
  • 12
  • I am seeing this issue on 6.1.0.2 version of worklight can you please confirm if its happening on this version as well. – Max Nov 10 '14 at 14:50