Reputation: 1030
I am trying to use a choice router to handle HTTP messages based on their path. This works well until I hit the case where the message is being submitted with a PUT method and the trailing part of the path is the customerID. So I have a path similar to this: services/v1/customer/{custNo}. In the choice router I have:
<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>
I have this working using rest and annotated java classes but I would rather keep it simple and in mule components if I can. Is there a way to wildcard the path in the MEL for the router? Also, if keeping with using the choice router, is there a good/simple way of extracting the customer number from the path?
Upvotes: 3
Views: 3035
Reputation: 11606
For the wildcard, you could use the regex function in your MEL expressions: http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+Reference Something like:
<when expression="#[regex('services/v1/users/.*', message.inboundProperties['http.relative.path'])]">
However, I think the apikit and the apikit router might be better suited to your needs as it handles path and method routing and variable templating automatically: http://www.mulesoft.org/documentation/display/current/APIkit+Basic+Anatomy
Or for older versions of Mule maybe the Rest router: http://mulesoft.github.io/mule-module-rest-router/mule/rest-router-config.html
Upvotes: 5