we are programming a small “home device” application as part of our study using Appcelerator Titanium. We programmed the interface in Java, which is connected to our front-end applications with an interface that can receive requests through a SOAP call. Therefore, we used suds.js. Everything works fine with iOS, but nothing happens on Android, and we don’t know why. :-( First of all, we want to give the user authorization to authorize the user. The username and password will be sent to the server server, which will subsequently provide the user token. Everything works fine in iOS, Android seems to have a problem with the following code, which I noticed with various test comments, because comments in this code do not appear in the developer console:
suds.invoke('login', callparams, function(xmlDoc) {
Titanium.API.info("Test after function is called");
var results = xmlDoc.documentElement.getElementsByTagName('return');
Titanium.API.info("another test comment");
Titanium.API.info(results);
if (results && results.length>0) {
var isAdmin = results.item(0).getElementsByTagName('admin');
if(isAdmin.item(0).text == "true") {
Titanium.API.info("isAdmin: true");
Titanium.App.Properties.setBool('isAdmin', true);
} else {
Titanium.API.info("isAdmin: false");
Titanium.App.Properties.setBool('isAdmin', false);
}
var userToken = results.item(0).getElementsByTagName('userToken');
Titanium.API.info("userToken: " + userToken.item(0).text);
Titanium.App.Properties.setString('userToken', userToken.item(0).text);
Titanium.App.Properties.setString('username', username.value);
openWindow('js/menue.js', 'Hauptmenü', true);
} else {
var resultsError = xmlDoc.documentElement.getElementsByTagName('S:Fault');
var errorString = resultsError.item(0).getElementsByTagName('faultstring');
Titanium.API.info("error: " + errorString.item(0).text);
alert(errorString.item(0).text);
}
});
URL- : http://localhost:8888 , . , .
!
,
:
app.js: ( )
checkbox.addEventListener('click', function(e) {
if(Titanium.App.Properties.getBool('loginAuto') == true){
imageUrl = 'images/checkbox_unchecked.png';
Titanium.App.Properties.setBool('loginAuto', false);
Titanium.API.info('Setze loginAuto = false');
} else if(Titanium.App.Properties.getBool('loginAuto') == false){
imageUrl = 'images/checkbox_checked.png';
Titanium.App.Properties.setBool('loginAuto', true);
Titanium.API.info('Setze loginAuto = true');
}
checkbox.image = imageUrl;
});
loginBtn.addEventListener('click', function(e) {
var db_userdata = Titanium.Database.install("db/myHome4.sqlite", 'myHome4');
if(Titanium.App.Properties.getBool('loginAuto') == true){
Titanium.API.info('Speichere Name und Password in der Datenbank.');
db_userdata.execute("DELETE FROM login");
db_userdata.execute("INSERT INTO login (id, name, password) VALUES (1, ?, ?)", username.value, password.value);
Titanium.App.Properties.setString('loginName', username.value);
Titanium.App.Properties.setString('loginPassword', password.value);
} else {
db_userdata.execute("DELETE FROM login");
}
db_userdata.close();
var url = Titanium.App.Properties.getString('url') + '/services?wsdl';
var callparams = {
username: username.value,
password: password.value
};
Titanium.API.info(Titanium.App.Properties.getString('url'));
var suds = new SudsClient({
endpoint: url,
targetNamespace: Titanium.App.Properties.getString('url')
});
Titanium.API.info("TEST1111");
try {
Titanium.API.info("Test before function");
suds.invoke('login', callparams, function(xmlDoc) {
Titanium.API.info("Test after function is called");
var results = xmlDoc.documentElement.getElementsByTagName('return');
Titanium.API.info("another test comment");
Titanium.API.info(results);
if (results && results.length>0) {
var isAdmin = results.item(0).getElementsByTagName('admin');
if(isAdmin.item(0).text == "true") {
Titanium.API.info("isAdmin: true");
Titanium.App.Properties.setBool('isAdmin', true);
} else {
Titanium.API.info("isAdmin: false");
Titanium.App.Properties.setBool('isAdmin', false);
}
var userToken = results.item(0).getElementsByTagName('userToken');
Titanium.API.info("userToken: " + userToken.item(0).text);
Titanium.App.Properties.setString('userToken', userToken.item(0).text);
Titanium.App.Properties.setString('username', username.value);
openWindow('js/menue.js', 'Hauptmenü', true);
} else {
var resultsError = xmlDoc.documentElement.getElementsByTagName('S:Fault');
var errorString = resultsError.item(0).getElementsByTagName('faultstring');
Titanium.API.info("error: " + errorString.item(0).text);
alert(errorString.item(0).text);
}
});
} catch(e) {
alert(e);
Ti.API.error('Error: ' + e);
}
});
Ti.App.addEventListener('eventLogout', function(event)
{
Titanium.App.Properties.removeProperty("username");
Titanium.App.Properties.removeProperty("userToken");
Titanium.App.Properties.removeProperty("isAdmin");
Titanium.API.info("Lösche Einstellungen...");
win2.close();
});
suds.js:
var url = Titanium.App.Properties.getString('url') + '/services?wsdl';
function SudsClient(_options) {
function isBrowserEnvironment() {
try {
if (window && window.navigator) {
return true;
} else {
return false;
}
} catch(e) {
return false;
}
}
function isAppceleratorTitanium() {
try {
if (Titanium) {
return true;
} else {
return false;
}
} catch(e) {
return false;
}
}
function extend(original, extended) {
for (var key in (extended || {})) {
if (original.hasOwnProperty(key)) {
original[key] = extended[key];
}
}
return original;
}
function isArray(obj) {
return Object.prototype.toString.call(obj) == '[object Array]';
}
function getXHR() {
return Titanium.Network.createHTTPClient();
}
function xmlDomFromString(_xml) {
xmlDoc = Titanium.XML.parseString(_xml);
return xmlDoc;
}
function convertToXml(_obj, namespacePrefix) {
var xml = '';
if (isArray(_obj)) {
for (var i = 0; i < _obj.length; i++) {
xml += convertToXml(_obj[i], namespacePrefix);
}
} else {
for (var key in _obj) {
if (namespacePrefix && namespacePrefix.length) {
xml += '<' + namespacePrefix + ':' + key + '>';
} else {
xml += '<'+key+'>';
}
if (isArray(_obj[key]) || (typeof _obj[key] == 'object' && _obj[key] != null)) {
xml += convertToXml(_obj[key]);
}
else {
xml += _obj[key];
}
if (namespacePrefix && namespacePrefix.length) {
xml += '</' + namespacePrefix + ':' + key + '>';
} else {
xml += '</'+key+'>';
}
}
}
return xml;
}
var config = extend({
endpoint:'https://localhost:8888/service',
targetNamespace: 'https://localhost:8888/service?wsdl',
envelopeBegin: '',
envelopeEnd: ''
},_options);
this.invoke = function(_soapAction,_body,_callback) {
var body = _body;
if (typeof body !== 'string') {
body = '<fron:'+_soapAction+'>';
body += convertToXml(_body);
body += '</fron:'+_soapAction+'>';
}
var ebegin = config.envelopeBegin;
config.envelopeBegin = ebegin.replace('PLACEHOLDER', config.targetNamespace);
var soapAction = '';
if (config.targetNamespace.lastIndexOf('/') != config.targetNamespace.length - 1) {
soapAction = config.targetNamespace+'/'+_soapAction;
}
else {
soapAction = config.targetNamespace+_soapAction;
}
var xhr = getXHR();
xhr.onload = function() {
_callback.call(this, xmlDomFromString(this.responseText));
};
xhr.open('POST',config.endpoint);
xhr.setRequestHeader('Content-Type', 'text/xml;charset=UTF-8');
xhr.send(config.envelopeBegin+body+config.envelopeEnd);
Titanium.API.info(config.envelopeBegin+body+config.envelopeEnd);
Titanium.API.info("Test SUDS!");
};
}