In Mule, currently I am using a custom transformer "JavaObjectToJSON" (as a Response Transformer) to convert a POJO to JSON i.e. my component class returns a Java Object (List or HashMap) and this transformer converts it into JSON and returns the result.
My code is like :
<flow name="OfferingDetails">
<http:inbound-endpoint address="http://localhost:1212/jcore/offering/details"
transformer-refs="HttpParams" responseTransformer-refs="JavaObjectToJSON">
</http:inbound-endpoint>
<component class="main.java.com.raman.jcore.OfferingDetails"/>
</flow>
Now Suppose I want to return the result in XML. For this i can use another custom transformer "JavaObjectToXML" that can do the same in similar manner.
But my query how can i do this dynamically. Like if i give choice to Client on how it wants the data. And he can hit the URL like
- "http://localhost:1212/jcore/offering/details/?response=json"
- "http://localhost:1212/jcore/offering/details.json/"
OR
- "http://localhost:1212/jcore/offering/details/?response=xml"
- "http://localhost:1212/jcore/offering/details.xml/
And so i would be able to change the transformer at runtime, and return the result in corresponding notation. Is there any way to do it..??
or apart from Changing Transformer, any other workaround ??
Please Help me. I am Stuck in this.