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 to Properly Extract Values from Incoming Request Header

VirtEyes
VirtEyes Posts: 62

I have a case where I would need to extract a couple values from the incoming request and parameterize it in the response.

I am not entirely clear on how to do this in Virtualize, as the docs page regarding the Header Data Bank Tool offers more information regarding its usage in SOAtest and not in Virtualize.

What is the proper way of receiving the incoming request header (usually by a third party tool like SOAPUI) and then extract the values accordingly within Virtualize? Is it through usage of the Header Data Bank? If so, what are the correct steps towards extracting the specific values / variables and then use them in parameterization in the response code?

The incoming request is in JSON format and is looks like this:
{ X-Source-Host-Name=danJohn.place.com, X-Provider-Service=commerce, X-Channel=YJGYUGYUGY, X-Trace-Id=abc123, X-Source-Timestamp=2021-07-01T10:13:17.485, X-Provider-Operation=POST, X-Provider-Version=1.0.0, Content-Type=application/json }

And I would like to extract values like X-Trace-Id and X-Source-Timestamp

Best Answer

  • benken_parasoft
    benken_parasoft Posts: 1,281 ✭✭✭
    Answer ✓

    When I use the Header Databank Tool, it does not provide me a list of headers, rather it is blank.

    Yes but that doesn't matter. In the Header Data Bank, click "Add Header". Select the header you just added then click "Modify". Put the name of the header in the Name field.

    Since you mentioned it may need extension tool usage to extract this value

    I don't know, since I don't completely understand your scenario. In my last comment, I suggested several different things depending on what you are actually doing.

Answers

  • benken_parasoft
    benken_parasoft Posts: 1,281 ✭✭✭
    edited July 2021

    Is it through usage of the Header Data Bank?

    Yes. You chain a Header Data Bank to the responder's "Incoming Request > Transport Header" output. It works for extracting HTTP headers, request headers or response headers, client tools or message responder tools.

    what are the correct steps towards extracting the specific values / variables

    In the Header Data Bank, click "Add Header". Select the header you just added then click "Modify". Put the name of the header in the Name field. Notice that you also provide a unique "column name" for each extraction. You will use each extraction's unique column name to parmaeterize your response.

    All "Data Bank" tools basically work the same in this sense.

    and then use them in parameterization in the response code?

    To use a data bank column in some field somewhere you would type ${variable_or_column_name} in that field where "variable_or_column_name" would be the column name you configured for one of the headers you are extracting in your Header Data Bank. If the field you want to parameterize has Fixed/Parameterized/Scripted combo box then you can also select Parameterized which will let you select the desired data bank column.

    How you parameterize fields basically works the same, regardless of whether this is a data bank column or a data source column or responder suite variable.

    The incoming request is in JSON format and is looks like this

    Where is this JSON document? If it is part of the message body then you would use a JSON Data Bank chained to the "Incoming Request > Payload" output instead.

    If you are saying this JSON document is the value of a HTTP header then the Header Data Bank would extract the entire JSON document. To extract specific values from the JSON, you may need to use an Extension Tool to return the data bank column value then chain a JSON Data Bank to parse the JSON after that. I don't have step-by-step instructions for this but this is a high level summary of what you might do in this case.

  • VirtEyes
    VirtEyes Posts: 62

    Hey Benken,

    Thank you for your suggestion, I have seen how it is sent and it is a case of extracting request header values and parameterizing them in the responder transport headers.

    When I use the Header Databank Tool, it does not provide me a list of headers, rather it is blank.

    Since you mentioned it may need extension tool usage to extract this value, I do need step by step instructions as necessary, in order to select the appropriate variables from the header and be able to parameterize them in the response.

    Can you please best advise on how to do this?

  • VirtEyes
    VirtEyes Posts: 62

    In the Header Data Bank, click "Add Header". Select the header you just added then click "Modify". Put the name of the header in the Name field.

    Got ya, however I need to have two values extracted from the header and it appears I am only able to list one.

    I don't know, since I don't completely understand your scenario. In my last comment, I suggested several different things depending on what you are actually doing.

    So what is going on is that the incoming request has a bunch of headers, I need to get two variables from it, like ID and date, and parameterize them in the response headers. So if there is a way, similar to JSON / XML data banks, where I just input in the headers and then just select which ones I wish to extract and then go from here.
    If this is possible without usage of the extension tool, that would be ideal.

    I hope this makes sense now

  • VirtEyes
    VirtEyes Posts: 62

    Scratch that, I can now add headers to the Header Data Bank. So are you advising to just add the headers that way, list the name of the headers and attribute them to a custom column name and the value should be extracted?

  • VirtEyes
    VirtEyes Posts: 62

    Benken you were correct, the right tool to use is the Header Data Bank Tool

    So to use it in Virtualize, just press Add Header then Modify as per your suggestions, and just list out the header name that is to be extracted and assign it a custom column name. From there, its just normal parameterization.

    Everything is working properly now. Thank you for everything!