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.

Using Extension Tool to capture the request code

VirtEyes
VirtEyes Posts: 62

I have an instance where I need to capture the incoming request, and find part of the code marked by an unique identifier and return it as my request for my responders. How can I code this effectively?

Here is the code I have so far that I got from another application, but not sure if it works in Virtualize:

function setRequest()
{
MyRequest = context.incomingRequest("lisa.Listen.rsp");

MyNewRequest = "";


if (MyRequest!=null && MyRequest.indexOf("CDATA")>0){

    MyNewRequest = MyRequest.substring(MyRequest.indexOf("CDATA[")+6,MyRequest.indexOf("]]"));
    return MyNewRequest;

}else {
    return MyRequest;
}

}

Comments

  • williammccusker
    williammccusker Posts: 640 ✭✭✭

    Hi,
    It looks like that code is searching for the first text in an xml document that is wrapped in CDATA and returning the text value without the CDATA wrapper. I wonder if it might be simpler to just use a data bank to extract the text from the desired xml node. Do you know what field in the request that code would find?

  • VirtEyes
    VirtEyes Posts: 62

    That part of the xml code will contain the entire xml request that is needed for the responders

  • williammccusker
    williammccusker Posts: 640 ✭✭✭

    Hi,
    Is the initial request also xml? You might be able to use something like an XML Transformer chained to the incoming request to extract the "payload" text from the initial payload and return the contents as xml.

  • VirtEyes
    VirtEyes Posts: 62

    correct, the overarching request is also xml. It just has a field within that contains the request code that I need for the response

  • VirtEyes
    VirtEyes Posts: 62

    So if I use the XML transformer and extract that element, will it be used as the request for my responders?

  • williammccusker
    williammccusker Posts: 640 ✭✭✭

    Hi,

    It can be, there is an option under the "Misc" tab of the responder in "Request Handling" that says "Allow incoming request tools to modify the message"

    Or you can chain tools directly to the output of the XML transformer to act on the output directly, e.g. data banks. Which one works best will depend on your responders situation: data source correlation vs data banking.