2

我是骡子 ESB 的新手。我正在尝试对通过 mule 流公开的休息端点进行集成测试。以下代码命中 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);

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

4

1 回答 1

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);

希望它可以帮助别人。,

于 2014-10-13T11:58:51.850 回答