Help with Regular Expression Criteria

VirtEyesVirtEyes Posts: 44

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_parasoftbenken_parasoft Posts: 895 ✭✭✭

    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.

  • VirtEyesVirtEyes Posts: 44

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

  • benken_parasoftbenken_parasoft Posts: 895 ✭✭✭
    edited February 4

    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?

  • VirtEyesVirtEyes Posts: 44

    it varies from plain text to xml

  • williammccuskerwilliammccusker Posts: 408 ✭✭

    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

  • VirtEyesVirtEyes Posts: 44

    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_parasoftbenken_parasoft Posts: 895 ✭✭✭
    edited February 4

    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'".

  • VirtEyesVirtEyes Posts: 44

    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(.)

  • VirtEyesVirtEyes Posts: 44

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

  • VirtEyesVirtEyes Posts: 44

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

  • VirtEyesVirtEyes Posts: 44

    I am also matching a literal MQ payload for the request

  • williammccuskerwilliammccusker Posts: 408 ✭✭

    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.

  • VirtEyesVirtEyes Posts: 44

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

  • benken_parasoftbenken_parasoft Posts: 895 ✭✭✭
    edited February 4

    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")
    
  • williammccuskerwilliammccusker Posts: 408 ✭✭

    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

Sign In or Register to comment.