WireMock evaluation of all criteria generates unnecessary warnings
See original GitHub issue[Description] Short version: Non-json requests are evaluated against json mappings with body patterns and fill the log with failed json validation warnings. Longer version: Because WireMock does an aggregation of the results for all evaluation rules (RequestPattern.match(Request request)) instead of hierarchically allowing a subsequent criterion to be evaluated against only after the higher one was matched, mappings that would immediately be excluded based on things like URL are still evaluated for body pattern matches. This is an issue when json body pattern matching mappings exists because it tries to evaluate ALL requests [that did not previously match] against the json body pattern matching mappings, which fills the log with all kind of json validation warnings.
[Repro]
- Start WireMock.
- Train WireMock [use something like Postman and POST to WireMockServer:WireMockPort/__admin/mappings/] with RAW body:
{ "id": "fab6d56b-d66e-4a5a-810a-ab323e485103", "request": { "urlPath": "/unavailablepath", "method": "POST", "headers": { "X-SessionId": { "equalTo": "90930D577144AB198B2082CA56E6A0F5", "caseInsensitive": true } }, "bodyPatterns": [ { "matchesJsonPath": "$.params[0][?(@.parameterone == 'something')]" } ] }, "response": { "status": 200, "bodyFileName": "a.json", "headers": { "Content-Type": "application/json" } }, "uuid": "fab6d56b-d66e-4a5a-810a-ab323e485103" }
- Make sure the a.json file exists. I do not believe its content is relevant, but when I was creating the repro for this bug this is what I put in mine:
{ "jsonrpc": "2.0", "id": "-1412417872994864924", "result": { "payload": { "timeStamp": "2017-02-17T16:26:28.588" } } }
- Send a non-admin request to WireMock. I used an empty GET to WireMockServer:WireMockPort/services/none
- Observe the WireMock console. Result contains something like (actual error differs based on body patterns in mappings and on the requests):
20:41:12 INFO WireMock - Warning: JSON path expression ‘$.params[0][?(@.parameterone == ‘something’)]’ failed to match document ‘’ because of error ‘json string can not be null or empty’ 20:41:12 INFO WireMock - Warning: JSON path expression ‘$.params[0][?(@.parameterone == ‘something’)]’ failed to match document ‘’ because of error ‘json string can not be null or empty’
The number of such entries considerably increases when the mappings are more complex and the requests are quite large. I think it is a one to one matching for each line of the request to each body pattern and each will generate at least a warning.
This makes our logs (which are already quite large) extremely large and it is very hard to follow what is wrong when you need to navigate through hundreds of pages of such warnings.
We also do not want to downgrade the logging level since we would like to be able to observe the [other] information provided.
[Environment]
We are using WireMock 2.5.1, but we tested (before actually debugging the code and finding the root cause) and the issue is still present in WireMock 2.8.0.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:6 (3 by maintainers)
I think it is the same as this issue
Closing individual logging issues in favour of (referenced) logging redesign issue.