【问题标题】:Worklight JavaScript HTTP adapter unable to receive request dataWorklight JavaScript HTTP 适配器无法接收请求数据
【发布时间】:2017-06-01 23:28:44
【问题描述】:

我正在尝试了解 MFP JSONStore 和 HTTP 适配器的工作原理。我下载了源代码here。我按照步骤构建应用程序。我还部署了这个适配器here。但是当我尝试将脏数据推送到适配器时,我注意到了。适配器仍然记录未定义。

这里是推送功能代码:

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");
    }
}

&这是适配器代码:

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;
}

请注意,我使用的是 cordova-plugin-mfp-jsonstore 的补丁版本。与this version 相同,但第 5238 行除外(如下):

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);

【问题讨论】:

  • 我已经尝试了完全相同的步骤,并且应用程序按预期工作。这是我的 Android 项目的link,应用了补丁(设置标题)。 注意:将项目按原样导入 Android Studio 修改服务器端点并运行项目。不要对项目执行任何可能覆盖已应用补丁的cordova操作。如果您仍然遇到问题,您也可以分享您的项目,我可以看看它。
  • 是一样的。适配器中没有接收到数据。这是我在适配器中得到的:MFP.Logger I Adapter: JSONStoreAdapter, procedure: addPerson called. MFP.Logger I Got data from JSONStore to ADD: undefined 我想知道,数据从哪里发送到适配器?我的意思是invocationData.parametersjsonstore.js 中的第 5224 行)从未在任何地方使用! resourceRequest.send() 也是无参数的!这可能是适配器中没有收到任何内容的原因吗?

标签: ibm-mobilefirst cordova-plugins mobilefirst-adapters jsonstore


【解决方案1】:

看起来参数没有作为推送请求的一部分传递。您可以使用here 提供的 jsonstore.js 并验证它是否解决了您的问题。这将在下一个 iFix 中正式发布。

【讨论】:

  • 我认为该修复没有包含在最新版本中,是吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-25
  • 2016-01-03
  • 1970-01-01
  • 2017-12-24
  • 2013-02-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多