我有一个集成测试,我正在使用带有springboot 2.0应用程序的mockserver-netty(v5.3.0)..一切正常但如果我尝试添加Content-Type标头,我会得到以下异常:< / p>
java.lang.IllegalArgumentException: Exception while parsing [{
"httpRequest" : {
"method" : "POST",
"body" : {
"type" : "XML",
"xml" : "......"
},
"times" : {
"remainingTimes" : 0,
"unlimited" : true
},
"timeToLive" : {
"unlimited" : true
}
}] for Expectation
at org.mockserver.client.AbstractClient.sendRequest(AbstractClient.java:95)
at org.mockserver.client.AbstractClient.sendExpectation(AbstractClient.java:441)
at org.mockserver.client.ForwardChainExpectation.respond(ForwardChainExpectation.java:25)
期望如下:
{
"method" : "POST",
"body" : {
"type" : "XML",
"xml" : "......"
}
},
"httpResponse" : {
"statusCode" : 200,
"headers" : {
"Content-Type" : [ "text/xml" ]
},
"body" : "......."
},
"times" : {
"remainingTimes" : 0,
"unlimited" : true
},
"timeToLive" : {
"unlimited" : true
}
}
我使用以下代码创建它:
private static HttpResponse responseWithBody(String responseBody, int statusCode, String contentType) {
return HttpResponse.response()
.withStatusCode(statusCode)
.withHeader("Content-Type",contentType)
.withBody(responseBody);
}
如果我只是用.withHeader(“Content-Type”,contentType)语句注释该行,一切运行正常。关于那个的任何线索? 非常感谢
答案 0 :(得分:0)
我遇到了同样的问题。看起来是由下面使用的xml解析器中的错误引起的,请参见https://github.com/jamesdbloom/mockserver/issues/451
升级到模拟服务器5.4.1,就可以了:)