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.

Help with Regular Expression Criteria

VirtEyes
VirtEyes Posts: 62

I have a MQ responder I am trying to move from one tool to Virtualize. This responder has two main types of criteria, one is in the form of regular expressions, and the other is just plain text.

I need help on how to create the criteria to match with the responder / how to handle these responders with these criteria.

An example of the regular expressions used are:
(?s)(.)authenticate(.)
(.)GET(.)GAIPROFILE(.*)

Can anyone help guide me on how to interpret these kinds of regular expressions, and how to interpret them as criteria for the virtual asset responders?

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    This responder has two main types of criteria, one is in the form of regular expressions, and the other is just plain text.

    What is the criteria used to match against? Are you trying to match something in the body of your MQ message, like the text in an XML element or JSON property, or something else like an MQMD or RFH2 header? Perhaps you can provide an example that describes your MQ message and what part of it you want to evaluate against your regular expression? The message responder lets you configure correlation in a variety of ways, so you can configure criteria for matching on values in body or header.

  • VirtEyes
    VirtEyes Posts: 62

    The criteria is usually a string like:
    GET GAITRPACES
    and this would return the response accordingly

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited February 2020

    and this would return the response accordingly

    What is the content type of the request you are matching the regular expression against? It it just a body of plain text or is it something structured like XML or JSON or EDI or fixed-length?

  • VirtEyes
    VirtEyes Posts: 62

    it varies from plain text to xml

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    Do you know where those strings come from? Are they in the MQ Message or are they part of RFH2 hearts? Without knowing where those strings come from it's hard to say what would need to be configured and where.

    Take a look at this link to documentation that talks about setting up correlations for MQ messages, it might help.
    https://docs.parasoft.com/display/SOAVIRT9104CTP311/Configuring+Server+and+Deployment+Settings#ConfiguringServerandDeploymentSettings-ConfiguringMQSettings

    Also here are some links to documentation that talks about responder correlations
    https://docs.parasoft.com/display/SOAVIRT9103/Understanding+the+Message+Correlation+Process
    https://docs.parasoft.com/display/SOAVIRT9103/Message+Responder+Overview#MessageResponderOverview-ResponderCorrelationTab

  • VirtEyes
    VirtEyes Posts: 62

    The strings are the MQ message being sent to the responder.
    Essentially I want to be able to convert this criteria for the virtual asset responder so that I can take in any MQ message that follows this criteria and as a result reply with the response message

    Headers, hearts and the like are not part of these responders

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited February 2020

    it varies from plain text to xml

    Let's say your message is XML. So, let's say "GET GAITRPACES" appears in an XML request like this:<root><foo>GET GAITRPACES</foo></root>

    In Virtualize, you would first create a "Plain XML Message Responder". On the Responder's "Options" tab, you can paste the sample XML request message for "Request Template". On the "Responder Correlation" tab under "Request Body", click "Enable Correlation" then add an XPath like "matches(/root/foo/text(), 'put-regex-here')" where "put-regex-here" is the regular expression you want to match on. If instead you want to match on a simple text value, your XPath can be something simple like "/root/foo/text()='some-text-to-match-on'".

  • VirtEyes
    VirtEyes Posts: 62

    I think there is a misunderstanding, the request will always be in plain text format, such as GET GAITRPACES
    However the criteria I am presented with instead is the regular expression:
    (?s)(.)authenticate(.)

  • VirtEyes
    VirtEyes Posts: 62

    so for instance, how would I handle a regex like:
    (.)GET(.)GAITRPACES(.*)

  • VirtEyes
    VirtEyes Posts: 62

    btw the forum keeps deleting the "*" I include with those dots in the parenthesis

  • VirtEyes
    VirtEyes Posts: 62

    I am also matching a literal MQ payload for the request

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    If you want to use a regular expression you probably want to create a "Custom" correlation in the "Responder Correlation" tab. You can write the regular expression in a scripting language and check that the incoming request matches.

  • VirtEyes
    VirtEyes Posts: 62

    Could you provide an example of what that would look like in this case?

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited February 2020

    I think there is a misunderstanding, the request will always be in plain text format,

    The "matches" XPath function I described earlier can be used to evaluate a regular expression against some node in the incoming request message. Even if your request is not XML, like plain text, you can convert it to XML. This is configured on the "Options" tab under "Request Handling" and "XML Conversion". Notice the "Plain Text" conversion option.

    Otherwise, without converting the request to XML, you can also evaluate a regular expression on the Responder Correlation tab under "Custom" where you can define a custom script. Your script could use a the Java String.matches() function which also accepts a regular expression. For example, your script could contain a method containing these two lines:

    requestBodyStr = context.get(CorrelationScriptingHookConstants.MESSAGE_STR)
    return requestBodyStr.matches("my-regex-goes-here")
    
  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    Here is an example the uses groovy to set a "custom" correlation that does a regular expression match that should be the same as one of the examples you provided. For more information on the regex pattern look at this documentation

    https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html