Service Virtualization

 View Only
  • 1.  Execute script (JSR-223) – Created script to slice request header value is not working, Please help

    Posted May 26, 2020 07:53 AM

    Request

    GET /REST/SO?searchDate=2020-05-19

    Authorization: security 123456

     

    Expected Response

    {

        "id": "123456", (This value is from request header with "security" string removed)

    }

     

    I have created below JSR Script after VS Image Response Selection

     ---------------------------------------------------------------------------------------------------

    var strauthorization = testExec.getStateValue("Authorization_val");

    strauthorization = strauthorization.substring(7, strauthorization.length());

    testExec.setStateValue("strauthorization",strauthorization);

    ------------------------------------------------------------------------------------------------------ 

    This script is not working and attached is the log file from inspection view

     

    Kindly help to solve this issue.

     

    Attachment(s)

    txt
    JSR-Script_errorlog.txt   4 KB 1 version


  • 2.  RE: Execute script (JSR-223) – Created script to slice request header value is not working, Please help

    Posted May 26, 2020 08:22 AM
    Hi,

    Logs states:
    ... : strauthorization .length ( )
    Target exception: java.lang.NullPointerException: Null Pointer in Method Invocation

    So, it seems that the property "Authorization_val" does not exist at the time when this script is executed. Can you let us know by what method did you get the value of header "Authorization" into the property with name "Authorization_val"?

    The header values are found in the metadata property list of the incoming request object (lisa_vse_request) and a Request Data Copier DPH would have been the easiest way to copy the value into a property inside TestExec.





    ------------------------------
    Cheers,
    Danny
    ------------------------------
    Architect
    HCL Enterprise Studio
    ------------------------------
    ------------------------------



  • 3.  RE: Execute script (JSR-223) – Created script to slice request header value is not working, Please help

    Posted May 26, 2020 10:00 AM
      |   view attached
    Hi Danny,
    I have tried using Data Copier DPH. I am not able to understand where is the issue.
    I have attached print screens of VSI and VSMs from Workstation. Request you to suggest me what is going wrong.
    Thanks & Regards, Raghu!!

    Attachment(s)

    msg
    DevTest Issue - Script.msg   387 KB 1 version


  • 4.  RE: Execute script (JSR-223) – Created script to slice request header value is not working, Please help

    Posted May 26, 2020 10:31 AM
    Hi,

    The way how you configured the RDC DPH it looks to me the property would be called "AuthorizationAuthorizationAuthorization_val"
    Because
    • you defined "Authorization" as pre-fix
    • "Authorization" is the name of the metadata argument itself
    • you defined "Authorization_val" as post-fix

    Try the RDC DPH with
    • prefix: <blank>
    • postfix: _val
    then the name will be "Authorization_val" and your original scripts should work:

    var strauthorization = testExec.getStateValue("Authorization_val");

    strauthorization = strauthorization.substring(7, strauthorization.length());

    testExec.setStateValue("strauthorization",strauthorization);



    ------------------------------
    Cheers,
    Danny
    ------------------------------
    Architect
    HCL Enterprise Studio
    ------------------------------
    ------------------------------



  • 5.  RE: Execute script (JSR-223) – Created script to slice request header value is not working, Please help
    Best Answer

    Posted May 26, 2020 11:03 AM
    Edited by Christopher Hackett May 29, 2020 04:02 PM
    Use as below for RDC (Same could be achieved using RDM as well- the script may be slightly diff for that)





    Thanks.


    ------------------------------
    Regards,
    Vaibhav Jain
    Capgemini
    ------------------------------



  • 6.  RE: Execute script (JSR-223) – Created script to slice request header value is not working, Please help

    Posted May 26, 2020 01:25 PM
    Thank you very much Vaibhav for your fantastic support. Thank you for taking your time to test by yourself and giving me the solution. It worked ..


  • 7.  RE: Execute script (JSR-223) – Created script to slice request header value is not working, Please help

    Posted May 26, 2020 01:26 PM
    It worked Danny. Thank you for your quick and excellent support.


  • 8.  RE: Execute script (JSR-223) – Created script to slice request header value is not working, Please help

    Posted May 26, 2020 08:42 AM
    Hi Raghu,

    You have to set the value of "Authorization_val" using RDM first then you can apply above logic to create a substring to remove "security " from the entire value.



    ------------------------------
    Regards,
    Vaibhav Jain
    Capgemini
    ------------------------------