Mule ESB - 集成测试 - REST端点 - 使用MuleClient

时间:2014-10-13 11:14:19

标签: java rest mule esb mule-component

我是骡子ESB的新手。我正在尝试对通过mule flow暴露的休息端点进行集成测试。 以下代码,命中POST REST端点,但我们怎么能说其余参数和http方法(获取或发布或删除等):

    MuleClient client = new MuleClient(muleContext);
    String payload = "foo";
    Map<String, Object> properties = new HashMap<String, Object>();
    MuleMessage result = client.send("http://localhost:5000/rest/resource", payload, properties);

我们应该在有效负载或传递的属性(Map)中设置任何东西吗?

1 个答案:

答案 0 :(得分:2)

在查看源代码后,我可以使用以下属性设置Http方法。

示例获取请求:

    MuleClient client = new MuleClient(muleContext);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("Content-type", "text/plain");
    properties.put("Accept", "text/plain");
    properties.put("http.method", "GET");

    MuleMessage result = client.send("http://localhost:5000/rest/resource?param1=268", null, properties);

示例发布请求:

    MuleClient client = new MuleClient(muleContext);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("Content-Type", "application/json");
    properties.put("http.method", "POST");

    String payload = "{...json here...}";

    MuleMessage result = client.send("http://localhost:5000/rest/resource", payload, properties);

希望它可以帮助别人。