0

我有一个集成测试,我将 mockserver-netty (v5.3.0) 与 springboot 2.0 应用程序一起使用。一切正常,但如果我尝试添加 Content-Type 标头,我会收到以下异常:

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) 语句注释该行,那么一切运行正常。有什么线索吗?非常感谢

4

1 回答 1

0

我遇到了同样的问题。看起来它是由下面使用的 xml 解析器中的错误引起的,请参阅https://github.com/jamesdbloom/mockserver/issues/451

升级到 mockserver 5.4.1,你会没事的 :)

于 2018-11-06T12:33:53.040 回答