I am bit new at Mule ESB and Anypoint Studio so I am trying to figure out how to fetch HTTP query parameters in a java transformer class.
I have tried
String firstname = message.getInboundProperty("fname");
String lastName = message.getInboundProperty("lname");
even went with
Map<String, String> queryParams = message.getInboundProperty("http.query.params");
String firstname = queryParams.get("fname");
String lastname = queryParams.get("lname");
but they return null values, I have even tried to use Callable Interface but I think it only possible to use it if it's a JAVA Component.
Do please let me know,
Thanks.
If you want to use in a Java transformer, you can follow the following example :-
public class MyCustomTransformer extends AbstractMessageTransformer {
@Override
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
Map<String, String> queryParams = message.getInboundProperty("http.query.params");
String fname=queryParams.get("fname");
System.out.println("fname: "+fname);
String lname=queryParams.get("lname");
System.out.println("lname: "+lname);
return message;
}
}
And Mule flow will be :-
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="Testlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<custom-transformer class="MyCustomTransformer" doc:name="Java"/>
</flow>
Now if you hit the url with query parameter for example:- http://localhost:8081/test?fname=anirban&lname=sen
You will get the following result in your console:-