如何在Mule中使用REST API和GET操作实现Callback接口?欢迎使用Mule的任何参考示例
以下是示例代码的步骤(最后说明了一些假设):
src/main/api
中创建RAML映射: #%RAML 0.8
---
title: sample
/YourServiceEndpoint
get:
responses:
200:
body:
application/json:
src/main/app
中创建映射。这根据问题使用GET
(在为用例编写集成测试时,可以用POST
或任何其他REST操作替换): <!-- /api/v1 is defined in the APIKit configuration -->
<flow name="get:/api/v1/YourServiceEndPoint">
<http:inbound-endpoint exchange-pattern="request-response" connector-ref="HTTP_HTTPS" ref="HTTP" doc:name="HTTP"/>
<apikit:router config-ref="APIKitRouter" doc:name="APIkit Router"/>
<exception-strategy ref="Standard_Error_Responses" doc:name="Reference Exception Strategy"/>
<!-- do all other stuff here; for example -->
<when expression="#[payload.containsKey("resultSet1") && payload.get("resultSet1").size() > 0]">
<set-payload value="#[payload.get("resultSet1").get(0)]" doc:name="Set Payload"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</when>
</flow>
connector-ref
要求你的全局配置(很可能在你的项目中定义为global-configuration.xml
)有一个类似于下面的配置片段: <https:connector name="HTTPS" enableCookies="true" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" doc:name="HTTP\HTTPS">
<https:tls-server path="${truststoreLocation}" storePassword="${truststorePassword}"/>
</https:connector>
假设:
Project > Mavenize
。有用的说明:
Callable
界面等的使用。这将使您可以继续前进。