Worklight JavaScript HTTP adapter unable to receive request data - ibm-mobilefirst

I am trying to understand how MFP JSONStore & HTTP adapters work. I downloaded the source code here. I followed the steps to build the app. I also deployed this adapter here. But when I tried to push the dirty data to the adapter, I got noting there. The adapter still logs undefined.
Here is the push function code:
function pushToAdapter(){
alert("pushToAdapter");
try {
WL.JSONStore.get(collectionName).push().then(function (res) {
if(Array.isArray(res) && res.length < 1){ // I changed this to res.length > 1
document.getElementById("resultsDiv").innerHTML = "Documents Pushed Successfuly";
} else {
document.getElementById("resultsDiv").innerHTML = "Failed To Push Documents to Adapter: "+ res[0].errorObject;
}
}).fail(function (errorObject) {
alert(errorObject.msg);
});
} catch (e) {
alert("Failed To Push Documents to Adapter");
}
}
& this is the adapter code:
function pushPeople(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: pushPeople called.');
MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
return;
}
function addPerson(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: addPerson called.');
MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
return;
}
function removePerson(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: removePerson called.');
MFP.Logger.debug('Got data from JSONStore to REMOVE: ' + JSON.stringify(data)); //always undefined
return;
}
Please note that I am using a patched version of cordova-plugin-mfp-jsonstore. It is the same as this version except for lines 5238 (as follows):
resourceRequest = new WLResourceRequest('adapters/' + invocationData.adapter + '/' + invocationData.procedure, WLResourceRequest.POST);
resourceRequest.setHeader('Content-Type','application/x-www-form-urlencoded'); //patched version
resourceRequest.send().then(ipOpts.onSuccess, ipOpts.onFailure);

Looks like the parameters were not being passed as a part of the push request. You can use the jsonstore.js provided here and verify if it solves your problem. This will be officially released in the next iFix.

Related

limitation in the callback function in nodejs redis?

I am not sure if the issue I am having is a limitation in redis itself or in the nodejs 'redis' module implementation.
var redis = require('redis');
var client = redis.createClient(6379,'192.168.200.5');
client.on('error',function (error) {
console.log("** error in connection **");
process.exit(1);
});
client.on('connect',function () {
console.log("** connected **");
client.on('message',function (channel,message) {
if (channel == 'taskqueue') {
console.log(channel + ' --> ' + message);
var params = message.split(' ');
var inputf = params[0];
var outputf = params[1];
var dim = inputf.split('_').slice(-1)[0];
client.rpush('records',message,function (e,reply) {
});
}
});
client.subscribe('taskqueue');
});
From the code snippet above, I tried to do an RPUSH inside an "ON MESSAGE" subscription event. It does not work, and I get a client 'ON ERROR' event, thus, it prints error in connection. What is the correct way to do this?
After further searching, I came across this page https://github.com/phpredis/phpredis/issues/365 which seems to explain the scenario.

Worklight JsonStore advanced find

How to use advanced find in worklight JSONStore using QueryPart?
I have tried the following code but its not working properly, I doubt if I am calling advancedFind correctly.
var query = WL.JSONStore.QueryPart().equal('age', 35);
var collectionName = "people";
WL.JSONStore.get(collectionName).find(query).then(function(arrayResults) {
// if data not present , get the data from DB
if (arrayResults.length == 0) {
} else {
}
}).fail(function(errorObject) {
alert("fail" + errorObject);
// handle failure
});
You are calling the find() method. The one you want to call is advancedFind(). Also, advancedFind receives an array of query parts, not just one query part. Your code should look like this:
var queryPart = WL.JSONStore.QueryPart().equal('age', 35);
var collectionName = "people";
WL.JSONStore.get(collectionName).advancedFind([queryPart]).then(function(arrayResults) {
// if data not present , get the data from DB
if (arrayResults.length == 0) {
} else {
}
}).fail(function(errorObject) {
alert("fail" + errorObject);
// handle failure
});
For future reference, here is the API and some examples on how to use the Javascript JSONStore API.

webrtc: createAnswer works on chrome but fires an error with firefox

function createPeerConnection() {
try {
pc = new RTCPeerConnection(null, pc_constraints);
pc.onicecandidate = handleIceCandidate;
pc.onaddstream = handleRemoteStreamAdded;
pc.onremovestream = handleRemoteStreamRemoved;
console.log('Created RTCPeerConnnection');
} catch (e) {
console.log('Failed to create PeerConnection, exception: ' + e.message);
alert('Cannot create RTCPeerConnection object.');
return;
}
try {
// Reliable Data Channels not yet supported in Chrome
sendChannel = pc.createDataChannel("sendDataChannel",
{reliable: false});
sendChannel.onmessage = handleMessage;
trace('Created send data channel');
} catch (e) {
alert('Failed to create data channel. ' +
'You need Chrome M25 or later with RtpDataChannel enabled');
trace('createDataChannel() failed with exception: ' + e.message);
}
sendChannel.onopen = handleSendChannelStateChange;
sendChannel.onclose = handleSendChannelStateChange;
pc.ondatachannel = gotReceiveChannel;
}
function doAnswer() {
console.log('Sending answer to peer.');
pc.createAnswer(setLocalAndSendMessage, null, sdpConstraints);
}
I got error:
TypeError: Argument 2 of mozRTCPeerConnection.createAnswer is not an object.
The following code should work in Firefox:
function doAnswer() {
console.log('Sending answer to peer.');
pc.createAnswer(setLocalAndSendMessage, handleCreateAnswerError, sdpConstraints);
}
function setLocalAndSendMessage(sessionDescription) {
sessionDescription.sdp = preferOpus(sessionDescription.sdp);
pc.setLocalDescription(sessionDescription);
console.log('setLocalAndSendMessage sending message' , sessionDescription);
sendMessage(sessionDescription);
}
function handleCreateAnswerError(error) {
console.log('createAnswer() error: ', e);
}
The reason why this fails in Firefox can be found in the documentation for createAnswer. The issue is that Firefox won't let you pass null for the error handler. All this requires is that you write your own and then pass it into createAnswer. Don't pass null, you should actually be passing a function (object) to do something with the error.
Sorry for the late response, better late than never!
how about this? Its what the guys # xsockets use...
pc.createAnswer(setLocalAndSendMessage,function (ex) { self.onerror(ex); }, sdpConstraints);

Problems with download link in phonegap android pdf

Someone know how to download an file (pdf) using phonegap for android
I already looked a lot of tutorial but any of them work for me.
THank you.
You will need to make use of the FileTransfer object here: http://docs.phonegap.com/en/3.3.0/cordova_file_file.md.html#FileTransfer.
With this, you will need to call the download method - passing in the file URI, destination and success/error callbacks.
I.e., if I want to download a PDF, you could do so as follows:
var win = function(r) {
console.log("Should not be called.");
}
var fail = function(error) {
// error.code == FileTransferError.ABORT_ERR
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
var ft = new FileTransfer();
ft.download(
'http://www.mydomain.com/mypdfdoc.pdf',
myURI, // you can obtain this via a window.requestFileSystem(...)
function (fileEntry) {
// do something with fileEntry
},
function (error) {
// handle error appropriately
});

WEBRTC Object #<RTCPeerConnection> has no method 'processSignalingMessage'

I have problems with the WebRTC:
I use this code from one example about Video calls.
if (new_connection) {
console.log('New Peer Connection');
var peer_connection = {};
peer_connection.connection_id = msg.from_connection_id;
peer_connection.pc = createPeerConnection(peer_connection.connection_id,
false);
peer_connections.push(peer_connection);
$('#remote').prepend(remoteVideoHtml.replace('remoteVideoId', 'peer' +
peer_connection.connection_id));
}
//Now process the SDP JSON Blob received
for (var i in peer_connections) {
if (peer_connections[i].connection_id == msg.from_connection_id) {
try {
peer_connections[i].pc.processSignalingMessage(msg.data);
}catch (e) {
console.log("Failed to create processSignalingMessage, exception: " + e.message);
}
I need help because I have one problem here.
peer_connections[i].pc.processSignalingMessage(msg.data);
The problem is:
Object #<RTCPeerConnection> has no method 'processSignalingMessage'
I don't know how those functions works and how they are invoqued:
pc.onconnecting = function (msg) {
console.log('onSessionConnecting');
}
pc.onopen = function (msg) {
console.log('onSessionOpened');
}
pc.onaddstream = function (event) {
console.log('onRemoteStreamAdded add the remote peers video stream.');
var url = webkitURL.createObjectURL(event.stream);
$('#peer' + connection_id).attr({
src: url
});
}
I will appreciate any help.
The initial version of WebRTC in Chrome was based on ROAP and it used to have a processSignallingMessage() method. The current version based on JSEP and it has methods like setRometeDescription() or setLocalDescription() to inject the local SDP and the SDP received from other users.
You can still find this implementation in old versions of Chrome or in Bowser.