2015-04-02 81 views
0

我需要得到一个JSON的内容,我需要传递这个JSON到一个Web服务谁将发送推,并重新发送到我的应用程序的JSON格式的响应。在我的应用程序中,如果推送发送成功,我必须对这个响应进行评论,否则必须发送一封电子邮件。对于我使用Postman的客户端应用程序(Google Chrome扩展)。但为了传输,我尝试了很多东西。但我有点困惑,我不知道使用什么组件,我试过这段代码是否正确和足够,或者有什么改变,使我的代码更好?! 需要我连接两个流程?因为我在第二个电话中有一个可变的电子邮件。如果是,我该怎么做。先谢谢你。
注意:我正在使用mule 2.5.0 CE。POST JSON与骡esb

<db:mysql-config name="MySQL_Configuration" host="localhost" port="3306" user="root" database="mulesoft" doc:name="MySQL Configuration"/> 
    <smtp:gmail-connector name="Gmail" validateConnections="true" doc:name="Gmail"/> 


<flow name="flows1Flow1"> 
    <http:inbound-endpoint host="localhost" port="8083" encoding="UTF-8" doc:name="HTTP"/> 
     <json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/> 
     <set-variable variableName="msg" value="#[message.payload.msg]" doc:name="Variable"/> 
     <set-variable variableName="token" value="#[message.payload.token]" doc:name="Variable"/> 
     <db:select config-ref="MySQL_Configuration" doc:name="Database"> 
      <db:parameterized-query><![CDATA[select * from push where token = #[message.payload['token']]]]></db:parameterized-query> 
     </db:select> 
     <foreach doc:name="For Each"> 
      <set-variable variableName="email" value="#[message.payload.email]" doc:name="Variable"/> 
     </foreach> 
     <json:object-to-json-transformer doc:name="Object to JSON"/> 
     <http:outbound-endpoint exchange-pattern="request-response" host="WS.com" port="8080" method="POST" doc:name="HTTP" path="api.php/push/send_test_push"/> 
    <logger message="#[message.payload.token]" level="INFO" doc:name="Logger"/> 
</flow> 


<flow name="flows1Flow2"> 
     <quartz:inbound-endpoint jobName="HTTP-Puller-Scheduler" repeatInterval="1000" responseTimeout="10000" doc:name="Quartz" repeatCount="0"> 
      <quartz:event-generator-job/> 
     </quartz:inbound-endpoint> 
     <http:outbound-endpoint exchange-pattern="request-response" host="WS.com" port="8080" method="GET" doc:name="HTTP" path="api.php/push/send_test_push"/> 
    <json:json-to-object-transformer 
      returnClass="java.lang.Object" doc:name="JSON to Object" /> 
     <choice doc:name="Choice"> 
      <when expression="#[message.payload.success=1]"> 
       <logger message="its ok" level="INFO" doc:name="Logger" /> 
      </when> 
      <otherwise> 
        <set-payload 
         value="Dear Mail Crawler, 
        \n\n No spam to my email, please!" 
         doc:name="Set Payload" /> 
        <smtp:outbound-endpoint host="smtp.gmail.com" 
         port="587" responseTimeout="10000" doc:name="SMTP" connector-ref="Gmail" 
         from="Rajeun" password="pass" subject="Mule Test with Velocity Transformer" 
         to="#[flowVars['email']]" user="mymail%40gmail.com" /> 

      </otherwise> 
</choice> 
</flow> 

回答

0

既然你已经使用在第一流动流可变电子邮件

<set-variable variableName="email" value="#[message.payload.email]" doc:name="Variable"/> 

你不会得到在第二流量值#[flowVars['email']]既然你已经使用了流变量,其范围仅限于一个流。

对于需要会话变量第一流动,而不是像下面这样的流量变量: -

<set-session-variable variableName="email" value="#[message.payload.email]" doc:name="Session Variable"/> 

,并在流2中提取的值,如下所示: -

#[sessionVars['email']] 

UPDATE

以下面的方式在出站中使用url,
例如,如果您的外部网址为http://localhost:8082/getData/retrieve,则在出站时使用以下内容: -

<http:outbound-endpoint exchange-pattern="request-response" method="GET" address="http://localhost:8082/getData/retrieve" contentType="application/json" doc:name="HTTP"/> 
+0

谢谢您的回复和您的帮助。更改我的代码并运行后,我得到这个错误:http://pastebin.com/9dGrrJe9另一个问题,我使用http(GET)恢复WS的响应。有一种方法可以在响应到达后运行get方法。或者如果石英是唯一的解决方案,我如何在响应到达后停止收听。再次感谢你。 – Rajeun 2015-04-03 09:51:57

+0

您使用url的方式是错误的..将完整的url粘贴到http:outbound-endpoint的地址属性中,并从那里删除端口和主机 – 2015-04-03 11:20:30

+0

检查我更新的答案 – 2015-04-03 11:26:18