MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
Describe the issue
Java MockServerClient throws exception when MockServerClient::retrieveActiveExpectations(RequestDefinition requestDefinition, Format format) method called
2020-12-11 16:56:27.516 ERROR [thread:default task-2] java.lang.IllegalArgumentException: "JSON" is not a valid value for "format" parameter, only the following values are supported [java, json, log_entries]
SNAPSHOT.war//org.mockserver.client.MockServerClient.sendRequest(MockServerClient.java:221)
SNAPSHOT.war//org.mockserver.client.MockServerClient.sendRequest(MockServerClient.java:244)
SNAPSHOT.war//org.mockserver.client.MockServerClient.retrieveActiveExpectations(MockServerClient.java:1190)
SNAPSHOT.war//org.mockserver.client.MockServerClient.retrieveActiveExpectations(MockServerClient.java:1174)
What you are trying to do
Trying to call method: MockServerClient.retrieveActiveExpectations
MockServer version
5.11.2
To Reproduce
Call the method with any parameter
Expected behaviour
Successfully call without exception
MockServer Log
2020-12-11 16:55:51 5.11.2 SEVERE 1080 exception processing request:
Describe the issue Java MockServerClient throws exception when MockServerClient::retrieveActiveExpectations(RequestDefinition requestDefinition, Format format) method called
2020-12-11 16:56:27.516 ERROR [thread:default task-2] java.lang.IllegalArgumentException: "JSON" is not a valid value for "format" parameter, only the following values are supported [java, json, log_entries] SNAPSHOT.war//org.mockserver.client.MockServerClient.sendRequest(MockServerClient.java:221) SNAPSHOT.war//org.mockserver.client.MockServerClient.sendRequest(MockServerClient.java:244) SNAPSHOT.war//org.mockserver.client.MockServerClient.retrieveActiveExpectations(MockServerClient.java:1190) SNAPSHOT.war//org.mockserver.client.MockServerClient.retrieveActiveExpectations(MockServerClient.java:1174)
What you are trying to do Trying to call method: MockServerClient.retrieveActiveExpectations
MockServer version 5.11.2
To Reproduce Call the method with any parameter
Expected behaviour Successfully call without exception
MockServer Log 2020-12-11 16:55:51 5.11.2 SEVERE 1080 exception processing request:
{ "method" : "PUT", "path" : "/mockserver/retrieve", "queryStringParameters" : { "type" : [ "ACTIVE_EXPECTATIONS" ], "format" : [ "JSON" ] }, "headers" : { "content-type" : [ "application/json; charset=utf-8" ], "host" : [ "localhost:1080" ], "accept-encoding" : [ "gzip,deflate" ], "content-length" : [ "233" ], "connection" : [ "keep-alive" ] }, "keepAlive" : true, "secure" : false, "body" : { "method" : "POST", "path" : "/mockany/test0", "headers" : { "Accept" : [ "application/xml" ], "X-REQUEST-ROOT-ID" : [ "ICKP-MODULE12345-c62360ef-6089-49f0-9006-43e84c23a777-0X5B564C94" ] }, "body" : null } }
error:
"JSON" is not a valid value for "format" parameter, only the following values are supported [java, json, log_entries]
Possible fix of the bug: add toLowerCase() call
public String retrieveActiveExpectations(RequestDefinition requestDefinition, Format format) { HttpResponse httpResponse = sendRequest( request() .withMethod("PUT") .withContentType(APPLICATION_JSON_UTF_8) .withPath(calculatePath("retrieve")) .withQueryStringParameter("type", RetrieveType.ACTIVE_EXPECTATIONS.name()) .withQueryStringParameter("format", format.name().toLowerCase()) .withBody(requestDefinition != null ? requestDefinitionSerializer.serialize(requestDefinition) : "", StandardCharsets.UTF_8) ); return httpResponse.getBodyAsString(); }
There are multiple places in the code where this format.name().toLowerCase() call is missing.