我如何找到 Mule 中是否存在 URI 参数?
How can I find if URI parameter exists in Mule?
我想使用 Mule 3.8.3 检查 URL 中是否存在 URI 参数,并且还需要确保在 Anypoint Studio 6.2 和 Mule 3.8 中使用 Choice 组件时 inboundProperties 不为空.3.
我试过:
#[message.inboundProperties.'http.uri.params'.code != empty]
#[org.mule.util.StringUtils.isNotEmpty(message.inboundProperties.'http.uri.params'.code)]
两者我都得到
org.mule.api.expression.ExpressionRuntimeException: Execution of the
expression
"org.mule.util.StringUtils.isNotEmpty(message.inboundProperties.'http.query.params'.code)"
failed.
还有其他方法可以试试吗?
上颚有两个"Expression"
1.表达式转换器
Example : <expression-transformer expression="#[message.inboundProperties.'http.uri.params'.param != empty]" doc:name="Expression"/>
2.表达式组件
Example : <expression-component doc:name="Expression"/>
确保使用“表达式转换器”,如下所示
在 Anypoint 中尝试以下流程 Studio.It 适合我。
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8082" basePath="/testapi" doc:name="HTTP Listener Configuration"/>
<flow name="uri">
<http:listener path="uri/{param}/resource" config-ref="HTTP_Listener_Configuration" doc:name="HTTP"/>
<expression-transformer expression="#[message.inboundProperties.'http.uri.params'.param != empty]" doc:name="Expression"/>
<object-to-string-transformer doc:name="Object to String"/>
<set-payload value="#[payload]" doc:name="Set Payload"/>
</flow>
在您的浏览器中 url 下面测试上面的内容
http://localhost:8082/testapi/uri/testUriParam/resource
这也可以与 选择组件 组件一起使用。
试试下面的代码:
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8082" basePath="/testapi" doc:name="HTTP Listener Configuration"/>
<flow name="uri">
<http:listener path="uri/{param}/resource" config-ref="HTTP_Listener_Configuration" doc:name="HTTP"/>
<choice doc:name="Choice">
<when expression="#[message.inboundProperties.'http.uri.params'.param != empty]">
<logger message="Found URI Param" level="INFO" doc:name="Logger"/>
<set-payload value="Found URI Param" doc:name="Set Payload"/>
</when>
<otherwise>
<logger level="INFO" doc:name="Logger" message="URI Param not found"/>
<set-payload value="URI Param not found" doc:name="Set Payload"/>
</otherwise>
</choice>
</flow>
我想使用 Mule 3.8.3 检查 URL 中是否存在 URI 参数,并且还需要确保在 Anypoint Studio 6.2 和 Mule 3.8 中使用 Choice 组件时 inboundProperties 不为空.3.
我试过:
#[message.inboundProperties.'http.uri.params'.code != empty]
#[org.mule.util.StringUtils.isNotEmpty(message.inboundProperties.'http.uri.params'.code)]
两者我都得到
org.mule.api.expression.ExpressionRuntimeException: Execution of the expression "org.mule.util.StringUtils.isNotEmpty(message.inboundProperties.'http.query.params'.code)" failed.
还有其他方法可以试试吗?
上颚有两个"Expression"
1.表达式转换器
Example : <expression-transformer expression="#[message.inboundProperties.'http.uri.params'.param != empty]" doc:name="Expression"/>
2.表达式组件
Example : <expression-component doc:name="Expression"/>
确保使用“表达式转换器”,如下所示
在 Anypoint 中尝试以下流程 Studio.It 适合我。
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8082" basePath="/testapi" doc:name="HTTP Listener Configuration"/>
<flow name="uri">
<http:listener path="uri/{param}/resource" config-ref="HTTP_Listener_Configuration" doc:name="HTTP"/>
<expression-transformer expression="#[message.inboundProperties.'http.uri.params'.param != empty]" doc:name="Expression"/>
<object-to-string-transformer doc:name="Object to String"/>
<set-payload value="#[payload]" doc:name="Set Payload"/>
</flow>
在您的浏览器中 url 下面测试上面的内容
http://localhost:8082/testapi/uri/testUriParam/resource
这也可以与 选择组件 组件一起使用。 试试下面的代码:
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8082" basePath="/testapi" doc:name="HTTP Listener Configuration"/>
<flow name="uri">
<http:listener path="uri/{param}/resource" config-ref="HTTP_Listener_Configuration" doc:name="HTTP"/>
<choice doc:name="Choice">
<when expression="#[message.inboundProperties.'http.uri.params'.param != empty]">
<logger message="Found URI Param" level="INFO" doc:name="Logger"/>
<set-payload value="Found URI Param" doc:name="Set Payload"/>
</when>
<otherwise>
<logger level="INFO" doc:name="Logger" message="URI Param not found"/>
<set-payload value="URI Param not found" doc:name="Set Payload"/>
</otherwise>
</choice>
</flow>