I have a flow in Mule. It contains an HTTP Inbound listening to a Port number and an Address. Now according to the address of the HTTP Inbound I have to route it to another VM.
This part I have done like below :
<flow name="MetaService">
<http:inbound-endpoint address="http://localhost:8000/jcore/meta"
transformer-refs="HttpParams" responseTransformer-refs="JavaObjectToJson">
</http:inbound-endpoint>
<component>
<spring-object bean="MetaServiceBean"/>
</component>
<choice>
<when evaluator="header" expression="INBOUND:http.request.path=/jcore/meta">
<vm:outbound-endpoint path="ToJSON" exchange-pattern="request-response"/>
</when>
<when evaluator="header" expression="INBOUND:http.request.path=/jcore/meta.json">
<vm:outbound-endpoint path="ToJSON" exchange-pattern="request-response"/>
</when>
<when evaluator="header" expression="INBOUND:http.request.path=/jcore/meta.xml">
<vm:outbound-endpoint path="ToXML" exchange-pattern="request-response"/>
</when>
<otherwise>
<message-properties-transformer>
<add-message-property key="http.status" value="404"/>
</message-properties-transformer>
<expression-transformer>
<return-argument evaluator="string"
expression="{"Exception": "Could not Render the Request. URL may be wrong"}"/>
</expression-transformer>
</otherwise>
</choice>
</flow>
What happens is, if there is ".json" OR ".xml" at the end of the Address, then I am routing it to a VM and in case of invalid URL's I am raising a HTTP 404 Error..
But the question is : I have to check the Valid / Invalid URL's at the start of the Flow , and not at the end.. And also I have to route them at the end (acc to URL's as shown)..!!
I can use the choice component at the starting also , but then it would be redundant..!!
Is there any good option..??