如何在Mule中使用REST API和GET操作实现Callback接口?

问题描述 投票:0回答:1

如何在Mule中使用REST API和GET操作实现Callback接口?欢迎使用Mule的任何参考示例

rest callback mule mule-studio mule-esb
1个回答
0
投票

以下是示例代码的步骤(最后说明了一些假设):

  1. 在项目的src/main/api中创建RAML映射:
      #%RAML 0.8
      ---
      title: sample
      /YourServiceEndpoint
        get:
          responses:
            200:
              body:
                application/json:
  1. 在Mule中使用API​​Kit Router在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(&quot;resultSet1&quot;) &amp;&amp; payload.get(&quot;resultSet1&quot;).size() &gt; 0]">
           <set-payload value="#[payload.get(&quot;resultSet1&quot;).get(0)]" doc:name="Set Payload"/>
           <json:object-to-json-transformer doc:name="Object to JSON"/>
        </when>
    </flow>
  1. 上面的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>

假设:

  1. APIKit Router需要Mulesoft / Salesforce的Enterprise许可证,否则这不起作用。
  2. 代码段路径假设使用Maven。如果您的项目不支持maven,请选择Project > Mavenize
  3. 这只是一个建议,与问题无关。用例表示“巨大的数据负载”,这意味着应该通过体系结构来区别对待 - 您应该使用SFTP而不是HTTP / HTTPS API。

有用的说明:

  1. 应用程序的“帮助”菜单中还有其他示例,用于演示SOAP,Callable界面等的使用。这将使您可以继续前进。
© www.soinside.com 2019 - 2024. All rights reserved.