如果要在 Java 转换器中使用,可以按照以下示例进行操作:-
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;
}
}
骡流将是:-
<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>
现在,如果您使用查询参数点击 url,例如:- http://localhost:8081/test?fname=anirban&lname=sen
您将在控制台中获得以下结果:-