【问题标题】:Mule JUnit test for "text/xml"“文本/xml”的骡子 JUnit 测试
【发布时间】:2013-02-14 14:47:05
【问题描述】:

我有一个带有 HTTP 端点的流,它期望“text/xml”作为内容类型。当我使用 RESTClient 之类的东西来点击它时,这个流程可以正常工作。

<http:inbound-endpoint exchange-pattern="request-response" host="${web.rsc.host}" port="${web.rsc.port}" path="Quote/1_0/submit" doc:name="HTTP" mimeType="text/xml"/>

但是,我无法让 JUnit 测试工作。

测试的精简版如下所示:

@Test 
public void test5() throws MuleException
{
    MuleClient client = muleContext.getClient();

    MuleMessage message = new DefaultMuleMessage( "", muleContext );

    String payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><quote><value>dummy</value></quote>";
    message.setProperty( "http.method", "POST", PropertyScope.OUTBOUND );
    message.setProperty( "http.content-type", "text/xml", PropertyScope.OUTBOUND );
    message.setPayload( payload );

    MuleMessage reply = client.send( "http://localhost:8081/Quote/1_0/submit", message, null, 5000 );

    assertNotNull( reply );
    assertNotNull( reply.getPayload() );
    assertEquals( reply.getPayload(), "200" );
}

运行时,Mule 在入站端点上抛出异常:“消息包含 MIME 类型“text/plain”,而预期为“text/xml”。”

在测试消息上设置内容类型需要什么?

【问题讨论】:

    标签: java junit mule


    【解决方案1】:

    创建一个HashMap 属性

    Map<String, String> properties = new HashMap<String, String>();
    properties.add("Content-Type", "text/xml");
    

    并将其放入client.send

    MuleMessage reply = client.send( "http://localhost:8081/Quote/1_0/submit", payload, properties);
    

    【讨论】:

    • 这并没有解决问题。我仍然遇到同样的异常。
    • 有没有办法在这些 cmets 中发布格式化代码?还是你想让我把它作为答案?
    • public void test() throws MuleException { MuleClient client = muleContext.getClient(); MuleMessage message = new DefaultMuleMessage( "", muleContext ); String payload = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;&lt;quote&gt;&lt;value&gt;dummy&lt;/value&gt;&lt;/quote&gt;"; Map&lt;String, Object&gt; prop = new HashMap&lt;String, Object&gt;(); prop.put( "http.Content-Type", "text/xml" ); prop.put( "http.method", "POST" ); MuleMessage reply = client.send( "http://localhost:8081/Quote/1_0/submit", payload, prop ); }
    • 暂时可以粘贴到这里。 Pastebin 是一个不错的选择
    • 谢谢。看来我们暂时不得不接受手动测试。
    【解决方案2】:

    试试这个。

     message.setProperty("Content-Type", "text/xml", PropertyScope.OUTBOUND );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-28
      相关资源
      最近更新 更多