我有一个带有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“时。”
在测试邮件上设置内容类型需要什么?
答案 0 :(得分: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);
答案 1 :(得分:0)
试试这个。
message.setProperty("Content-Type", "text/xml", PropertyScope.OUTBOUND );