0

我在骡子有流量。它包含一个监听端口号和地址的 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="{&quot;Exception&quot;: &quot;Could not Render the Request. URL may be wrong&quot;}"/>
                </expression-transformer>
            </otherwise>
        </choice>
    </flow>

发生的情况是,如果地址末尾有“ .json ”或“ .xml ”,那么我会将其路由到 VM,如果 URL 无效,我将引发 HTTP 404 错误。


但问题是:我必须在 Flow 开始时检查 Valid / Invalid URL,而不是在结尾处。我还必须在最后路由它们(根据 URL 所示)..!!

我也可以在开始时使用选择组件,但是那将是多余的..!!

有什么好的选择..??

4

2 回答 2

1

我不明白为什么开始帖子中提出的解决方案不起作用?

如果你只是改变你的选择:

<when evaluator="header" expression="INBOUND:http.request.path=/jcore/meta">

<when evaluator="header" expression="INBOUND:http.request.path == /jcore/meta">

那么这些应该评估为真或假。

或者我在这里错过了什么?

于 2012-01-18T08:02:45.687 回答
1
  • 在入站 HTTP 端点之后使用 message-properties-transformer 添加新的调用范围属性。
  • 在此转换器中,使用 Groovy 表达式根据入站属性“http.request.path”为该属性赋予“json”、“xml”或“error”的值。
  • 然后在您选择的路由器中,只需将您的路由基于此调用属性。
于 2012-01-13T16:39:14.810 回答