3

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?

SteveS
  • 1,008
  • 3
  • 18
  • 32

1 Answers1

5

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

Ryan Carter
  • 11,441
  • 2
  • 20
  • 27
  • Thank you for suggesting the apikit router. Does indeed look like that is what I was really looking for. I am working through the tutorial and it looks like it is going to do what I need. – SteveS Aug 06 '14 at 18:43