gpt4 book ai didi

mule - 我如何处理 mule Choice 路由器中的 HTTP 路径参数?

转载 作者:行者123 更新时间:2023-12-01 11:38:11 25 4
gpt4 key购买 nike

我正在尝试使用选择路由器来根据路径处理 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 中通配路径?另外,如果继续使用选择路由器,是否有一种好的/简单的方法从路径中提取客户编号?

最佳答案

对于通配符,您可以在 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

关于mule - 我如何处理 mule Choice 路由器中的 HTTP 路径参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25164675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com