首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >添加Content-Type标头时无法解析mockserver-netty上的期望

添加Content-Type标头时无法解析mockserver-netty上的期望
EN

Stack Overflow用户
提问于 2018-06-08 20:10:21
回答 1查看 315关注 0票数 0

我有一个集成测试,其中我使用mockserver-netty (v5.3.0)和springboot 2.0 application..everything工作正常,但如果我尝试添加Content-Type头,我会得到以下异常:

代码语言:javascript
复制
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)

期望值如下:

代码语言:javascript
复制
{
    "method" : "POST",
    "body" : {
      "type" : "XML",
      "xml" : "......"
    }
  },
  "httpResponse" : {
    "statusCode" : 200,
    "headers" : {
      "Content-Type" : [ "text/xml" ]
    },
    "body" : "......."
  },
  "times" : {
    "remainingTimes" : 0,
    "unlimited" : true
  },
  "timeToLive" : {
    "unlimited" : true
  }
}

我用下面的代码创建它:

代码语言:javascript
复制
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)语句注释该行,一切都运行得很好。有什么线索吗?非常感谢

EN

回答 1

Stack Overflow用户

发布于 2018-11-06 20:33:53

我也有同样的问题。看起来它是由下面使用的xml解析器中的一个bug引起的,请参阅https://github.com/jamesdbloom/mockserver/issues/451

升级到mockserver 5.4.1就可以了:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50760368

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档