Service Virtualization

 View Only
Expand all | Collapse all

Response element to +1 on every request

  • 1.  Response element to +1 on every request

    Posted Jan 20, 2020 07:34 AM
    Hello,
    I want to see number of requests and they should be tracked in response.

    {
    "requestnumber": 1
    }

    Everytime there is a new request, requestnumber should add 1 and give the same in response.
    Please help on how to achieve this.


  • 2.  RE: Response element to +1 on every request

    Posted Jan 20, 2020 08:04 AM

    Hi,

     

    How "persistent" does this requestnumber have to be (the more persistent, the more difficult to implement).

    Is it ok if it is reinitialized when the virtual service is redeployed?

    Or is it ok when it is reinitialized when the VSE is recycled?

    Or does it need to be stored outside the SV platform such that it never reinitializes (until you specifically reset it)

     

    Is the "requestnumber" on the level of virtual service, ie. only one number even if there are many different transactions in your vsi?

    Or is the "requestnumber" on the level of the (specific) transactions?

     

    Cheers,

    Danny

     

    ::DISCLAIMER::

    The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents (with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates. Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of authorized representative of HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any email and/or attachments, please check them for viruses and other defects.






  • 3.  RE: Response element to +1 on every request

    Posted Jan 20, 2020 11:50 PM
    This is at each transaction level. Every time there is a new hit to the request URL, requestnumber should add 1 and give as response.


  • 4.  RE: Response element to +1 on every request

    Posted Jan 21, 2020 04:36 AM

    Hi,

     

    I guess there are many ways to solve this, here is something that could work.

     

    I made an assumption: this is a REST interface that is being virtualized, right? (because for SOAP interface the URL doesn't change for different transactions)

     

    Your requirement seems to suggest a 1-to-1 relationship between URL and transaction. In the vsi a transaction has a 1-to-1 relationship with a signature but not necessarily with the URL. For one URL there can exist more than one signature, specifically with POST requests.

     

    Below is an implementation that counts requests for the same URL, ie. the operation of the signature is the identifier for the count.

     

    Add a scriptable step between "VS Image Response Selection" and "Virtual HTTPS Responder", add following script:

     

           int request_number = 0;

           String request_id = "count " + lisa_vse_request.getOperation();

           String strNumber = null;

           strNumber = testExec.getStateValue(request_id);

           if (strNumber != null))

           {

               request_number = Integer.parseInt(strNumber)

           }

           request_number++;

           testExec.setStateValue(request_id, request_number);

     

     

    In your vsi, your responses should contain:

     

    {
    "requestnumber": {{request_number}}
    }

     

    Cheers,

    Danny

     

    ::DISCLAIMER::

    The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents (with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates. Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of authorized representative of HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any email and/or attachments, please check them for viruses and other defects.






  • 5.  RE: Response element to +1 on every request

    Posted Jan 21, 2020 05:15 AM
      |   view attached
    Hi Danny,

    Your understanding is absolutely right. This is a REST service and with POST method.
    Request you to clarify what do you mean by "

    Add a scriptable step between "VS Image Response Selection" and "Virtual HTTPS Responder""
    I am not able to find option to add scriptable step after VS Image Response Selection, I have attached print screen.

    Raghu!!




  • 6.  RE: Response element to +1 on every request

    Posted Jan 21, 2020 05:21 AM

    This printscreen should guide you:

     

     

     

    Cheers,

    Danny

     






  • 7.  RE: Response element to +1 on every request

    Posted Jan 21, 2020 05:45 AM
    Hi Danny,

    I have added the script. However, it is not returning number in the response, instead is giving as below.
    {
        "requestnumber": {{request_number}}
    }

    Inspection view log message says " THINK for 911"



  • 8.  RE: Response element to +1 on every request

    Posted Jan 21, 2020 07:03 AM

    Indeed, apologies, there was one statement missing at the end, the  property request_number itself was not added to the test execution environment:

     

           int request_number = 0;

           String request_id = "count " + lisa_vse_request.getOperation();

           String strNumber = null;

           strNumber = testExec.getStateValue(request_id);

           if (strNumber != null))

           {

               request_number = Integer.parseInt(strNumber)

           }

           request_number++;

           testExec.setStateValue(request_id, request_number);

           testExec.setStateValue("request_number", request_number);

     

     

    Cheers,

    Danny

     

    ::DISCLAIMER::

    The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents (with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates. Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of authorized representative of HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any email and/or attachments, please check them for viruses and other defects.






  • 9.  RE: Response element to +1 on every request

    Posted Jan 21, 2020 07:13 AM
    Hi Danny,

    It is working with first hit, but not giving +1 response for next requests. It is giving response as below again
    {
        "requestnumber": {{request_number}}
    }



  • 10.  RE: Response element to +1 on every request

    Posted Jan 21, 2020 07:19 AM
      |   view attached
    Uploading log as well

    Attachment(s)

    txt
    error.txt   3 KB 1 version


  • 11.  RE: Response element to +1 on every request

    Posted Jan 21, 2020 07:25 AM

    Thanks for the log, that helps.

     

    The fourth statement, can you add the casting to String so that it becomes:

     

    strNumber = (String) testExec.getStateValue(request_id);

     

     

    Cheers,

    Danny

     

    ::DISCLAIMER::

    The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents (with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates. Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of authorized representative of HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any email and/or attachments, please check them for viruses and other defects.






  • 12.  RE: Response element to +1 on every request

    Posted Jan 21, 2020 07:37 AM
      |   view attached
    it is still the same result, only first hit works. Attached is the log file.

    Attachment(s)

    txt
    error2.txt   4 KB 1 version


  • 13.  RE: Response element to +1 on every request
    Best Answer

    Posted Jan 21, 2020 07:59 AM

    Ok, apologies, doing this from top of head without help of Eclipse's semantic checking.

    Did you change the initialization of request_number to "1234567"? (if you did not then something strange happened)

     

    Please change statement 4 back to what is was, ie:

     

    strNumber = testExec.getStateValue(request_id);

     

    And change the second to last statement to:

     

    testExec.setStateValue(request_id, String.valueOf(request_number));

     

     

    The whole should look like:

     

    int request_number = 0;

    String request_id = "count " + lisa_vse_request.getOperation();

    String strNumber = null;

    strNumber = testExec.getStateValue(request_id);

    if (strNumber != null)

    {

        request_number = Integer.parseInt(strNumber)

    }

    request_number++;

    testExec.setStateValue(request_id, String.valueOf(request_number));

    testExec.setStateValue("request_number", request_number);

     

     

     

     

    Cheers,

    Danny

     

    ::DISCLAIMER::

    The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents (with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates. Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of authorized representative of HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any email and/or attachments, please check them for viruses and other defects.






  • 14.  RE: Response element to +1 on every request

    Posted Jan 21, 2020 08:03 AM

    Oh, and there is a semi-colon missing at the end of the statement in the if-block

     

                  request_number = Integer.parseInt(strNumber);

     

     

    Cheers,

    Danny

     

    ::DISCLAIMER::

    The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents (with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates. Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of authorized representative of HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any email and/or attachments, please check them for viruses and other defects.






  • 15.  RE: Response element to +1 on every request

    Posted Jan 21, 2020 08:16 AM
    Hi Danny,

    I had changed this to "12345678" as per requirement. This script worked and respective results are achieved.
    Thank you very much for your fantastic support and time taken to resolve my query. 

    Raghu!!


  • 16.  RE: Response element to +1 on every request

    Posted May 07, 2020 07:02 AM
    Hi Danny,
    will this script which adds +1 for every response work for XML payloads as well OR it is only limited only for JSON payloads.

    I have same requirement to create virtual service using XML Payload. Please suggest.

    Raghu!!



  • 17.  RE: Response element to +1 on every request

    Posted May 07, 2020 07:14 AM

    Hi Raghu,

     

    Yes, this piece of scripting should work also for XML payloads. It is independent from data protocol and/or transport protocol. It only manipulates properties, one for each operation called "count <operationName>" and another one called "request_number".

     

    Cheers,

    Danny

     

    ::DISCLAIMER::

    The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents (with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates. Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of authorized representative of HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any email and/or attachments, please check them for viruses and other defects.