【问题标题】:How do I handle an HTTP path parameter in mule Choice router?如何在 mule Choice 路由器中处理 HTTP 路径参数?
【发布时间】:2014-08-06 23:55:26
【问题描述】:

我正在尝试使用选择路由器根据其路径处理 HTTP 消息。这很有效,直到我遇到使用 PUT 方法提交消息并且路径的尾随部分是 customerID 的情况。所以我有一个类似这样的路径:services/v1/customer/{custNo}。在我的选择路由器中:

   <choice doc:name="Route Message By Path">
        <when expression="message.inboundProperties['http.relative.path'] == 'services/v1/users'">
            <flow-ref name="NewUser" doc:name="New User"/>
        </when>
        <when expression="message.inboundProperties['http.relative.path'] == 'services/v1/users/{userID}'">
            <flow-ref name="UpdateUser" doc:name="Update User"/>
        </when>
        <when expression="message.inboundProperties['http.relative.path'] == 'services/v1/emails'">
            <flow-ref name="CaptureEmail" doc:name="Capture Email"/>
        </when>
        <when expression="message.inboundProperties['http.relative.path'] == 'services/v1/taxes'">
            <flow-ref name="Taxes" doc:name="Taxes"/>
        </when>
        <otherwise>
            <logger message="The path submitted is unknown. Submitted path is: #[message.inboundProperties['http.relative.path']]" level="INFO" doc:name="Unknown path"/>
            <set-payload value="The path submitted is unknown. Submitted path is: #[message.inboundProperties['http.relative.path']]" doc:name="Set Payload"/>
            <http:response-builder status="500" contentType="text/plain" doc:name="HTTP Response Builder"/>

        </otherwise>
    </choice>

我使用 rest 和带注释的 java 类来完成这项工作,但如果可以的话,我宁愿保持简单并在 mule 组件中。有没有办法在路由器的 MEL 中通配路径?另外,如果继续使用选择路由器,是否有一种从路径中提取客户编号的好/简单的方法?

【问题讨论】:

    标签: mule mule-el


    【解决方案1】:

    对于通配符,您可以在 MEL 表达式中使用正则表达式函数:http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+Reference 比如:

    <when expression="#[regex('services/v1/users/.*', message.inboundProperties['http.relative.path'])]">
    

    但是,我认为 apikit 和 apikit 路由器可能更适合您的需求,因为它会自动处理路径和方法路由以及变量模板:http://www.mulesoft.org/documentation/display/current/APIkit+Basic+Anatomy

    或者对于旧版本的 Mule,可能是 Rest 路由器:http://mulesoft.github.io/mule-module-rest-router/mule/rest-router-config.html

    【讨论】:

    • 感谢您推荐 apikit 路由器。看起来确实是我真正想要的。我正在学习本教程,看起来它可以满足我的需要。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-22
    • 2022-11-28
    • 1970-01-01
    相关资源
    最近更新 更多