Service Virtualization

  • 1.  CA Devtest 8.0.1: Looking for a step to convert xml to Base64 encoded string and then to Base64 decode.

    Posted Jan 11, 2017 07:04 PM

    Hi, I need to Base64 encode xml and then post it as HTML request. Please let me know how to Base64 encode XML. 

    Also would need to decode the Base64 encoded string. 

    LISA has step to Base64 encode file but my need is to do it for XML. Please advise. Thanks. 



  • 2.  Re: CA Devtest 8.0.1: Looking for a step to convert xml to Base64 encoded string and then to Base64 decode.

    Posted Jan 12, 2017 11:20 AM

    Is it possible for you to add a JSR-223 step to perform the action?  Haven't tried this in the latest versions of DevTest.

    Assume that a prior step created a property called "flatXML" and that contains your XML.

    import com.itko.lisa.remote.utils.Base64;

    message = testExec.getStateValue("flatXML");

    String encodedMessage = (String) Base64.encode( message.getBytes() );

    testExec.setStateValue("encodedMsg", encodedMessage); 

    return encodedMessage;

     

    In a different step, decode the encoded message

    import com.itko.lisa.remote.utils.Base64;

    encodedMessage =  (String) testExec.getStateValue("endodedMsg");

    byte[] decodedMessage = Base64.decode( encodedMessage );

    String msg = new String( decodedMessage );

    testExec.setStateValue("decodedMsg", msg); 

    return msg;



  • 3.  Re: CA Devtest 8.0.1: Looking for a step to convert xml to Base64 encoded string and then to Base64 decode.
    Best Answer

    Posted Jan 19, 2017 06:40 PM

    Thank you so much Joel. I could use the code with slight tweaking. Also it wasn't working in JSR223 so added JavaScript step and it worked.  

    I used the below code to encode and decode.

    import org.apache.commons.codec.binary.Base64;

    String message = testExec.getStateValue("Input_PA_Req");

    String encodedMessage = new String(Base64.encodeBase64(message.getBytes()));

    testExec.setStateValue("encodedMsg", encodedMessage);

     

    byte[] decodedMessage = Base64.decodeBase64(encodedMessage.getBytes());

    String msg = new String(decodedMessage);

    testExec.setStateValue("decodedMsg", msg);


    return encodedMessage;



  • 4.  Re: CA Devtest 8.0.1: Looking for a step to convert xml to Base64 encoded string and then to Base64 decode.

    Posted Jan 19, 2017 04:04 PM

    Jyoti,

     

    Did Joel's response help you out with your questions?