我在骡子有流量。它包含一个监听端口号和地址的 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 ”或“ .xml ”,那么我会将其路由到 VM,如果 URL 无效,我将引发 HTTP 404 错误。
但问题是:我必须在 Flow 开始时检查 Valid / Invalid URL,而不是在结尾处。我还必须在最后路由它们(根据 URL 所示)..!!
我也可以在开始时使用选择组件,但是那将是多余的..!!
有什么好的选择..??