Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How can I apply a regex rule to a URL Path?

Options

Problem:
Given the URL: server.com/Responder/param1/value1

I want the value1 to be a number 18 length digits only, so when I call e.g.:
param1/123456789123456789 the test should PASS
and
param1/1234abc should FAIL

and then, whatever comes in as value1 should be returned in the JSON response.

My questions are:
where can I apply this "regex" like rule?

Answers

  • henriquevc
    henriquevc Posts: 3
    edited February 2022
    Options

    Things I tried to config:

    response:

    Path

  • williammccusker
    williammccusker Posts: 645 ✭✭✭
    Options

    Hi,

    I would suggest either the Data Source Criteria as a place to start. The [*] example is fairly close, its not clear from the screenshots if that was being used in a Data Source Correlation where the criteria are supported. Otherwise, the Custom correlation option could be used to script the regex matching of the path.

    Here is some documentation about using criteria, it explains the syntax as well as how to use criteria with Message Responders and Data Source correlations
    https://docs.parasoft.com/display/SOAVIRT9103/Criteria+Expressions+for+Matching+Values+with+the+Message+Responder

  • henriquevc
    henriquevc Posts: 3
    edited February 2022
    Options

    Hi William, thanks for the reply!

    I managed to make a regex match work but the value as shown here:

    Here is the regex applied on the data source correlation table

    The problem now is that I want to see this entered value in the response but the response is printing the regex code.

    Thats how I am pulling the OrderNo value for correlation:

    What am I doing wrong please? and why is the response printing the regex? shouldnt it be interpreted as code/script and then just return me the URL path value that has been tested against the regex?

  • williammccusker
    williammccusker Posts: 645 ✭✭✭
    Options

    Hi,

    The parameterization from the screenshot is taking the value from the data source, the regex, and sending it back as you noted. To get the actual value extract it from the path using a REST URL Data Bank tool attached to the incoming request header. This will allow you to path the value from the path, put into a Data Bank column and then use that Data Bank column in the response to send back the actual value rather than the regex.

    https://docs.parasoft.com/display/SOAVIRT9103/REST+URL+Data+Bank