Monday, 15 March 2010

javascript - Worklight 6.1 Encrypted Cache error -



javascript - Worklight 6.1 Encrypted Cache error -

i writing code store info worklight encrypted cache. trying encrypt value primary key in local db looks 50005 number , passing write method of encrypted cache running project in web preview environment. error invalid argument value '50005', expected null or 'string'. next code snippet

function setuserid(userid){ wl.encryptedcache.write("user_id",userid, oncompletehandler, onerrorhandler); } function oncompletehandler(status){ console.log("global cache write success."); } function onerrorhandler(status){ console.log("global cache open error."+status); switch(status){ case wl.encryptedcache.error_key_creation_in_progress: console.log("error: key creation in progress"); break; case wl.encryptedcache.error_local_storage_not_supported: console.log("error: local storage not supported"); break; case wl.encryptedcache.error_no_eoc: console.log("error: no eoc"); break; case wl.encryptedcache.error_could_not_generate_key: console.log("error: not generate key"); break; case wl.encryptedcache.error_credentials_mismatch: console.log("error: credentials mismatch"); break; default: console.log("an error has occured. status :: " + status); } }

always @ api documentation before using api call. here's documentation write.

it says:

parameters:

value - mandatory. string. info encrypt. when set null, key removed.

change:

wl.encryptedcache.write("user_id",userid, oncompletehandler, onerrorhandler);

to:

wl.encryptedcache.write("user_id",userid.tostring(), oncompletehandler, onerrorhandler);

you can store strings using api. if want store objects, must utilize json.stringify (object string) , json.parse (string object). if want go string int, can utilize parseint function this: parseint(userid).

alternatively, utilize jsonstore api instead. note it's supported on android , ios (in worklight v6.2 it's supported on wp8 , w8 too). code this:

var collections = { users : { searchfields : {'userid' : 'integer'} } }; var options = { password: '123' }; wl.jsonstore.init(collections, options) .then(function () { homecoming wl.jsonstore.get('users').add({userid: 50005}); }) .then(function () { homecoming wl.jsonstore.get('users').findall();//or .find({userid: 50005}) }) .then(function (results) { wl.logger.debug(results); }) .fail(function () { //handle failure in of api calls above });

there's documentation here jsonstore.

javascript worklight worklight-security

No comments:

Post a Comment