简体   繁体   English

Mule ESB:AJAX提供的休息服务

[英]Mule ESB: Rest Service with AJAX

currently I am working with mule esb. 目前,我正在使用Mule esb。 I would like to implement a rest service. 我想提供休息服务。 The inbound of my app is AJAX. 我的应用程序的入站是AJAX。 Here is the flow example that I want: 这是我想要的流程示例:

流

Is it possible? 可能吗? if yes, can you please give me an example about how to do it and the example of the rest class (just a simple class about how to get the payload and pass it to the next element)? 如果是,请给我一个有关如何做的示例以及其余类的示例(只是一个有关如何获取有效负载并将其传递给下一个元素的简单类)? Thanks in advance. 提前致谢。

One way of having a RESTful service in Mule is: 在Mule中拥有RESTful服务的一种方式是:

1) Use http:listener 1)使用http:listener

<http:listener-config name="HTTPListener" host="127.0.0.1" port="8080"/>

2) Exploit regex and choice 2)利用正则表达式和选择

<flow name="restFlow">
<http:listener config-ref="HTTPListener" path="/path*" doc:name="HTTP"/>
<choice doc:name="Choice">
  <when expression="#[regex('/path', message.inboundProperties['http.request.path'])]">
    <json:json-to-object-transformer returnClass="java.util.HashMap" />
    <logger message="INCOMING: #[message.inboundProperties['http.request.path']] PAYLOAD: #[message.payload]" level="INFO"/>
    <set-property propertyName="success" value="true" doc:name="Property"/>      
    <set-payload value="#[new java.util.HashMap()]"/>
    <expression-transformer expression="#[
      message.payload.success=message.outboundProperties.success;
      message.payload]" />
    <json:object-to-json-transformer doc:name="Object to JSON"/>
  </when>
  <otherwise>
    <logger message="UNSUPPORTED" level="INFO"/>
  </otherwise>
</choice>

You should get JSON back. 您应该取回JSON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM