Service Virtualization

  • 1.  Live Invocation "Replacement URI"

    Posted Aug 17, 2016 03:33 PM

    I need to create a variable containing a substring of the actual URI for use in the "Replacement URI" field in the Live Invocation Step.  I see that I can add a Scriptable Data Protocol Handler in the VRS.  I don't, however, quite understand the syntax for getting the URI and setting the new variable.

     

    Here's an example of what I am needing to do:

     

    Current URI:   https://responder.mycompany.com:4000/application_name/service_name/operation_name/version

     

    Want to strip out "/application_name" and pass just the following to the live invocation:

     

    /service_name/operation_name/version

     

    Any ideas?

     

    Thanks in advance,

     

    Jeff Tucker



  • 2.  Re: Live Invocation "Replacement URI"

    Posted Aug 19, 2016 08:27 AM

    Hi Jeff, try adding a scriptable DPH in the LISTEN Step to get the URI from the incoming request's MetaData and then perform your logic on it.

    Once a property is set in TestExec, you can use the property {{ }} notation, in the example below {{fl_newURI}}, in the Live Invocation Step to use the value.

     

    %beanshell%

    import com.itko.util.ParameterList;

    ParameterList metadata = lisa_vse_request.getMetaData();

    String sUri = metadata.get("HTTP-URI") ;

     

    < Add logic to split & build the override URI >

     

    testExec.setStateValue("fl_newURI", <overrideUriVariableGoesHere>);

     

    In the VRS file, the logic will go inside the CDATA tag.  The safest way to get this into the VRS is to use Workstation to perform the recording, set up the protocol handlers, and right before finalizing the recording, CLICK the small folder Icon above the Finish button and save the VRS file.  You can hand roll the VRS, but that is a bit more challenging.  The resulting VRS will contain an XML block that looks something like this:

     

     

    :

    :

    <Protocol type="com.itko.lisa.vse.stateful.protocol.scriptable.ScriptableDataProtocolHandler">

            <updateRequestScript><![CDATA[%beanshell%

    import com.itko.util.ParameterList;

    ParameterList metadata = lisa_vse_request.getMetaData();

    String sUri = metadata.get("HTTP-URI") ;

     

    < Add logic to split & build the override URI >

     

    testExec.setStateValue("fl_newURI", <overrideUriVariableGoesHere>);

    ]]>

            </updateRequestScript>

        </Protocol>

    </RequestSide>

    </Transport>

    :

    :

    :

     

    I am not exactly sure which property in the Live Invocation holds the replacement value.  It may be something like <replacementUri> or <replacementURI>.



  • 3.  Re: Live Invocation "Replacement URI"

    Posted Aug 20, 2016 04:42 PM

    Hi Joel,

     

    Thanks for the information.  I have added the DPH, including the code to strip the top-level of the context.  That seems to be running (no errors in Inspection View).  But, I am not sure because I do not see any reference to the new variable anywhere.  Is there some way to make it show up as an event in Inspection View?

     

    I've added the variable reference in the VRS using <replacementUri>{{fl_newURI}}</replacementUri>.however it doesn't appear to save the reference.  When I download the .mar to inspect the generated .vsm that Replacement URI field remains empty.

     

    Jeff Tucker



  • 4.  Re: Live Invocation "Replacement URI"

    Posted Aug 20, 2016 06:22 PM

    The goal here is to essentially strip out the <basePath> value from the responder URL so that just the remaining portion of the URI is passed to the back end system.  Perhaps there's a better way to go about that.  My goal in doing this is so that I can place multiple development teams on the same port, segmented by <basePath>.  In order for the live invocation to work properly in all cases, the expected URI needs to be sent to the backend (obviously without the context used to separate applications).

     

    e.g.

    https://my.responder.url.com:50000/<application>/<expected_live_invocation_uri>/<other_path_info>

    would be passed to the live invocation as:

    https://live.invocation.url.com/<expected_live_invocation_uri>/<other_path_info>

     

    Seems like it would be a useful feature.  Thanks,

     

    Jeff Tucker



  • 5.  Re: Live Invocation "Replacement URI"

    Posted Aug 23, 2016 08:07 AM

    Try running your service in ITR mode and sending a request so you can use the Events tab to see the data that is contained in the meta data when the request is processed.

    You can also add displays by adding logging lines in your DPH.  The _logger writes lines of output to the Workstation.log if running in ITR or vse.log if running the service on the VSE.  You can also see these lines in the Event tab if you are running in ITR as well.  The scripting guide that has been posted has more background on logging.

     

    Three examples are shown below so you can get an idea of how the logger works with and without variables:

    // logging with no parameters

    _logger.info(" <<<<  entering my logic ");

    ParameterList metaData = lisa_vse_request.getMetaData();

    // logging with one parameter

    _logger.info(" <<<<  value of HTTP-URI in MetaData is: {}", metadata.get("HTTP-URI") );

      :

      :

    // logging with multiple parameters

    _logger.info(" <<<< value of HTTP-URI is: {} and the fl_newURI is: {}",

                 metadata.get("HTTP-URI"),

                 testExec.getStateValue("fl_newURI") );