【问题标题】:Mule ESB - integration testing - REST endpoint - using MuleClientMule ESB - 集成测试 - REST 端点 - 使用 MuleClient
【发布时间】:2014-10-27 17:00:13
【问题描述】:

我是 mule 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);

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

【问题讨论】:

    标签: java rest mule esb mule-component


    【解决方案1】:

    查看源代码后,我可以设置具有以下属性的 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);
    

    希望对其他人有所帮助。,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-23
      • 2017-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多