【发布时间】:2015-04-17 15:17:19
【问题描述】:
我正在尝试从我的原生 android 应用程序中发布一些数据。
本机代码:
WLProcedureInvocationData invocationData = new WLProcedureInvocationData("TaskAdapter", "updateTask");
int taskId = Integer.parseInt(tvTaskId.getText().toString());
String assignedTo = tvAssignedTo.getText().toString();
String address = "";
String description = "";
String latitude = "5.0";
String longitude = "5.0";
String status = "5.0";
String comments = "5.0";
String lastupdate = "5.0";
String userLatitude = "5.0";
String userLongitude = "5.0";
String userLocation = "5.0";
String photoData = "5.0";
Object[] parameters = new Object[]{
taskId,
assignedTo,
description,
address,
latitude,
longitude,
status,
comments,
lastupdate,
userLatitude,
userLongitude,
userLocation,
photoData
};
invocationData.setParameters(parameters);
WLRequestOptions options = new WLRequestOptions();
options.setTimeout(30000);
client.getInstance().invokeProcedure(invocationData, new MyInvokeListener(), options);
适配器代码:
function updateTask(id) {
var input = {
method : 'PUT',
returnedContentType : 'json',
path : '/Api/Task?taskid=' + id
};
return WL.Server.invokeHttp(input);
}
适配器 XML:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed Materials - Property of IBM
5725-I43 (C) Copyright IBM Corp. 2011, 2013. All Rights Reserved.
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
-->
<wl:adapter name="TaskAdapter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wl="http://www.ibm.com/mfp/integration" xmlns:http="http://www.ibm.com/mfp/integration/http">
<displayName>TaskAdapter</displayName>
<description>TaskAdapter</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>testmeternative.vdot.virginia.gov</domain>
<port>80</port>
<connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
<socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
<maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
<!-- Following properties used by adapter's key manager for choosing specific
certificate from key store <sslCertificateAlias></sslCertificateAlias> <sslCertificatePassword></sslCertificatePassword> -->
</connectionPolicy>
</connectivity>
<procedure name="getAllTasks" />
<procedure name="updateTask" />
</wl:adapter>
我不确定我是否以正确的方式发送正文。此外,如何将id(参数)发送到适配器函数。
当我在 Eclipse 中单击 Call Mobile First Adapter 时,它会向我显示过程名称,但下拉菜单中的 REST 调用类型为 GET,我希望它为 PUT。
【问题讨论】:
-
你的问题很混乱。 1)如果要使用“put”,那么问题摘要中的“post”是什么意思? 2)参数对象中的空“”是什么? 3)什么是“id”?
-
嗨 Idan,更正了我的更改。参数对象中的空 "" 是我正在为地址传递一个空字符串。我想在查询字符串中传递 taskid 并将任务对象作为 body 传递。所以我想创建一个适配器函数,它将参数 id 作为任务 id
-
您问题的 Eclipse 部分可能取决于适配器 XML,请告诉我们。乍一看,您传递的任务 ID 很好,您应该能够将任何原始类型作为参数传递。但是,您传递了许多参数,但只希望收到一个。
-
是的,结果只会是成功或失败字符串,它是一种后端测试方法。也添加了我的 XML
-
@user3681378 您使用的是哪个版本的 MobileFirst(6.3 或 7.0)?
标签: ibm-mobilefirst mobilefirst-adapters mobilefirst-server