How do I handle the HTTP path parameter in a mule select router?

I am trying to use a select router to process HTTP messages based on their path. This works well until I got into a case where a message is sent using the PUT method and the final part of the path is the user ID. So I have a path like this: services / v1 / customer / {custNo}. In the router of choice 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 a job using rest and annotated Java classes, but I'd rather keep them simple and in mule components if I can. Is there a way to substitute the path in the MEL for the router? Also, if you are using a select router, is there a good / easy way to extract the client number from the path?

+3


source to share


1 answer


For template, you can use regex function in 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 apikit and apikit router are better suited to your needs as it handles the routing of routes and methods and patterns automatically: http://www.mulesoft.org/documentation/display/current/APIkit+Basic+Anatomy

Or for older versions of Mule maybe Rest router: http://mulesoft.github.io/mule-module-rest-router/mule/rest-router-config.html

+5


source







All Articles