0

Moqui - 向远程 URL 发送 RESTful sendJSONRequest()?

我应该如何使用 Moqui 向远程 URL 发送 JSON 请求?

Moqui 中是否存在内置方法,或者我需要做什么?我是否需要直接使用 JsonBuilder 和 JsonSlurper groovy 类、simpleHttpStringRequest() 方法和直接 CURL 语句来编写脚本?(我是 Java 和 Groovy 的初学者。)

例如需要服务:

<service verb="create" noun="RcSupplier">
 <!-- 1. Parse my service's in-parameters and the corresponding remote application parameter field names to needed JSON request body. Also include correct header, authorisation, method, etc. 
 <!-- 2. POST JSON to remote application https://api.xxxxxxxxxxxx.com/api/v1/Suppliers ("Create" Supplier) -->
 <!-- 3. Check response is ok and handle errors --> 
 <!-- 4. GET the Supplier ("find" Supplier) just created on the remote app, to retrieve the primary key (id) that was generated for it by the remote system (either append $filter=code eq 'partyId' or else retrieve all Suppliers as a list to perform our own query) -->
 <!-- 5. Parse the JSON response body received to a map that will be utilised to update my corresponding entity (field: externalId) with the remote primary key value. (note: probably better to use EntityDataLoader to do this later on for check and other functionality?) -->
</service>
4

2 回答 2

1

Moqui 框架中不需要 JSON 生成或 HTTP 客户端代码,有很好的工具可用。我首选的 JSON 工具是 Groovy 中的类(JsonBuilder 或 JsonOutput),请参阅:

http://docs.groovy-lang.org/latest/html/gapi/groovy/json/package-summary.html

对于 HTTP 请求,您可以使用 StupidWebUtilities.simpleHttpStringRequest() 方法,但它只是 Apache HTTP 客户端库的一个简单包装器,用于简单、常见的情况。您也可以直接使用 Apache HTTP 客户端库。

于 2015-07-14T14:32:58.413 回答
0

查看Example 文件夹中的示例,并在此处查看REST 示例,但可能对您最有帮助的是Authorize.net的现有应用程序,其中有一个使用 XML 进行远程服务调用的工作示例,因此切换到 JSON应该不会太难

于 2015-07-14T02:24:09.093 回答