如何检查有效的 URL 并将其路由到 MULE 中流程末尾的 VM?
我在 Mule 有一个流程。它包含侦听端口号和地址的 HTTP 入站。现在,根据 HTTP 入站地址,我必须将其路由到另一个虚拟机。
这部分我已经完成如下:
<flow name="MetaService">
<http:inbound-endpoint address="http://localhost:8000/jcore/meta"
transformer-refs="HttpParams" responseTransformer-refs="JavaObjectToJson">
</http:inbound-endpoint>
<component>
<spring-object bean="MetaServiceBean"/>
</component>
<choice>
<when evaluator="header" expression="INBOUND:http.request.path=/jcore/meta">
<vm:outbound-endpoint path="ToJSON" exchange-pattern="request-response"/>
</when>
<when evaluator="header" expression="INBOUND:http.request.path=/jcore/meta.json">
<vm:outbound-endpoint path="ToJSON" exchange-pattern="request-response"/>
</when>
<when evaluator="header" expression="INBOUND:http.request.path=/jcore/meta.xml">
<vm:outbound-endpoint path="ToXML" exchange-pattern="request-response"/>
</when>
<otherwise>
<message-properties-transformer>
<add-message-property key="http.status" value="404"/>
</message-properties-transformer>
<expression-transformer>
<return-argument evaluator="string"
expression="{"Exception": "Could not Render the Request. URL may be wrong"}"/>
</expression-transformer>
</otherwise>
</choice>
</flow>
发生的情况是,如果地址末尾有“.json”或“.xml”,那么我将路由它到虚拟机,如果 URL 无效,我将引发 HTTP 404 错误。
但问题是:我必须在流程开始时检查有效/无效 URL,而不是在结束时检查。而且我还最后给它们布线(按照如图所示的 URL)..!!
我也可以在开始时使用选择组件,但这样就多余了..!!
有什么好的选择吗..?
I have a flow in Mule. It contains an HTTP Inbound listening to a Port number and an Address. Now according to the address of the HTTP Inbound I have to route it to another VM.
This part I have done like below :
<flow name="MetaService">
<http:inbound-endpoint address="http://localhost:8000/jcore/meta"
transformer-refs="HttpParams" responseTransformer-refs="JavaObjectToJson">
</http:inbound-endpoint>
<component>
<spring-object bean="MetaServiceBean"/>
</component>
<choice>
<when evaluator="header" expression="INBOUND:http.request.path=/jcore/meta">
<vm:outbound-endpoint path="ToJSON" exchange-pattern="request-response"/>
</when>
<when evaluator="header" expression="INBOUND:http.request.path=/jcore/meta.json">
<vm:outbound-endpoint path="ToJSON" exchange-pattern="request-response"/>
</when>
<when evaluator="header" expression="INBOUND:http.request.path=/jcore/meta.xml">
<vm:outbound-endpoint path="ToXML" exchange-pattern="request-response"/>
</when>
<otherwise>
<message-properties-transformer>
<add-message-property key="http.status" value="404"/>
</message-properties-transformer>
<expression-transformer>
<return-argument evaluator="string"
expression="{"Exception": "Could not Render the Request. URL may be wrong"}"/>
</expression-transformer>
</otherwise>
</choice>
</flow>
What happens is, if there is ".json" OR ".xml" at the end of the Address, then I am routing it to a VM and in case of invalid URL's I am raising a HTTP 404 Error..
But the question is : I have to check the Valid / Invalid URL's at the start of the Flow , and not at the end.. And also I have to route them at the end (acc to URL's as shown)..!!
I can use the choice component at the starting also , but then it would be redundant..!!
Is there any good option..??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白为什么起始帖子中提出的解决方案不起作用?
如果您只是将选择从:
更改为
那么这些值应该评估为 true 或 false。
或者我在这里遗漏了什么?
I can't see why the solution presented in the starting post would not work?
If you just change your choices from:
<when evaluator="header" expression="INBOUND:http.request.path=/jcore/meta">
to
<when evaluator="header" expression="INBOUND:http.request.path == /jcore/meta">
then these should evaluate to true or false.
Or Am I missing something here?