Share this page

# Implement callbacks

For a list of protocols that support asynchronous communication, see 64-bit recording, Async, and IPv6 support.

After VuGen scans a Vuser script for asynchronous communication, the Async tab of the Design Studio lists the asynchronous conversations that were found in the script. For each asynchronous conversation found during the scan, VuGen adds the callback function signatures matching those declared in the web_reg_async_attributes step. The signatures are added to the AsyncCallbacks.c extra file.

The names of the callback functions start with the conversation ID of the asynchronous conversation. For example, the RequestCB callback for an asynchronous conversation with ID “LongPoll_0” will be LongPoll_0_RequestCB.

The names of the callback functions are declared in the web_reg_async_attributes step in the script.

The available callbacks are:

- RequestCB

  This callback is called before a request is sent.

- ResponseBodyBufferCB

  This callback is called when there is content in the response body buffer and at the end of the response body. This callback is generated by VuGen automatically for push-type conversations, but is available for poll and long-poll conversations as well.

- ResponseCB

  This callback is called after every response is received in the conversation.

Example 1:

In the following sample code, the callback functions are declared in the web_reg_async_attributes step.

Copy code

    /*Added by Async CodeGen.
    ID=LongPoll_0
    ScanType = Recording
    The following URLs are considered part of this conversation:
    http://your_URL.com/request.ashx?key=111111-11
    http://your_URL.com/request.ashx?key=111111-11
    http://your_URL.com/request.ashx?key=111111-11
    http://your_URL.com/request.ashx?key=111111-11

    TODO - The following callbacks have been added to AsyncCalIbacks.c.
    Add your code to the callback implementation as necessary.
        LongPoll_0_RequestCB
        LongPoll_0_ResponseC8
    */

        web_reg_async_attributes("ID: LongPoll_0",)
            "URL: http://your_URL.com/request.ashx?key=111111-11",
            "Pattern=LongPoll"
            "RequestCB=LongPoll_0_RequestCB",
            "ResponseCB=LongPoll_0_ResponseCB",
            LAST);

Example 2:

In the following sample code, the two callbacks are implemented in the AsyncCallbacks.c extra file.

Copy code

    int LongPoll_0_RequestCB()
    {
      //enter your implementation for RequestCB() here

      //call web_util_set_request_url() here to modify polling url:
      //web_util_set_request_url("<request_url>");

      //call web_util_set_request_body() here to modify request body:
      //web_util_set_request_body("<request_body>");

        return WEB_ASYNC_CB_RC_OK;
    }

    int LongPoll_0_ResponseCB(
        const char *    aResponseHeadersStr,
        int             aResponseHeadersLen,
        const char *    aResponseBodyStr,
        int             aResponseBodyLen,
        int             aHttpStatusCode)
    {

        //enter your implementation for ResponseCB() here

        return WEB_ASYNC_CB_RC_OK;
    }

You can modify the callbacks to implement the required behavior. For details, see Modify callbacks.

Example 3:

The following sample code shows an implementation of the ResponseHeaders callback function, including the three arguments: HTTP Status code, Accumulated headers string, and Accumulated headers string length.

Copy code

    int Push_0_ResponseHeadersCB(

       int aHttpStatusCode,
       const char * aAccumulatedHeadersStr,
       int aAccumulatedHeadersLen)
    {

           //Enter your implementation for ResponseHeadersCB() here.

           lr_output_message("Response status code is :[%d]", aHttpStatusCode);
           lr_output_message("Response headers are :/n[%s]", aAccumulatedHeadersStr);

    return WEB_ASYNC_CB_RC_OK;
    }

A sample of the output from the above callback function is shown below:

Response status code is :[200]

Response headers are :

[HTTP/1.1 200 OK

Connection: close

Date: Tue, 25 Jun 2013 09:03:33 GMT

Server: Microsoft-IIS/6.0

Content-Type: text/html

Cache-control: private]

https://admhelp.microfocus.com VuGen,Professional Performance Engineering,Performance Engineering for Developers 8942
Tips to improve your search results... OpenText™ Virtual User Generator Help Center OpenText™ VuGen Help 26.1-26.3 All View Local Help Center View Online Help Center Version: