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.

Skip Special Character in Incoming Request

VirtEyes
VirtEyes Posts: 62

I have an instance where the incoming request will be a Hex string that is preceded with ">>>" and ends with "<<<"

Ex: >>>1601 0200 <<<

I wanted to know what is the best way for me to skip the three arrows preceding the hex string and after?

I want to skip the first three arrows and just deal with the hex string in-between

Comments

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    Where is it that you are interacting with the message and want to skip the leading characters? Is this in a correlation or an extension tool? Knowing where in the process this is happening will help me understand what options are available.

  • VirtEyes
    VirtEyes Posts: 62

    Hey William,

    The current process of what's happening is that the request is sent in that form with the three arrows (>>>1601 0200<<), and I am trying to extract the hex string that is in between the arrows so then it can hopefully be treated as xml via the iso8583 packager we have, and then form it accordingly.

    Currently I need to extract the hex string as the first step before it gets interpreted by the packager we created. Correlation will occur after the hex string has been extracted and has been transformed by the packager into the proper xml format

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    There is an option to allow tool's chained to the incoming request to modify the payload before apply data source correlations. In the responder editor go to the "Options" tab, the section "Request Handling" and check the option "Allow incoming request tools to modify the message..."

    Then on the responder you could chain an extension tool to the incoming request and parse the string there to extract the contents inside the arrows.

    Would that work for your use case?

  • VirtEyes
    VirtEyes Posts: 62

    Also William, I suppose I am would be using the extension tool to extract this hex string in order to work with it, unless you know of a different way.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    The extension tool is the way I know of. I don't know if any other tool that would work for transforming the incoming request. A Text Data Bank would be able to extract the right value but it would not change the request payload that is used for correlation.

  • VirtEyes
    VirtEyes Posts: 62

    Hey William,

    That sounds perfect, I am just unsure on how to parse it in the extension tool. And I would suppose I would store the string in another tool or would it be able to then go to the "Request handling" stage and be handled accordingly?

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    Depending on which scripting language you use it will be slightly different. Probably doing some form of a substring, here is a link to some examples of doing substring with Groovy

    https://www.tutorialspoint.com/groovy/groovy_substring.htm

    Once the extension tool has the desired request, just return the value from the method and it should replace the original request.

  • VirtEyes
    VirtEyes Posts: 62
    edited January 2021

    Hey William,

    Could you provide an example of how the scripting would look like?

    I take it, that it would be similar to:

       import com.parasoft.api.*;
    
       String evaluateRequest(Object input, Context context)
        {
        String Request = input.toString();
        int arrows = Request.indexOf(">>>");
    
        if(arrows < 0)
          return 0; 
        int end = remainder.lastIndexOf("<<<");
    
       String remainder = Request.substring( arrows, end ).trim();
    
       return remainder;
       }
    
  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    At a quick glance, yes that looks to be about what you want.

  • VirtEyes
    VirtEyes Posts: 62

    ok sweet, let me test it and the results. I will update on what I find