Using Backendless with Appcelerator Titanium

I am trying to use he Backendless Javascript API with Titanium (also Javascript) and am running into an external Javascript library dependency issue with backendless.js. Specifically, the url.js and http.js dependencies stop the compilation process. I tried including those libraries from node.js distribution but that doesn’t work because those libraries have other nested dependencies within node. So I am wondering how others are using backendless.js outside of the node.js context (bootstrap, jquery, angular, etc) to resolve the url.js & http.js dependencies of backendless.js.

Thanks.

Hi Kam,

We looked into the problem you described. The root cause is the library makes a check to determine if it runs in a browser or in the node.js environment. In case of Titanium, the “browser check” fails and the code assumes that it is running in node and requires additional modules (which is wrong). We’re going to make a change in the library to enable smoother support for Titanium. It should take a few days.

Regards,
Mark

Hi Kam,
We’ve just released the new version of the JS-SDK.
The possibility to plug XMLHttpRequest constructor has been added in this version.
Please add next code after initApp function in your app.

Backendless.XMLHttpRequest = function() { return Ti.Network.createHTTPClient(); };

It should resolve your problem. Please, let us know about your result.

Regards, Ilya

Hi Ilya,

I have tried the new JS-SDK. The node library dependency is resolved, however, when I try the login process, I am not able to log in as the process hangs and I get the following error:

[ERROR] : TiHTTPClient: (TiHttpClient-1) [16831,17245] HTTP Error (java.io.IOException): 401 : Unauthorized

[ERROR] : TiHTTPClient: java.io.IOException: 401 : Unauthorized

[ERROR] : TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1227)

[ERROR] : TiHTTPClient: at java.lang.Thread.run(Thread.java:856)

This is regardless of whether I enter the correct or incorrect credentials. I believe testing the error conditions caused some problems and I was no longer able to login after a few successful attempts. Something has gone terribly wrong as I am getting very inconsistent results.

Thanks,
Kam

Hi Kam,
Sorry for the delay.
Please, provide us a minimal example of code to reproduce your issue.
Regards, Ilya

HI Ilya,

The login process is now working however the object retrieval process is returning the following error:



[ERROR] :  TiExceptionHandler: (main) [1,12067] - In libs/backendless.js:854,13
[ERROR] :  TiExceptionHandler: (main) [0,12067] - Message: Uncaught Class name should be specified
[ERROR] :  TiExceptionHandler: (main) [0,12067] - Source:             throw 'Class name should be specified';
[ERROR] :  V8Exception: Exception occurred at libs/backendless.js:854: Uncaught Class name should be specified
[ERROR] :  V8Exception: Class name should be specified

This seems to be an issue with backendless.js and how it interfaces with Titanium as I am using the following syntax as described in the documentation:

Backendless.Persistence.of( constructor-function ).findById( async );

Thanks,
Kam

Hi Kam,
I am glad to hear that you have progressed with login.
As for the new case with the ‘findById’ method, the suggestion is the same - please, provide us some minimal example of code to reproduce the problem.
The issue was not clarified just by the error trace though I have some guess.
I am wondering what does the ‘constructor-function’ variable contain?
It should contain either a string value - name of the table either the constructor function of the data object.
For example, suppose you have a table with name ‘Test’. For retrieving data by id from this table you should use one of the next variants

Backendless.Persistence.of('Test').findById( 'OBJECT-ID', async );

or

function Test () {
//....
}
Backendless.Persistence.of( Test ).findById( 'OBJECT-ID', async );

Also, please pay attention that the first argument of the ‘findById’ method should be string value - an object id.

Regards, Ilya

Hi Ilya,

Thanks for the quick reply. Your suggestion worked! Please consider revising some of your online documentation on Javascript data retrieval to clarify the usage of the ‘constructor-function’.

Unfortunately, I have yet again encountered the problem with login. It seems as if this problem shows up from time to time on the same code fragment. Anyway, I will share the code with you and the stack trace and hopefully you can shed some light on what is going wrong here.

The problem now only happens when invalid credentials are entered for login. Instead of showing the error message specified in the callback function for errors, an exception is thrown. Here is the code:

 
 
 
 
 
 
Backendless.UserService.login( email.value, password.value, true, new Backendless.Async( loginSuccess, backendlessError )); 



And the error callback function:

 
 
 
 
 
 
backendlessError = function(err){ 
 
		loginActivityIndicator.hide(); 
 
		alert('LOGIN ERROR: ' + err.message); 
 
	}; 



Once again, when correct credentials are entered, login executes properly as the success callback function is called. But with the erroneous credentials, the ‘backendlessError’ function is not called probably because the process is interrupted due to the following exception:

 
 
 
 
 
 
[ERROR] : TiHTTPClient: (TiHttpClient-1) [5773,5829] HTTP Error (java.io.IOException): 401 : Unauthorized
 
[ERROR] : TiHTTPClient: java.io.IOException: 401 : Unauthorized 
 
[ERROR] : TiHTTPClient: 	at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1227) 
 
[ERROR] : TiHTTPClient: 	at java.lang.Thread.run(Thread.java:841) 



Thanks,
Kam

Hi Kam,
We’ve already realized the cause of the issue.
Probably it will take a couple of days to fix this problem.
We’ll let you know when it’ll be done.

Regards Ilya

Hi Kam,
We’ve just released the new version of JS-SDK which contains the fix for your problem. Please, update your SDK and try it.

Regards, Ilya