0

I have an integration test where I am using mockserver-netty (v5.3.0) with a springboot 2.0 application..everything is working fine but if I try to add the Content-Type header, I get the following exception:

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)

The expectation is the following:

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

I create it with the following code:

private static HttpResponse responseWithBody(String responseBody, int statusCode, String contentType) {
    return HttpResponse.response()
            .withStatusCode(statusCode)
            .withHeader("Content-Type",contentType)
            .withBody(responseBody);
}

If I just comment the line with the .withHeader("Content-Type",contentType) statement, everything runs fine. Any clue about that? Thanks a lot

filmac
  • 177
  • 2
  • 15

1 Answers1

0

I got the same problem. Looks like it was caused by a bug in xml parser used underneath, see https://github.com/jamesdbloom/mockserver/issues/451

Upgrade to mockserver 5.4.1 and you'll be fine :)

Michael Zilbermann
  • 1,398
  • 9
  • 19