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 preprocess request body before it is processed by virtual asset for correlation

Options

Hello, I would like to preprocess modify request body (e.g., remove blank spaces etc) before the requests is processed by the virtual asset message responders for correlation. may i use groovy extension tool for this purpose or is there any other way of achieving this. if using groovy extension tool, code snipped will be helpful. thank you.

Answers

  • williammccusker
    williammccusker Posts: 718 ✭✭✭
    Options

    Hi,

    I would recommend adding the Extension tool to the Pre-correlation Incoming Request so that your script runs before Responder correlations.

  • alemayehu_bofa
    Options

    thanks for the response. do you have a code snippet on how to retrieve the incoming request body, modify it somehow and then save it back to be used in responder correlation.

  • williammccusker
    williammccusker Posts: 718 ✭✭✭
    Options

    Hi,

    The easiest way I found was to to use a Text Bank chained to the Pre-correlation Extension tool

    Here is the script in the Extension tool
    `import com.parasoft.api.Application

    def modify(input, context) {
    payload = input.toString()

    Application.showMessage("Payload: " + payload)
    payload = payload.replaceAll("hello", "world")
    Application.showMessage("Modified: " + payload)
    return payload
    }`

    Here is the xpath that uses the data bank column modified payload
    '${modified}' = '{"greeting": "world"}'

    Screenshot of the chained tools

  • alemayehu_bofa
    Options

    thanks William