我试图将会话变量集中的值访问到另一个流
代码:
<flow name="test" doc:name="test" >
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete" connector-ref="" transformer-refs="transform" doc:name="HTTP">
</http:inbound-endpoint>
<set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/>
<set-session-variable variableName="message" value="test" doc:name="Set Message ID"/>
<http:outbound-endpoint host="teste.local" path="newlocation/autocomplete?#[groovy:return req.toString();]" port="8080" user="login" password="1234" exchange-pattern="request-response" doc:name="HTTP">
</http:outbound-endpoint>
</flow>另一个试图打印它的流程:
<flow name="test2" doc:name="test2" >
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete2" connector-ref="" transformer-refs="transform" doc:name="HTTP">
</http:inbound-endpoint>
<set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/>
<logger message="#[sessionVars.message]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint host="teste.local" path="newlocation/autocomplete?#[groovy:return req.toString();]" port="8080" user="login" password="1234" exchange-pattern="request-response" doc:name="HTTP">
</http:outbound-endpoint>
</flow>但是有一个错误表示,即使当我第一次尝试访问第一个url它们时,也没有将变量设置到该流中,我会将它们更改为seccond,在那里它希望有会话。
->骡子3.4版
发布于 2014-07-08 14:29:32
会话变量需要从一个流传递到另一个流。它们在事件上被序列化和反序列化。您正在第一个流中设置它,并调用/autocomplete,但是它所读取的流正在侦听/autocomplete2。
您不能在/autocomplete2之后单独单击/autocomplete,并期望会话变量在设置为不同事件时存在。如果您希望在单独的流调用之间存储状态,请查看mule对象存储模块。
http://mulesoft.github.io/mule-module-objectstore/mule/objectstore-config.html
关于Mule对象存储的信息如下:
http://www.mulesoft.org/documentation/display/current/Mule+Object+Stores
这里有一些示例配置:
https://github.com/mulesoft/mule-module-objectstore/blob/master/src/test/resources/mule-config.xml
发布于 2014-07-08 15:28:28
您的流量如下:-
<flow name="test" doc:name="test" >
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete" doc:name="HTTP">
</http:inbound-endpoint>
<set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/>
<set-session-variable variableName="message" value="test" doc:name="Set Message ID"/>
<logger message="Done #[sessionVars.message]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:8081/services/autocomplete2" doc:name="HTTP"/>
</flow>
<flow name="test2" doc:name="test2" >
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete2" doc:name="HTTP">
</http:inbound-endpoint>
<set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/>
<logger message="#[sessionVars.message] #[sessionVars['message']] " level="INFO" doc:name="Logger"/>
</flow>https://stackoverflow.com/questions/24634159
复制相似问题