Moqui -发送一个RESTful sendJSONRequest()到远程URL?
如何使用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>发布于 2015-07-14 14:32:58
在Moqui中不需要生成JSON或HTTP客户端代码,有很好的工具可供使用。我首选的JSON工具是Groovy中的类(JsonBuilder或JsonOutput),请参见:
http://docs.groovy-lang.org/latest/html/gapi/groovy/json/package-summary.html
对于HTTP请求,您可以使用StupidWebUtilities.simpleHttpStringRequest()方法,但对于简单、常见的情况,它只是Apache客户端库的一个薄包装器。您也可以直接使用Apache客户端库。
发布于 2015-07-14 02:24:09
看看示例文件夹中的示例,这里也签出了REST示例,但可能对您最有帮助的是Authorize.net的现有应用程序,其中有一个使用XML的远程服务调用的工作示例,因此切换到JSON应该不会太困难。
https://stackoverflow.com/questions/31378950
复制相似问题