Service Virtualization

 View Only
Expand all | Collapse all

Virtual Service Matching response

  • 1.  Virtual Service Matching response

    Posted Aug 29, 2019 07:03 AM
    Hi,

    Current:
    I have 5 specific transactions in a logical transaction which will be responded based on the incoming article number combinations. the default transaction is having a response which is magic string applied to send the articles whatever coming in the request. But because of this it always responds from meta (default) as the incoming article numbers rarely match with specific. 

    Expected:
    I will be having 5 specific transactions and the meta response but I want a random response picked from any one of these 5 specific transactions and the response should be parametrized with the article ids coming in the request. 

    Best Regards,
    Venkata Yedida 



  • 2.  RE: Virtual Service Matching response

    Posted Aug 29, 2019 08:21 AM
    Venkat,
    As you have incoming article number combinations, you can filter this and respond with any one of stored response using match script.





  • 3.  RE: Virtual Service Matching response

    Posted Aug 29, 2019 10:12 AM
    it is not possible because we get different articles, not the combination we have.


  • 4.  RE: Virtual Service Matching response

    Posted Aug 29, 2019 08:56 AM

    Hi,

     

    The matching algorithm doesn't allow for any randomly picking a response. So, some scripting would be needed.

     

    I would go about as follows:

    • In your VSI
      • Leave your 5 specific transactions
      • For your META
        • Set first response to the string META
        • Set second response to parameterized specific response 1, third response to parameterized specific response 2, etc... , until 6th response set to specific response 5

     

    Then add a scripted assertion to the response selection step (set fire on 'false')

     

    if (lisa_vse_response.get(0).getBodyText().equals("META"))

    {

    lisa_vse_response.set(0,lisa_vse_response.get(ThreadLocalRandom.current().nextInt(1, 5 + 1)));

    }

    return true;

     

    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: Virtual Service Matching response

    Posted Aug 29, 2019 11:14 AM
    Hi Danny,

    thanks for the reply.
    I have added this scripted assertion and still, I can see normal behavior.

    Best Regards,
    Venkata Yedida   



  • 6.  RE: Virtual Service Matching response

    Posted Aug 29, 2019 11:24 AM

    Can you put some vsi printscreens of your definition of the responses of your META transaction?

     

    If you have replaced the first response of your META with the actual text "META" instead of a real response then I fail to see how you can get normal behaviour because your consumers would actually receive the text "META" as a response?

     

    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.
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------





  • 7.  RE: Virtual Service Matching response

    Posted Aug 29, 2019 11:36 AM
    Edited by Venkat Yedida Aug 29, 2019 11:36 AM
    yes, I mean to say I am getting the response as meta. but i can see the script is failing because of below error,

    execution error so we assume false: javax.script.ScriptException: bsh.EvalError: Sourced file: inline evaluation of: ``// This script should return a boolean result indicating the assertion is true o . . . '' : Attempt to resolve method: current() on undefined variable or class name: ThreadLocalRandom : at Line: 4 : in file: inline evaluation of: ``// This script should return a boolean result indicating the assertion is true o . . . '' : ThreadLocalRandom .current ( )
    in inline evaluation of: ``// This script should return a boolean result indicating the assertion is true o . . . '' at line number 4-------------------------------------------
    i am using 10.5
    Original Message:
    Sent: 08-29-2019 11:24 AM
    From: Danny Saro
    Subject: Virtual Service Matching response

    Can you put some vsi printscreens of your definition of the responses of your META transaction?

     

    If you have replaced the first response of your META with the actual text "META" instead of a real response then I fail to see how you can get normal behaviour because your consumers would actually receive the text "META" as a response?

     

    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.
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



    Original Message------

    Hi Danny,

    thanks for the reply.
    I have added this scripted assertion and still, I can see normal behavior.

    Best Regards,
    Venkata Yedida   


  • 8.  RE: Virtual Service Matching response

    Posted Aug 29, 2019 11:39 AM

    My mistake, can you add the following line to the top of the script:

     

    Import java.util.concurrent.ThreadLocalRandom;

     

     

    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: Virtual Service Matching response

    Posted Aug 29, 2019 12:06 PM
    That's fine I might add it,

    I am still getting an error, I have verified that I am getting a random number generated and stored in int but after I am getting below error,


    Assertion name: Scripted Assertion checks for: false is of type: Assert by Script Execution.
    Script, // This script should return a boolean result indicating the assertion is true or false
    import java.util.concurrent.ThreadLocalRandom;

    if (lisa_vse_response.get(0).getBodyText().equals("meta"))
    {
    int boundedRandomValue = ThreadLocalRandom.current().nextInt(1, 5);
    lisa_vse_response.set(0,lisa_vse_response.get(boundedRandomValue));
    }
    return true; execution error so we assume false: javax.script.ScriptException: bsh.TargetError: Sourced file: inline evaluation of: ``// This script should return a boolean result indicating the assertion is true o . . . '' : Method Invocation lisa_vse_response.get : at Line: 7 : in file: inline evaluation of: ``// This script should return a boolean result indicating the assertion is true o . . . '' : lisa_vse_response .get ( boundedRandomValue )

    Target exception: java.lang.IndexOutOfBoundsException: Index: 3, Size: 1
    in inline evaluation of: ``// This script should return a boolean result indicating the assertion is true o . . . '' at line number 7


  • 10.  RE: Virtual Service Matching response

    Posted Aug 29, 2019 12:25 PM

    Have you added multiple responses for your META response? (I am not sure if that part of the solution is understood?)

     

    For your META transaction it should say "Response 1 of 6"

     

    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.
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------





  • 11.  RE: Virtual Service Matching response
    Best Answer

    Posted Aug 29, 2019 12:45 PM
    Hi,

    That error is resolved after adding this, I have faced metadata error but I have solved it. it is working.

    Thank you.


  • 12.  RE: Virtual Service Matching response

    Posted Aug 29, 2019 12:57 PM

    Ok, good to hear you got it working.

     

    As a reference for anyone reading this in the future: Indeed, I forgot to mention that when adding those additional responses to the META transaction, not only the response bodies need to be added but at a minimum also the response metadata of http status code and http status text.

     

    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.
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------