Mismatch of url patch with query string

470 views
Skip to first unread message

Mabz Hussain

unread,
Apr 28, 2018, 11:50:12 AM4/28/18
to wiremock-user

I'm sending a request from SOAPUI to a wiremock server, and I'm attempting to match the url's.

This is the request that is being sent out: /user/test/?and=query

I've written the following regular expression:

stubFor(post(urlPathMatching("/user/test/\\?(and)\\=([a-z]*)"))

The problem is when I try to match the "?" when I use one backslash to capture the literal character, I get an error in Java saying:

"Illegal Escape Character"

What I tried to do to resolve the problem: I know the solution is to use the second backslash to capture the "?" like this: "\?", but when I send the request I get an error saying the urls don't match because this is the request that is matched against the original one being sent from soap ui:

/user/test/\?(and)\=([a-z]*) 

Second attempt I've tried to use the dot notation to represent the "?" and "=" symbol. I've tested this on a regular expression tester and it checks out, but, It's still saying the url's dont match on soap ui.

Regular expression: stubFor(post(urlPathMatching("/user/test/.*(and).*([a-z]*)")).atPriority(1)

mismatched url: /user/test/.*(and).*([a-z]*)



Can someone please help?

Tom Akehurst

unread,
Apr 29, 2018, 3:51:53 PM4/29/18
to wiremock-user
One observation - you're using urlPathMatching with a path + query, which will not work under any circumstances. urlMatching will attempt to match path and query.

However, given that regexes are a bit messy when there's a query string involved, you might find it easier to use separate path and query parameter matching e.g.

stubFor(post(urlPathEqualTo("/user/test"))
  .withQueryParam("and", matching("([a-z]*)"))

Mabz Hussain

unread,
Apr 30, 2018, 9:19:04 AM4/30/18
to wiremock-user
Thanks Tom!
Reply all
Reply to author
Forward
0 new messages