Hello Team, I am currently using Wiremock for our ...
# help
e
Hello Team, I am currently using Wiremock for our development process. I am getting a request token in the serveEventListeners ( code is below ) . I have my request token inside of originalRequest.query.token ( tested it and it works correctly ), then I want to extract the middle part of the jwt token with regexExtract (code below again), but the problem is that the 'parts.1' doesn't work at all. I tried multiple versions like just using 1 etc, but nothing works. Does somebody know what the problem may be?
Copy code
"serveEventListeners": [
    {
      "name": "webhook",
      "parameters": {
        "method": "POST",
        "url": "https://......",
        "headers": {
          "Accept": "application/json; charset=utf-8; version=1",
          "Content-Type": "application/json"
        },
        "body": "{\"test\": \"{{regexExtract originalRequest.query.token '^[^.]+\\.([^.]+)\\..*$' 'parts.1'}}\"}"

      }
    }
  ]
And just for the sake of telling the whole scope -> if I do it just with
Copy code
"body": "{\"test\": \"{{regexExtract originalRequest.query.token '^[^.]+\\.([^.]+)\\..*$'}}\"}"
this works, but I get the two parts of the token, but I need only the middle one, because after that I also need to decode the String and parse the json with
Copy code
{{parseJson (base64 (regexExtract request.query.token '^[^.]+\.([^.]+)\.[^.]+$' '1') decode=true) test_variable}}
l
Would this be
parts.1
you need or
parts.0
?
e
parts.1, I need the middle part of the jwt token, there is the first, the second and the third part, but I only need the second, hence parts.1
l
I haven't used this part of the regextract before but I think the last variable is the name of the variable you want to use to store the parts. You can then use the parts variable after. Does this work -
"body": "{\"test\": \"{{regexExtract originalRequest.query.token '^[^.]+\\.([^.]+)\\..*$' 'parts'}}{{parts.1}}\"}"
e
unfortunately that is syntactically incorrect
l
Did it generate an error ? Can you provide the full wiremock json for the stub and a sample request so I can test this out myself ?
e
Sure, so first it did generate a 422 error This is my full wiremock json for the stub
Copy code
{
  "uuid": "e8068f1a-b575-42f3-88d7-ed053796d9c3",
  "request": {
    "urlPathPattern": "/activation/.*",
    "method": "GET",
    "queryParameters": {
      "token": {
        "matches": ".*"
      }
    }
  },
  "response": {
    "status": 200
  },
  "priority": 996,
  "metadata": {
    "wiremock-gui": {
      "folder": "/static"
    }
  },
  "serveEventListeners": [
    {
      "name": "webhook",
      "parameters": {
        "method": "POST",
        "url": "<https://dev.net/webhook-processor/results>",
        "headers": {
          "Accept": "application/json; charset=utf-8; version=1",
          "Content-Type": "application/json"
        },
        "body": "{\"reference\": \"{{regexExtract originalRequest.query.token '^[^.]+\\.([^.]+)\\..*$' 'parts'}}{{parts.1}}\"}",
        "delay": {
          "type": "fixed",
          "milliseconds": 1000
        }
      }
    }
  ]
}
sample request
Copy code
<https://dev.net/activation/?token=eyJraWQiOiIwNDE1MjhjOS1kMjg1LTQyNzEtOWUzOS00ZTM1YTliZmY2YTIiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJidW5kbGUiLCJhdWQiOiJGb3J0dW1vIiwidXJscyI6eyJidW5kbGVfY2FsbGJhY2siOiJodHRwczovL2Z1LndhaXB1LWRldi5uZXQvd293LXdlYmhvb2stcHJvY2Vzc29yL3dvdy9yZXN1bHRzIn0sIm5iZiI6MTc0NTU3NTg3MCwiZW50aXRsZW1lbnRfaWQiOiIzOTA2NWUxNi1iOGNlLTRmNjQtOWRmYi03NjhiYjViOWFlNmUiLCJvcGVyYXRpb25fcmVmZXJlbmNlIjoiMmFjMTRlOTktOGYyMy00MjI4LWEzM2EtZGRiNDQ0NjcxMWNjIiwiaXNzIjoiZjVkNmQ3LWJ1bmRsaW5nLXRlc3Qtb2ZmZXItY2ZhMWEiLCJleHAiOjE3NDU1NzY3NzAsImlhdCI6MTc0NTU3NTg3MCwianRpIjoiZTJhMmJjZGMtNzRmZC00YjliLWI2ZjQtNDY1ZDJjZWUxZmQzIn0.Wzsj7JFYINxvx0xUwUWnxtwEu3bVGmjxtsrCuE-sLR7KyZ7sFkLPBn4C-jxvo3Oo57HNUqygCePySxYIlLidswkC2ew1dhMxWuqzNdKM97WCRMJqnryQnTHrncIks748gLFI4LgUFqCM6B1KHDI35pwfcmitV_MCwpmXKHhfOgvw_ZyVG6-8ej6oFJa8YXkwxKqWLhRt8op_F9ZubEFa7Y69AcRquYN93PdsCZ3gIIiIHzCvMHQFKY-rNL6BS0NTvPM5sjcFMuinF03vh8XRGdFpU1YtFzD1-UoWvfYWE6jVwzT85cvRD6F_tfFbIvo1j_ypA7uI6AT3ZykSSJ5rmw>
the https://dev.net/webhook-processor/results is a lambda
The token is safe, no important data, hence I just posted it
Bildschirmfoto 2025-04-25 um 12.14.17.png
l
OK, I have trimmed this back a little so I don't need to setup something for the webhook to talk to but I think you will get the idea:
Copy code
{
  "request": {
    "urlPathPattern": "/activation/.*",
    "method": "GET",
    "queryParameters": {
      "token": {
        "matches": ".*"
      }
    }
  },
  "response": {
    "status": 200,
    "body": "{\"reference\": \"{{regexExtract request.query.token '^[^.]+\\.([^.]+)\\..*$' 'parts'}}{{parts.0}}\"}",
    "transformers": [
      "response-template"
    ]
  }
}
Using this request:
Copy code
GET <http://localhost:8080/activation/?token=eyJraWQiOiIwNDE1MjhjOS1kMjg1LTQyNzEtOWUzOS00ZTM1YTliZmY2YTIiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJidW5kbGUiLCJhdWQiOiJGb3J0dW1vIiwidXJscyI6eyJidW5kbGVfY2FsbGJhY2siOiJodHRwczovL2Z1LndhaXB1LWRldi5uZXQvd293LXdlYmhvb2stcHJvY2Vzc29yL3dvdy9yZXN1bHRzIn0sIm5iZiI6MTc0NTU3NTg3MCwiZW50aXRsZW1lbnRfaWQiOiIzOTA2NWUxNi1iOGNlLTRmNjQtOWRmYi03NjhiYjViOWFlNmUiLCJvcGVyYXRpb25fcmVmZXJlbmNlIjoiMmFjMTRlOTktOGYyMy00MjI4LWEzM2EtZGRiNDQ0NjcxMWNjIiwiaXNzIjoiZjVkNmQ3LWJ1bmRsaW5nLXRlc3Qtb2ZmZXItY2ZhMWEiLCJleHAiOjE3NDU1NzY3NzAsImlhdCI6MTc0NTU3NTg3MCwianRpIjoiZTJhMmJjZGMtNzRmZC00YjliLWI2ZjQtNDY1ZDJjZWUxZmQzIn0.Wzsj7JFYINxvx0xUwUWnxtwEu3bVGmjxtsrCuE-sLR7KyZ7sFkLPBn4C-jxvo3Oo57HNUqygCePySxYIlLidswkC2ew1dhMxWuqzNdKM97WCRMJqnryQnTHrncIks748gLFI4LgUFqCM6B1KHDI35pwfcmitV_MCwpmXKHhfOgvw_ZyVG6-8ej6oFJa8YXkwxKqWLhRt8op_F9ZubEFa7Y69AcRquYN93PdsCZ3gIIiIHzCvMHQFKY-rNL6BS0NTvPM5sjcFMuinF03vh8XRGdFpU1YtFzD1-UoWvfYWE6jVwzT85cvRD6F_tfFbIvo1j_ypA7uI6AT3ZykSSJ5rmw>
I get this reposnse:
Copy code
{
  "reference": "eyJzdWIiOiJidW5kbGUiLCJhdWQiOiJGb3J0dW1vIiwidXJscyI6eyJidW5kbGVfY2FsbGJhY2siOiJodHRwczovL2Z1LndhaXB1LWRldi5uZXQvd293LXdlYmhvb2stcHJvY2Vzc29yL3dvdy9yZXN1bHRzIn0sIm5iZiI6MTc0NTU3NTg3MCwiZW50aXRsZW1lbnRfaWQiOiIzOTA2NWUxNi1iOGNlLTRmNjQtOWRmYi03NjhiYjViOWFlNmUiLCJvcGVyYXRpb25fcmVmZXJlbmNlIjoiMmFjMTRlOTktOGYyMy00MjI4LWEzM2EtZGRiNDQ0NjcxMWNjIiwiaXNzIjoiZjVkNmQ3LWJ1bmRsaW5nLXRlc3Qtb2ZmZXItY2ZhMWEiLCJleHAiOjE3NDU1NzY3NzAsImlhdCI6MTc0NTU3NTg3MCwianRpIjoiZTJhMmJjZGMtNzRmZC00YjliLWI2ZjQtNDY1ZDJjZWUxZmQzIn0"
}
Is that what you were looking for?
e
THANK YOU VERY MUCH! Yes that was it. For the sake of completion. Here is the whole query inkl. parsing
Copy code
{{#parseJson 'parsedObj'}}{{#base64 decode=true}}{{regexExtract originalRequest.query.token '^[^.]+\\.([^.]+)\\..*$' 'parts'}}{{parts.0}}{{/base64}}{{/parseJson}}{{parsedObj.test_obj}}
l
Awesome, glad it is working
🙌 1