Query parameter's not matching

1,013 views
Skip to first unread message

jeevjyot singh chhabda

unread,
Oct 11, 2017, 2:15:31 PM10/11/17
to wiremock-user
I am using wiremock as Standalone server and creating the mapping using Admin API through Json
and mapping is being created successfully. Here is the mapping



{
 
"id" : "21fba65e-23ce-4be9-82c1-02a779dd669c",
 
"request" : {
   
"urlPattern" : "v1/safe/files/1234/url?tokenCreator=Creator&tokenExpires=1800",
   
"method" : "GET"
 
},
 
"response" : {
   
"status" : 201,
   
"body" : "this will return the body",
   
"headers" : {
     
"Content-Type" : "application/json"
   
}
 
},
 
"uuid" : "21fba65e-23ce-4be9-82c1-02a779dd669c",
 
"persistent" : true
}

and i sending the request mapping request as
http://localhost:8080/v1/safe/files/1234/url?tokenCreator=Creator&tokenExpires=1800

Wiremock verbose response:

Closest match:

{
"urlPattern" : "/v1/safe/files/1234/url?tokenCreator=Creator&tokenExpires=1800",
"method" : "GET"
}


2017-10-11 09:05:34.871 Request received:
0:0:0:0:0:0:0:1 - GET /v1/safe/files/1234/url?tokenCreator=Creator&tokenExpires=1800

Authorization: [Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbGxpX2lkdCI6IkFwcGxpY2F0aW9uIiwic3ViIjoidXJuOmVsbGk6c2VydmljZTplZGVsaXZlcnkiLCJhdWQiOiJ1cm46ZWxsaTpzZXJ2aWNlOm1lZGlhIiwic2NvcGUiOiJhcGlwbGF0Zm9ybSIsImlzcyI6InVybjplbGxpOnNlcnZpY2U6aWRzIiwianRpIjoiNmZkMTI2ZDctMzRjOC00YTM4LTliNjgtZDM1MTkyYjRiNjJiIiwiaWF0IjoxNTA3NzM3OTM0LCJleHAiOjE1MDc3MzgyMzR9.hj5tiKmEG2HAtL-BxqWuGTYNRkPJdRcBYaArY4JS9tw]
Host: [localhost:8080]
Accept: [application/json]
X-Correlation-Id: [ce24b495-14be-4433-85cb-86f8e25584dd]

Matched response definition:
(no response definition configured)

Response:
HTTP/1.1 404
(no headers)

Any help or feedback would be very helpful. Where i am going wrong?

Tom Akehurst

unread,
Oct 11, 2017, 2:28:21 PM10/11/17
to wiremock-user
The problem is the ? in the URL combined with urlPattern. Because ? is a metacharacter in regular expressions you need to escape it with a backslash if you want it to denote the path/query boundary.
Message has been deleted

jeevjyot singh chhabda

unread,
Oct 11, 2017, 3:21:48 PM10/11/17
to wiremock-user
Thank you for the response, Tom. I added the backslash to my urlPattern. Here is my updated urlPattern ="v1/safe/files/1234/url\\?tokenCreator=Creator&tokenExpires=1800"; 
Ans still not success. 

thanks 

Tom Akehurst

unread,
Oct 12, 2017, 7:26:30 AM10/12/17
to wiremock-user
You also need a leading slash on the URL

jeevjyot singh chhabda

unread,
Oct 13, 2017, 2:01:44 PM10/13/17
to wiremock-user
Thank you, Tom. That was lame mistake at my end.
thanks 

Tom Akehurst

unread,
Oct 13, 2017, 2:10:47 PM10/13/17
to wiremock-user
No worries, very commonly made mistake!

jeevjyot singh chhabda

unread,
Oct 13, 2017, 2:21:28 PM10/13/17
to wiremock-user
thanks!!
Reply all
Reply to author
Forward
0 new messages