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.

Accessing incoming request bytes from an Extension Tool

Options
jesantos
jesantos Posts: 14

I am using a TCP custom jar as listener to get a pack of streamed bytes, bytes are received as expected, however, I need to send a byte stream as response too. I can generate the response bytes using an Extension Tool attached to the responder’s Outgoing Response.

However, the script also needs access to the incoming request payload, which is also binary data.

The script currently receives an ExtensionToolContext parameter. I know I can use context.get(...) to retrieve values stored in variables, but I am not sure how to store the original incoming request bytes in a variable first.

Would a Data Bank preserve the raw bytes, or would it convert the payload to text? If Data Banks only store string values, what is the recommended way to access the original incoming binary payload from an Extension Tool attached to the outgoing response?

Tagged:

Answers

  • williammccusker
    williammccusker Posts: 711 ✭✭✭
    Options

    Hi,

    Is the extension tool being chained to the incoming request? If so can you call getBytes on the input text to get the original bytes of the message?

  • benken_parasoft
    benken_parasoft Posts: 1,391 ✭✭✭
    Options

    This is what has worked for me, chaining an Extension Tool to the "Incoming Request" output (Groovy):

    import com.parasoft.api.Application
    import com.parasoft.api.ExtensionToolContext
    
    void handleRequest(String input, ExtensionToolContext context) {
        byte[] originalBytes = input.getBytes('ISO-8859-1')
        Application.showMessage('got bytes: ' + originalBytes.length)
    }
    

    The "context" object also has "put" and "get" methods so you can store and later retrieve arbitrary objects including byte arrays.