Topic
  • 5 replies
  • Latest Post - ‏2012-10-12T17:02:53Z by SystemAdmin
ddougherty
ddougherty
21 Posts

Pinned topic Samples on WAS failing init - Cannot read property 'userInfo' of null

‏2012-09-25T22:26:58Z |
Hi,

I used IM to install WL onto Liberty and then on a WAS8 profile, each has their own databases. I built several of the samples to run /9080/worklight - HellowWorld, Engadget and CityWeather. (I changed the HelloWorld initOptions to connect at startup)

All 3 run on Liberty OK - all 3 fail on WAS. The browser gets an alert that says 'Response cannot be parsed, please contact support.
The responses for Liberty and WAS look the same.

Console window in Chrome:
wlclient init started worklight.js:1083
Request [/worklight/apps/services/api/HelloWorklight/common/init] worklight.js:1083
POST http://dddw520:9080/worklight/apps/services/api/HelloWorklight/common/init 401 (Unauthorized) base.js:889
Request [/worklight/apps/services/api/HelloWorklight/common/init] worklight.js:1083
response [/worklight/apps/services/api/HelloWorklight/common/init] success: /*-secure-
{"gadgetProps":{"ENVIRONMENT":"common"},"userPrefs":{},"userInfo":{"wl_deviceNoProvisioningRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_anonymousUserRealm":{"userId":"eca00b17-4295-4aed-9e46-cc71e2fb5da2","attributes":{},"isUserAuthenticated":1,"displayName":"eca00b17-4295-4aed-9e46-cc71e2fb5da2"},"WorklightConsole":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_deviceAutoProvisioningRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_authenticityRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_antiXSRFRealm":{"userId":"antiXSRF","attributes":{"savedInstanceId":"ogokacr391cq81l963q517a1ct"},"isUserAuthenticated":1,"displayName":"antiXSRF"},"wl_remoteDisableRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"SampleAppRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"WASLTPARealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"myserver":{"userId":"eca00b17-4295-4aed-9e46-cc71e2fb5da2","attributes":{},"isUserAuthenticated":1,"displayName":"eca00b17-4295-4aed-9e46-cc71e2fb5da2"}}}*/ worklight.js:1083
[/worklight/apps/services/api/HelloWorklight/common/init] exception. Cannot read property 'userInfo' of null worklight.js:1083
Uncaught TypeError: Cannot read property 'userInfo' of null wlclient.js:1361

any suggestions?

dave
  • ddougherty
    ddougherty
    21 Posts

    Re: Samples on WAS failing init - Cannot read property 'userInfo' of null

    ‏2012-09-26T15:50:26Z  
    This is the same problem or similar as this thread: http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14884433&tstart=0

    That thread seems to be about the Page Editor preview but the same problem exists in the console on a standalone WAS. That thread mentions using a specific env instead of common, but if I do that in the console I get the same error for android instead of common.

    Request [/worklight/apps/services/api/HelloWorklight/android/init] wlgap.android.js:1285
    response [/worklight/apps/services/api/HelloWorklight/android/init] success: /*-secure-
    {"gadgetProps":{"ENVIRONMENT":"android"},"userPrefs":{},"userInfo":{"wl_deviceNoProvisioningRealm":{"userId":"device","attributes":{"mobileClientData":"com.worklight.core.auth.impl.MobileClientData@1db3d8e"},"isUserAuthenticated":1,"displayName":"device"},"wl_anonymousUserRealm":{"userId":"884117cb-d423-48a4-8a0d-721ebff698e2","attributes":{},"isUserAuthenticated":1,"displayName":"884117cb-d423-48a4-8a0d-721ebff698e2"},"WorklightConsole":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_deviceAutoProvisioningRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_authenticityRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_antiXSRFRealm":{"userId":"antiXSRF","attributes":{"savedInstanceId":"7oqvgd6n95srdu9mvs1heoiv2f"},"isUserAuthenticated":1,"displayName":"antiXSRF"},"wl_remoteDisableRealm":{"userId":"NullLoginModule","attributes":{},"isUserAuthenticated":1,"displayName":"NullLoginModule"},"SampleAppRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"WASLTPARealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"myserver":{"userId":"884117cb-d423-48a4-8a0d-721ebff698e2","attributes":{},"isUserAuthenticated":1,"displayName":"884117cb-d423-48a4-8a0d-721ebff698e2"}}}*/ wlgap.android.js:1285
    [/worklight/apps/services/api/HelloWorklight/android/init] exception. wlgap.android.js:1291
    Uncaught TypeError: Cannot read property 'userInfo' of null
  • ddougherty
    ddougherty
    21 Posts

    Re: Samples on WAS failing init - Cannot read property 'userInfo' of null

    ‏2012-09-26T17:27:32Z  
    Found this workaround to the RPE problem - http://planetlotus.org/profiles/handly-cameron_107097

    Basically going back to the old WL.Client.init in the html, but that does not work either. (Again, this is not a problem on Liberty only WAS.
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Samples on WAS failing init - Cannot read property 'userInfo' of null

    ‏2012-09-26T18:30:47Z  
    Found this workaround to the RPE problem - http://planetlotus.org/profiles/handly-cameron_107097

    Basically going back to the old WL.Client.init in the html, but that does not work either. (Again, this is not a problem on Liberty only WAS.
    Dave,

    Not sure if this helps, but MattThornhill had a similar "Uncaught TypeError: Cannot read property 'userInfo' of null" error reported in this thread that was related to context type:

    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14881906&#14881906

    Barbara Hampson, Manager, IBM Worklight
  • ddougherty
    ddougherty
    21 Posts

    Re: Samples on WAS failing init - Cannot read property 'userInfo' of null

    ‏2012-09-26T19:59:26Z  
    Matts post details the cause of this problem:

    This was being caused by the content-type header not being set on the server side for all worklight API calls after authentication (causing the responseJSON property to be null). As a work-around I have added the following to the if statement in the _getResponseJSON function in common/js/base.js (in the application deployable):

    && !(this.responseText.indexOf("/*-secure") >= 0)

    This will make it treat all responses containing "/*-secure" as JSON. This is a bit of a hack but is working for now until I can find out why the content type is not being set.
    I upgraded to WAS 8004 and this problem has been fixed, and now the samples run.
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Samples on WAS failing init - Cannot read property 'userInfo' of null

    ‏2012-10-12T17:02:53Z  
    Matts post details the cause of this problem:

    This was being caused by the content-type header not being set on the server side for all worklight API calls after authentication (causing the responseJSON property to be null). As a work-around I have added the following to the if statement in the _getResponseJSON function in common/js/base.js (in the application deployable):

    && !(this.responseText.indexOf("/*-secure") >= 0)

    This will make it treat all responses containing "/*-secure" as JSON. This is a bit of a hack but is working for now until I can find out why the content type is not being set.
    I upgraded to WAS 8004 and this problem has been fixed, and now the samples run.
    Update on the 'response cannot be parsed' issue related to content type.

    As mentioned above, this issue occurs when the WAS server is not returning a content type of application/json as the content type of the initialization response. Two workarounds included below from our development teams; either should work. 1) WAS configuration change or 2) javascript change in the app's html

    1) Possible fix for WAS:
    Access the WebSphere admin console
    Go to Servers > Server Types > WebSphere application servers > server_name > Web Container Settings > Web container
    Under Additional Properties select Custom properties
    On the Custom properties page, Click New
    In the Name field, enter com.ibm.ws.webcontainer.invokeflushafterservice
    In the Value field, enter false
    Click OK, then Save
    Restart the server
    2) Javascript workaround

    
    
    /** * Workaround for 5.0.0.3 and earlier 'bug' where worklight client does not handle JSON returned * when the JSON is not specifically stated to be JSON on initialization. Include this after * base.js in your HTML document */   window.WLJSX.Ajax.Response = WLJSX.Class.create(
    { initialize: function(request)
    { this.request = request; var transport  = this.transport  = request.transport, readyState = this.readyState = transport.readyState;   
    
    if ((readyState > 2 && !WLJSX.detectBrowser().isIE) || readyState == 4) 
    { this.status       = this.getStatus(); this.statusText   = this.getStatusText(); this.responseText = WLJSX.String.interpret(transport.responseText); this.headerJSON   = this._getHeaderJSON(); 
    }   
    
    if (readyState == 4) 
    { var xml = transport.responseXML; this.responseXML  = WLJSX.Object.isUndefined(xml) ? 
    
    null : xml; this.responseJSON = this._getResponseJSON(); 
    } 
    },   status:      0,   statusText: 
    '',   getStatus: window.WLJSX.Ajax.Request.prototype.getStatus,   getStatusText: function() 
    { 
    
    try 
    { 
    
    return this.transport.statusText || 
    ''; 
    } 
    
    catch (e) 
    { 
    
    return 
    '' 
    } 
    },   getHeader: window.WLJSX.Ajax.Request.prototype.getHeader,   getAllHeaders: function() 
    { 
    
    try 
    { 
    
    return this.getAllResponseHeaders(); 
    } 
    
    catch (e) 
    { 
    
    return 
    
    null 
    } 
    },   getResponseHeader: function(name) 
    { 
    
    return this.transport.getResponseHeader(name); 
    },   getAllResponseHeaders: function() 
    { 
    
    return this.transport.getAllResponseHeaders(); 
    },   _getHeaderJSON: function() 
    { var json = this.getHeader(
    'X-JSON'); 
    
    if (!json) 
    
    return 
    
    null; json = decodeURIComponent(escape(json)); 
    
    try 
    { 
    
    return Sting.wl.evalJSON(json, this.request.options.sanitizeJSON || !this.request.isSameOrigin()); 
    } 
    
    catch (e) 
    { this.request.dispatchException(e); 
    } 
    },   _getResponseJSON: function() 
    { var options = this.request.options; 
    
    try 
    { 
    
    return WLJSX.String.evalJSON(this.responseText, (options.sanitizeJSON || !this.request.isSameOrigin())); 
    } 
    
    catch (e) 
    { 
    
    if (  !options.evalJSON || (options.evalJSON != 
    'force' &&  (this.getHeader(
    'Content-type') || 
    '').indexOf(
    'application/json') < 0) || WLJSX.String.isBlank(this.responseText)) 
    
    return 
    
    null; 
    
    else this.request.dispatchException(e); 
    } 
    } 
    });
    


    We also opened a defect to look at addressing this to avoid the need for any workaround.

    Barbara Hampson, Manager, IBM Worklight