0
votes

I want to check if a URI parameter exists in the URL using Mule 3.8.3 and also need to make sure that inboundProperties is not empty either when using the Choice component in Anypoint Studio 6.2 and Mule 3.8.3.

I have tried:

#[message.inboundProperties.'http.uri.params'.code != empty]

#[org.mule.util.StringUtils.isNotEmpty(message.inboundProperties.'http.uri.params'.code)]

For both I get

org.mule.api.expression.ExpressionRuntimeException: Execution of the expression "org.mule.util.StringUtils.isNotEmpty(message.inboundProperties.'http.query.params'.code)" failed.

Is there any other way to try?

1
let us know if the solution mentioned below worked for you.This might help others visiting this page for same query.And kindly accept the answer if so. - Mahesh_Loya

1 Answers

2
votes

There are two "Expression" in palate.

1.Expression-transformer

Example : <expression-transformer expression="#[message.inboundProperties.'http.uri.params'.param != empty]" doc:name="Expression"/>

2.Expression-component

Example : <expression-component doc:name="Expression"/>

Make sure you use "Expression-transformer" as shown below

Try below flow in Anypoint Studio.It works for me.

<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>

Test above with below url in your browser

http://localhost:8082/testapi/uri/testUriParam/resource

This could be used with Choice component component as well. Try below code :

<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>