ExactMatcher does not accept ISO8601 DateTime? #230

Closed
opened 2025-12-29 14:25:50 +01:00 by adam · 7 comments
Owner

Originally created by @jglavic on GitHub (Dec 2, 2019).

Hi, I am trying to respond to the following sample request:

[GET] http://localhost/api/update?since=2019-12-01T22:10:25.000Z

using this mapping in a json file:

{
  "Headers": { "Content-Type": "application/json" },
  "Request": {
    "Path": {
      "Matchers": [
        {
          "Name": "ExactMatcher",
          "Pattern": "/api/update"
        }
      ]
    },
    "Params": [
      {
        "Name": "since",
        "Matchers": [
          {
            "Name": "ExactMatcher",
            "Pattern": "2019-12-01T22:10:25.000Z"
          }
        ]
      }
    ],
    "Methods": [ "get" ]
  },
  "Response": {
    "StatusCode": 200,
    "Headers": { "Content-Type": "application/json" },
    "BodyAsJson": { "result": [] }
  }
}

I am receiving a 404 response.
The mapping does not even get registered. The otuput log says:

[Error]: Static MappingFile : 'REST\mappings\update_1.json' could not be read. This file will be skipped.

Have you got any ideas why this won't work as expected??
thank you! (ps: great project I love it!)

Originally created by @jglavic on GitHub (Dec 2, 2019). Hi, I am trying to respond to the following sample request: [GET] http://localhost/api/update?since=2019-12-01T22:10:25.000Z using this mapping in a json file: ``` js { "Headers": { "Content-Type": "application/json" }, "Request": { "Path": { "Matchers": [ { "Name": "ExactMatcher", "Pattern": "/api/update" } ] }, "Params": [ { "Name": "since", "Matchers": [ { "Name": "ExactMatcher", "Pattern": "2019-12-01T22:10:25.000Z" } ] } ], "Methods": [ "get" ] }, "Response": { "StatusCode": 200, "Headers": { "Content-Type": "application/json" }, "BodyAsJson": { "result": [] } } } ``` I am receiving a 404 response. The mapping does not even get registered. The otuput log says: > [Error]: Static MappingFile : 'REST\mappings\update_1.json' could not be read. This file will be skipped. Have you got any ideas why this won't work as expected?? thank you! (ps: great project I love it!)
adam added the bug label 2025-12-29 14:25:50 +01:00
adam closed this issue 2025-12-29 14:25:50 +01:00
Author
Owner

@StefH commented on GitHub (Dec 2, 2019):

The error message REST\mappings\update_1.json is a different one, not related to ExactMatcher.

When I post your mapping and test it using a GET, it works fine:
image

@StefH commented on GitHub (Dec 2, 2019): The error message `REST\mappings\update_1.json` is a different one, not related to ExactMatcher. When I post your mapping and test it using a GET, it works fine: ![image](https://user-images.githubusercontent.com/249938/69936200-626c2480-14d7-11ea-9045-2567b0a3963d.png)
Author
Owner

@StefH commented on GitHub (Dec 3, 2019):

@yankeepenky Do you still need support on this issue?

@StefH commented on GitHub (Dec 3, 2019): @yankeepenky Do you still need support on this issue?
Author
Owner

@jglavic commented on GitHub (Dec 4, 2019):

sorry for my late reply!
first, the strange issue occured when using "Matchers": [ {"Name": "...", "Pattern": "..."}]. As soon as I changed that to "Patterns": [ "..." ] the file was read in successfully.

Now the _value of the matcher was still empty...
matcher


Next I changed from VS2015 to VS2017 in order to check the issue there. I now receive the following exception when trying to call any path with any http method:

xxx.Core.Exceptions.WebRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

Environment: VS2017, targeting .NET 4.7.2 (full framework)
As soon as I fixed that issue (which does not seem to be connected to wiremock) I'll report back.

@jglavic commented on GitHub (Dec 4, 2019): sorry for my late reply! first, the strange issue occured when using `"Matchers": [ {"Name": "...", "Pattern": "..."}]`. As soon as I changed that to "Patterns": [ "..." ] the file was read in successfully. Now the _value of the matcher was still empty... ![matcher](https://user-images.githubusercontent.com/35534941/69963867-69b02400-1511-11ea-8c42-4c41933b6cd3.png) --------------------------------------- Next I changed from VS2015 to VS2017 in order to check the issue there. I now receive the following exception when trying to call any path with any http method: > xxx.Core.Exceptions.WebRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host Environment: VS2017, targeting .NET 4.7.2 (full framework) As soon as I fixed that issue (which does not seem to be connected to wiremock) I'll report back.
Author
Owner

@StefH commented on GitHub (Dec 5, 2019):

Just using Pattern should also work fine.

@StefH commented on GitHub (Dec 5, 2019): Just using `Pattern` should also work fine.
Author
Owner

@jglavic commented on GitHub (Dec 13, 2019):

@StefH I checked the issue again, now while debugging your code:

This is the json file:
"Request": { "Path": { "Matchers": [ { "Name": "ExactMatcher", "Pattern": "/api/update" } ] }, "Params": [ { "Name": "since", "Matchers": [ { "Name": "ExactMatcher", "Pattern": "2019-12-01T22:10:25.000Z" } ] } ], "Methods": [ "get" ] },

The issue is the pattern being cast to a DateTime:
Serialization\MatcherMapper.cs line 39:
string[] stringPatterns = matcher.Patterns != null ? matcher.Patterns.OfType<string>().ToArray() : new[] { matcher.Pattern as string };

here matcher.Pattern is a DateTime and matcher.Pattern as string returns null.

Serialization occurs here: Server\FluentMockServer.Admin.cs Line 232
var mappingModels = DeserializeObjectToArray<MappingModel>(JsonConvert.DeserializeObject(value));

@jglavic commented on GitHub (Dec 13, 2019): @StefH I checked the issue again, now while debugging your code: This is the json file: `"Request": { "Path": { "Matchers": [ { "Name": "ExactMatcher", "Pattern": "/api/update" } ] }, "Params": [ { "Name": "since", "Matchers": [ { "Name": "ExactMatcher", "Pattern": "2019-12-01T22:10:25.000Z" } ] } ], "Methods": [ "get" ] },` The issue is the pattern being cast to a DateTime: Serialization\MatcherMapper.cs line 39: `string[] stringPatterns = matcher.Patterns != null ? matcher.Patterns.OfType<string>().ToArray() : new[] { matcher.Pattern as string };` here matcher.Pattern is a DateTime and `matcher.Pattern as string` returns null. Serialization occurs here: Server\FluentMockServer.Admin.cs Line 232 `var mappingModels = DeserializeObjectToArray<MappingModel>(JsonConvert.DeserializeObject(value));`
Author
Owner

@StefH commented on GitHub (Dec 13, 2019):

@yankeepenky I understand your issue.
I fixed it, can you try version WireMock.Net.1.0.40-ci-12334 from MyGet?

@StefH commented on GitHub (Dec 13, 2019): @yankeepenky I understand your issue. I fixed it, can you try version `WireMock.Net.1.0.40-ci-12334` from MyGet?
Author
Owner

@jglavic commented on GitHub (Dec 14, 2019):

@StefH Great news! all my tests succeeded! thank you for your fix...
I am waiting now for the next release - this issue was solved.

@jglavic commented on GitHub (Dec 14, 2019): @StefH Great news! all my tests succeeded! thank you for your fix... I am waiting now for the next release - this issue was solved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#230