我在Mule中有一个流。它包含一个HTTP入站侦听端口号和地址。现在,根据HTTP Inbound的地址,我必须将其路由到另一个VM。
这部分我做了如下:
<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"OR".xml"在地址的末尾,然后我将其路由到VM,如果URL无效,我将引发HTTP 404错误。。
但问题是:我必须检查流开头的有效/无效URL,而不是结尾。。而且我还必须在最后路由它们(根据如图所示的URL)。。!!
我也可以在开始时使用选项组件,但这将是多余的。。!!
有什么好的选择吗。。??
- 在入站HTTP端点之后立即使用消息属性转换器来添加新的调用范围的属性
- 在这个转换器中,使用Groovy表达式根据入站属性"http.request.path"为这个属性指定一个值"json"、"xml"或"error"
- 然后,在您选择的路由器中,只需基于此调用属性进行路由即可
我不明白为什么开始文章中提供的解决方案不起作用?
如果您只是从更改您的选择
<when evaluator="header" expression="INBOUND:http.request.path=/jcore/meta">
至
<when evaluator="header" expression="INBOUND:http.request.path == /jcore/meta">
那么这些应该评估为真或假。
或者我在这里错过了什么?