Service Virtualization

Expand all | Collapse all

How to inject a propertyValue from ListenerStep to ResponseSelection?

  • 1.  How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 16, 2019 10:13 AM

    How to inject a property value taken in a DataFilter_scriptableDataProtocol under VSListener, to be sent in the response message under ResponseSelection(VS Image). requestData is in ASCII.

     

    • able to capture the value in systemLogs using. used the below code in Scriptable DPH
      • String token = ascii.subString(1,5);
    • not able to send the value(token) in the response using VS Image.
      • Response
      • 9868707998769{{token}}, it's coming as text {{token}} in the response.
        What am i missing? Please help.


  • 2.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 16, 2019 11:31 AM

    Your variable "token" is only defined in the scope of the running script. You must store the property and its value in the testExec object (which is an object available and used by all steps in a flow to store and retrieve properties.

     

    So try this:

    • String token = ascii.subString(1,5);
    • testExec.setStateValue("token", token);

     

    Cheers,

    Danny



  • 3.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 16, 2019 11:58 AM

    Thanks for the response Danny.

    But, still the response comes with the {{token}} tag.

    Do i need to add anything to the responseSelection step in the modelVSM? (as i have given the reference for {{token}} only in the imageVSI so far)

    • Response
    • 9868707998769{{token}}


  • 4.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 16, 2019 12:07 PM

    No, if token is added as a property to testExec then as part of the flow the response will get parsed and {{token}} will be replaced with its value.

     

    I would like to rule out that "token" somehow is a property already used internally by DevTest (maybe for stateful Conversations and that it gets removed from te environmentat some point. Could you give your property a random name and let us know the outcome?

     

    Cheers,

    Danny



  • 5.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 16, 2019 12:41 PM

    No, result is still the same.

    • have changed "token" to "trnumber" in VSM-DPH as well as VSI, but no luck.
    • Response
      • 9868707998769{{trnumber}}


  • 6.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 16, 2019 12:52 PM

    Ok, something must be wrong somewhere, obviously, so it's root-cause analysis time :-)

     

    Are you sure your scriptable DPH doesn't throw a script error? You would see that in the VSE.log. If there's a script error the VSM would just continue with the processing, you wouldn't see that error anywhere from the outside

     

    Can you share the script? We might be able to see if something i wrong. 

     

    Or, if possible, run your vsm inside the ITR inside your workstation. Then send a request to that local port. In the ITR you can check in the properties pane whether or not "trnumber" was added to the environment (should be a green property as it was newly added to the testExec). also, in system messages, you can see script error logging if any. 

     

    Hope this helps,

     

    Cheers,

    Danny



  • 7.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 16, 2019 01:21 PM
    • I am sure, scriptable DPH did not throw any error.
    • Script:
      • String ascii = lisa_vse_request.getBodyText();
        String trnumber = ascii.substring(1,5);
        testExec.setStateValue("trnumber", trnumber);

        _logger.debug("{}", trnumber);

    • I am running it inside the ITR only for now.
      • i could see the property being added and can see the value being assigned as well.
      • No error in the system logs.


  • 8.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 16, 2019 02:39 PM

    If you can see the property being added with the correct value then we must turn attention to the vsi.

     

    Can you paste a snippet from the response where  you are using {{trnumber}}.

    Check if there is no space somewhere before or after the propertyname

     

    Cheers,

    Danny

     

    Outlook voor Android downloaden<https://aka.ms/ghei36>



  • 9.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 16, 2019 08:11 PM
    • No, there is no space as i could see.
    • Snippet from VSI Response(text)
      • 09868707998769{{trnumber}}51000771689R32           83[ETX]
      • ETX is the endOfTansaction delimiter and looks like a empty when seen in VSI.
    • to add more info from VSI.
      • there are 3 keys under MetaData
        • LittleEndian false
        • ByteAlign true
        • Payload.class String
    • i checked more on that in debug mode and able to see the trnumber if i remove the ETX from responseVSI, i can see the trnumber coming in the response.
      • but when ETX included, again the tag {{trnumber}} reappears in the response.


  • 10.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 17, 2019 01:13 AM

    At the start of trnumber there is no double curly brace, only a single one. Fix that, let us know any difference.

     

    Outlook voor Android downloaden<https://aka.ms/ghei36>



  • 11.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 17, 2019 01:38 AM

    That was just a typo in the discussion above.

    Else I have checked the issue only occurs, when I add the ETX delimiter to the responseVSI.



  • 12.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 17, 2019 02:31 AM

    Ok, so you identified what is causing the issue. I understand , since you are setting the ETX character, the broader context is that this is part of a TCP virtualization.

     

    I think you might have encountered a product issue here, I would open a support issue, and get a proper resolution for this.

     

    Now, as a potential work-around, the ETX-character will only be used in the TCP Listen and the TCP Respond step, so I would try to force a response parsing before the flow reaches the TCP Respond step.

     

    I would try something like:

     

       

    •   Add a scripted assertion to your ResponseSelection step

       

    •   Set assertion to fire when false, and then make sure the last statement of the script is return true; so that it never fires only executes the script.

     

    (this saves you from adding an additional script step to your VSM but if you use other execution modes beside efficient you will have to check if each execution mode passes via your newly added assertion)

     

       

    •   Try this line:

     

    lisa_vse_request.get(0).setBodyText(testExec.parseInState(lisa_vse_request.get(0).getBodyText()));

    The above line is from the top of my head, there might be syntax errors in there, the key part is the methode:  testExec.parseInState( ) which returns a String object where all double-curly braces are replaced if the property exists in testExec

     

    Cheers,

    Danny



  • 13.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 20, 2019 06:19 AM

    Hi Danny,

     

    lisa_vse_request.get(0).setBodyText(testExec.parseInState(lisa_vse_request.get(0).getBodyText()));

    • the above line did not work, moreover it refers to the request where in we are trying to put the {{trnumber}} in the response body.


  • 14.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?
    Best Answer

    Posted May 20, 2019 06:27 AM

    You are absolutely right (I believe I mentioned I did this from the top of my head, not?)

     

    Did you try?

     

    lisa_vse_response.get(0).setBodyText(testExec.parseInState(lisa_vse_response.get(0).getBodyText()));

     

     

    Cheers,

    Danny



  • 15.  Re: How to inject a propertyValue from ListenerStep to ResponseSelection?

    Posted May 20, 2019 07:32 AM

    thanks Danny, it worked...!!