Service Virtualization

  • 1.  How to modify the original request and metadata from vsm

    Posted Sep 23, 2015 06:50 AM

    Hi,

     

    I was trying to modify the user name and password from the request calling virtual service (lisa.vse.request)

     

    To achieve i used the following code in dph filter

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

    String usernameStart="<wsse:Username>";

    String usernameEnd="</wsse:Username>";

     

    String passwordStart="#PasswordDigest\">";

    String passwordEnd="</wsse:Password>";

     

    String theBody = lisa_vse_request.getBodyText();

     

    if (theBody.contains(usernameStart)) {

     

      usernameBody=theBody.substring(theBody.indexOf(usernameStart),theBody.indexOf(usernameEnd)+usernameEnd.length());

      passwordBody=theBody.substring(theBody.indexOf(passwordStart),theBody.indexOf(passwordEnd)+passwordEnd.length());

     

    theBody = theBody.replace(usernameBody, "<wsse:Username>MODIFIEDRaku</wsse:Username>");

      theBody = theBody.replace(passwordBody, "#PasswordDigest\">MODIFIEDpassword=</wsse:Password>"); 

      testExec.setStateValue("lisa.vse.request", theBody);

    }

     

     

    but i noticed its changing the request body where as the lisa.vse.request still holds the old request

     

    in lisa as designed - the internal structure of the request property is (request+metadata) + (request body)

     

    Kindly let me know is there any inbuilt function available to modify entire request property ?

     

    Thanks,

    Ravikumar S.E



  • 2.  Re: How to modify the original request and metadata from vsm

    Posted Sep 28, 2015 02:05 AM

    Hi Ravi

     

    I am not able to understand what you are trying to achieve here. If username and password are arguments use the code to set arguments not the body.

    eg:

    ParameterList pl = lisa_vse_request.getArguments();

      String Username = pl.getParameter("username");

    You can user setParameterValue

    pl.setParameterValue(key, value)

     

    if not, username and password are part of body then use setbody to set the body only. Don't use setStateValue.

    lisa_vse_request.setBody(arg0);

     

    Hope that helps.



  • 3.  Re: How to modify the original request and metadata from vsm

    Posted Sep 29, 2015 05:42 AM

    HI Monika,

    Thanks for looking into this issue, I am trying to modify the request message reaching Virtual service (VSM) before sending it to other system (live system)

     

    I am using lisa as a router to redirect all the request reaching to VS - I am trying send the modified request message to live system.

     

    request.setBody will change only in request body, I am trying to send the modified request (request+metadata) + (request body) to other system.



  • 4.  Re: How to modify the original request and metadata from vsm

    Posted Sep 29, 2015 06:05 AM

    Use RDM to modify metadata.

     

    can u share sample request?

    1. Request

    2. Expected modified request after applying scriptable protocol.



  • 5.  Re: How to modify the original request and metadata from vsm

    Posted Sep 29, 2015 07:10 AM

    You can use any sample request and response:

     

    Client ---request msg---->Server

     

    Client----req---->Lisa---modified req----->Server

     

    create 2 VS - one as router and other as actual server

     

    ------sample req-----

     

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wssu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">

        <soapenv:Header>

            <wsse:Security>

                <wsse:UsernameToken>

                    <wsse:Username>user</wsse:Username>

                    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">mypassword=</wsse:Password>

                    <wsse:Nonce>NjQ3OTA5MzI4NzU=</wsse:Nonce>

                </wsse:UsernameToken>

            </wsse:Security>

        </soapenv:Header>

        <soapenv:Body>

            <Add xmlns="http://Example.org">

          <!--a is optional-->

                <a>1</a>

          <!--b is optional-->

                <b>1</b>

            </Add>

        </soapenv:Body>

    </soapenv:Envelope>

    ----

     

    lisa_vse_request is expected to carry modified request

     

    <soapenv:Header>

            <wsse:Security>

                <wsse:UsernameToken>

                    <wsse:Username>modififed </wsse:Username>

                    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">modified password</wsse:Password>

                    <wsse:Nonce>NjQ3OTA5MzI4NzU=</wsse:Nonce>

                </wsse:UsernameToken>

            </wsse:Security>

        </soapenv:Header>



  • 6.  Re: How to modify the original request and metadata from vsm

    Posted Sep 29, 2015 10:42 AM

    Hi Ravi,

     

     

     

     

    Once the request flows into virtual service, the request content,header information etc, which will store in property com.itko.lisa.vse.http.HTTPTransaction as mentioned below.

     

     

    com.itko.lisa.vse.http.HTTPTransaction[method=POST, uri=/, httpVersion=1.1, headers=User-Agent=Fiddler&Host=localhost:8081&Content-Length=973, request content=<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wssu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">

        <soapenv:Header>

            <wsse:Security>

                <wsse:UsernameToken>

                    <wsse:Username>user</wsse:Username>

                    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">mypassword=</wsse:Password>

                    <wsse:Nonce>NjQ3OTA5MzI4NzU=</wsse:Nonce>

                </wsse:UsernameToken>

            </wsse:Security>

        </soapenv:Header>

        <soapenv:Body>

            <Add xmlns="http://Example.org">

          <!--a is optional-->

                <a>1</a>

          <!--b is optional-->

                <b>1</b>

            </Add>

        </soapenv:Body>

    </soapenv:Envelope>]

     

     

     

     

    use the below code to construct the logic as per your requirement.

     

     

    import com.itko.lisa.vse.http.HTTPTransaction;

    import com.itko.lisa.vse.http.Transaction;

    HTTPTransaction transaction = ((HTTPTransaction) testExec.getStateObject("lisa.vse.http.current.transaction"));

     

    construct the logic to replace the username and password values as per your requirement

    transaction.getRequestContentAsString().replace("username", "u");

    transaction.getRequestContentAsString().replace("password", "p");

     

     

    testExec.setStateObject("lisa.vse.http.current.transaction",transaction);

    return testExec.getStateValue("lisa.vse.http.current.transaction");

     

     

    if you run your VSM in ITR you shall see the requestContent updated.

     

     

    Regards

    Nandeesha



  • 7.  Re: How to modify the original request and metadata from vsm

    Posted Jan 05, 2016 04:43 PM

    Hello Ravi,

     

              Please see the below link for a solution that i used when i faced a similar situation and let us know if it helps.

     

    Re: Modify argument values in request to send in LIVE SYSTEM/Image Validation mode?

     

    Thanks,

    Surya.



  • 8.  Re: How to modify the original request and metadata from vsm

    Community Manager
    Posted Sep 29, 2015 11:48 AM

    Ravi -- were you able to solve your challenge with the solutions offered?



  • 9.  Re: How to modify the original request and metadata from vsm

    Posted Aug 10, 2016 11:01 AM

    Yes, As VSE request is immutable , We created 2 VSMs to modify the request and forwarded the modified request to actual downstream system.