Jonathan Sweetman
Jonathan Sweetman

Reputation: 55

IBM Worklight 6.0 - "Received bad token from client" error occurs frequently

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.

Upvotes: 4

Views: 1689

Answers (2)

Idan Adar
Idan Adar

Reputation: 44516

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"?

Upvotes: 2

Anton
Anton

Reputation: 3166

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

Upvotes: 1

Related Questions