如何检查有效的 URL 并将其路由到 MULE 中流程末尾的 VM?

发布于 2024-12-26 19:09:09 字数 2034 浏览 1 评论 0原文

我在 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="{&quot;Exception&quot;: &quot;Could not Render the Request. URL may be wrong&quot;}"/>
                </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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

御守 2025-01-02 19:09:09
  • 在入站 HTTP 端点之后使用消息属性转换器来添加新的调用范围属性。
  • 在此转换器中,使用 Groovy 表达式根据入站属性“http.request.path”为此属性赋予值“json”、“xml”或“error”。
  • 然后在您选择的路由器中,只需将您的路由基于此调用属性即可。
  • Use a message-properties-transformer right after your inbound HTTP endpoint to add a new invocation-scoped property.
  • In this transformer, use a Groovy expression to give this property a value of "json", "xml" or "error" based on the inbound property "http.request.path".
  • Then in your choice router, just base your routing on this invocation property.
樱花落人离去 2025-01-02 19:09:09

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

如果您只是将选择从:

更改为

那么这些值应该评估为 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文