url matching and query parameters

1,595 views
Skip to first unread message

sam

unread,
Sep 29, 2015, 11:17:35 AM9/29/15
to wiremock-user
I have two URLs with query parameters. One has a specified date and the other has the date as .* to be the generic url. For playback, is there a way to prioritize the mappings? Even if my request includes the specified date, it will use the mappings with the .* date.

Tom Akehurst

unread,
Sep 29, 2015, 12:26:22 PM9/29/15
to wiremock-user
Message has been deleted

sam

unread,
Sep 29, 2015, 3:52:30 PM9/29/15
to wiremock-user
Thank you for your response. Below are some examples of the request/response pairs in mappings:

{
  "request" : {
    "urlPattern" : "/product-web/effectiveproducts/12153537-3856-1000-1000-00000010\\?asofdate=2013-12-20",
    "method" : "GET"
  },
  "response" : {
    "status" : 200,
    "bodyFileName" : "body-effectiveproducts-12153537-3856-1000-1000-00000010-8Niif.json",
    "headers" : {
      "Date" : "Tue, 29 Sep 2015 18:54:52 GMT",
      "Access-Control-Allow-Origin" : "*",
      "X-Server" : "ea-app0739.com",
      "X-SourceOfRecord" : "false",
      "X-StaleDataIndicator" : "false",
      "Content-Type" : "application/vnd.vsp.effectiveproduct+json;version=2.1",
      "Keep-Alive" : "timeout=5, max=94",
      "Connection" : "Keep-Alive",
      "Transfer-Encoding" : "chunked"
    }
  }
}

{
  "request" : {
    "urlPattern" : "/product-web/effectiveproducts/12153537-3856-1000-1000-00000010\\?asofdate=2013-06-18",
    "method" : "GET"
  },
  "response" : {
    "status" : 200,
    "bodyFileName" : "body-effectiveproducts-12153537-3856-1000-1000-00000010-WatMY.json",
    "headers" : {
      "Date" : "Tue, 29 Sep 2015 18:54:49 GMT",
      "Access-Control-Allow-Origin" : "*",
      "X-Server" : "ea-app0739.com",
      "X-SourceOfRecord" : "false",
      "X-StaleDataIndicator" : "false",
      "Content-Type" : "application/vnd.vsp.effectiveproduct+json;version=2.1",
      "Keep-Alive" : "timeout=5, max=98",
      "Connection" : "Keep-Alive",
      "Transfer-Encoding" : "chunked"
    }
  }
}

{
  "request" : {
    "urlPattern" : "/product-web/effectiveproducts/12153537-3856-1000-1000-00000010\\?asofdate=.*",
    "method" : "GET"
  },
  "response" : {
    "status" : 200,
    "bodyFileName" : "body-effectiveproducts-12153537-3856-1000-1000-00000010-OUXLJ.json",
    "headers" : {
      "Date" : "Tue, 29 Sep 2015 18:54:53 GMT",
      "Access-Control-Allow-Origin" : "*",
      "X-Server" : "ea-app0739.com",
      "X-SourceOfRecord" : "false",
      "X-StaleDataIndicator" : "false",
      "Content-Type" : "application/vnd.vsp.effectiveproduct+json;version=2.1",
      "Keep-Alive" : "timeout=5, max=92",
      "Connection" : "Keep-Alive",
      "Transfer-Encoding" : "chunked"
    }
  }
}

Initially I had:
wireMockServer.stubFor(get(urlMatching("/.*")).willReturn(aResponse().proxiedFrom(getRecordingTargetURL())));
because I had hundreds of URLs that varied in parameters. However, when all the parameters are the same, and the query parameter for the date varies, that's when I want to set priority. I tried regex, but I get an illegal argument exception:

wireMockServer.stubFor(get(urlMatching("/product-web/effectiveproducts/12153537-3856-1000-1000-00000010\\?asofdate=\\.\\*")).atPriority(5).willReturn(aResponse().proxiedFrom(getRecordingTargetURL())));
wireMockServer.stubFor(get(urlMatching("/product-web/effectiveproducts/12153537-3856-1000-1000-00000010\\?asofdate=.*")).atPriority(1).willReturn(aResponse().proxiedFrom(getRecordingTargetURL())));

But I would like to match the URLeven if the parameters in the middle (12153537-3856-1000-1000-00000010) vary without having to write a new URL matching for each URL if possible.

Tom Akehurst

unread,
Sep 29, 2015, 4:02:16 PM9/29/15
to wiremock-user
I'm not totally sure I understand what you're trying to do. It seems that in both cases you're just proxying onto the same URL, so I'm not sure what difference having two stubs would make.

Can you describe the behaviour you're trying to get?

sam

unread,
Oct 2, 2015, 10:36:45 AM10/2/15
to wiremock-user
Sorry, i'll take it one step at a time.

So just to make sure I am setting the priority, I tried:

wireMockServer.stubFor(get(urlMatching(".*")).atPriority(10).willReturn(aResponse().proxiedFrom(getRecordingTargetURL())));

but in the JSON, it is not showing any priority:

{
  "request" : {
    "urlPattern" : "/product-web/effectiveproducts/12153537-3856-1000-1000-00000010\\?asofdate=2013-06-18",
    "method" : "GET"
  },
  "response" : {
    "status" : 200,
    "bodyFileName" : "body-effectiveproducts-12153537-3856-1000-1000-00000010-Mk7hY.json",
    "headers" : {
      "Date" : "Fri, 02 Oct 2015 14:32:44 GMT",
      "Access-Control-Allow-Origin" : "*",
      "X-Server" : "ea-app0739.com",
      "X-SourceOfRecord" : "false",
      "X-StaleDataIndicator" : "false",
      "Content-Type" : "application/vnd.vsp.effectiveproduct+json;version=2.1",
      "Keep-Alive" : "timeout=5, max=98",
      "Connection" : "Keep-Alive",
      "Transfer-Encoding" : "chunked"
    }
  }
}

Is my code incorrect?

Tom Akehurst

unread,
Oct 9, 2015, 7:26:57 AM10/9/15
to wiremock-user
Where are you getting that bit of JSON from?
Reply all
Reply to author
Forward
0 new messages