Citrus framework 有效负载中的意外字符

Citrus framework 有效负载中的意外字符,citrus-framework,Citrus Framework,我的柑橘测试向某个RESTAPI发送(旅行)请求。答复的处理方式如下: http() .client("http://localhost:18082/cases") .send() .post() .accept("application/json; charset=UTF-8") .contentType("application/json") //.payload(new ClassPathResource("templates/travelrequest.json")); .payload

我的柑橘测试向某个RESTAPI发送(旅行)请求。答复的处理方式如下:

http()
.client("http://localhost:18082/cases")
.send()
.post()
.accept("application/json; charset=UTF-8")
.contentType("application/json")
//.payload(new ClassPathResource("templates/travelrequest.json"));
.payload(
"{ "+
"\"definition\": \"travelrequest.xml\", "+
"\"name\": \"travelrequest\" "+
"} "
);
虽然收到了响应代码500,但这是我所期望的。在Wireshark中,我捕获了以下包:

Host: localhost:18082
Connection: Keep-Alive                
User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_121)
Accept-Encoding: gzip,deflate

{ "definition": "travelrequest.xml", "name": "travelrequest" } HTTP/1.1 500 Internal Server Error
Server: spray-can/1.3.3
Date: Thu, 13 Apr 2017 15:33:37 GMT
Host: localhost:18082
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_121)
Accept-Encoding: gzip,deflate

?{
"definition": "travelrequest.xml",
"name": "travelrequest"
}HTTP/1.1 400 Bad Request
Server: spray-can/1.3.3
Date: Thu, 13 Apr 2017 15:36:15 GMT
当我将有效负载移动到模板时,测试的接收部分现在如下所示:

http()
.client("http://localhost:18082/cases")
.send()
.post()
.accept("application/json; charset=UTF-8")
.contentType("application/json")
.payload(new ClassPathResource("templates/travelrequest.json"));
//.payload(
//        "{ "+
//        "\"definition\": \"travelrequest.xml\", "+
//       "\"name\": \"travelrequest\" "+
//        "} "
//);
模板资源包含以下文本:

{
"definition": "travelrequest.xml",
"name": "travelrequest"
}
当我运行这个测试时,我收到一个不同的响应代码:400。在Wireshark中,我捕获了以下包:

Host: localhost:18082
Connection: Keep-Alive                
User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_121)
Accept-Encoding: gzip,deflate

{ "definition": "travelrequest.xml", "name": "travelrequest" } HTTP/1.1 500 Internal Server Error
Server: spray-can/1.3.3
Date: Thu, 13 Apr 2017 15:33:37 GMT
Host: localhost:18082
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_121)
Accept-Encoding: gzip,deflate

?{
"definition": "travelrequest.xml",
"name": "travelrequest"
}HTTP/1.1 400 Bad Request
Server: spray-can/1.3.3
Date: Thu, 13 Apr 2017 15:36:15 GMT
请注意,请求以一个意外的问号开始。此问号在柑橘输出中不可见:

17:36:13,629 DEBUG    client.HttpClient| Sending HTTP message to: 'http://localhost:18082/cases'
17:36:13,629 DEBUG    client.HttpClient| Message to send:
 {
"definition": "travelrequest.xml",
"name": "travelrequest"
}
17:36:13,630 DEBUG ingClientInterceptor| Sending Http request message
注意开口支架正前方的空间

这是一个特殊的角色吗?为什么要将其添加到有效负载中?有合乎逻辑的解释吗

干杯,
Ed似乎是一个编码问题。柑橘在读取文件内容时默认使用
UTF-8
编码。可能文件使用了其他编码,第一个字符就是这种差异的结果

请检查文件编码。通过设置系统属性,可以告诉Citrus使用其他编码

citrus.file.encoding=UTF-8
您还可以将此属性添加到
柑橘应用程序.properties
文件中,如下所述: