Service Virtualization

 View Only
  • 1.  how to convert zip file to byte content

    Posted Sep 26, 2018 05:27 AM

    Hi All,

    Requirement is  : while sending the response back, VS should zip or compress the responseXML (which is very huge) and convert the compressed or zip file into byte message and send back the byte content of the zip file to the consumer application. 

     

    Transport protocol of the VS is MQ.

     

    is this requirement doable in DevTest? if so. please suggest the approach.

    J_NeSmith 

     

    Thanks,

    Sumalatha



  • 2.  Re: how to convert zip file to byte content
    Best Answer

    Broadcom Employee
    Posted Sep 26, 2018 07:25 AM

    Yes, this is doable.

     

    One way to do it, you need to add a “Scriptable Data Protocol” as the Response Side Dataprotocol

     

    From the top of my head - meaning the below might not be correct at all – here is something mixed up from some zipping-a-string-stuff that I grabbed from StackOverflow. It could go something like this:

     

    import com.itko.util.ParameterList;

    import java.io.ByteArrayOutputStream;

    import java.io.IOException;

    import java.util.zip.GZIPOutputStream;

    import java.util.zip.*;

     

    // Get the response payload

    String theBody = lisa_vse_response.getBodyText();

     

    // Zip the response payload string

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    GZIPOutputStream gzip = new GZIPOutputStream(out);

    gzip.write(theBody.getBytes());

    gzip.close();

     

    // Set the response payload as binary

    lisa_vse_response.setBodyBytes(out.toByteArray());

     

     

    Hope this helps,

     

    Cheers,

    Danny



  • 3.  Re: how to convert zip file to byte content

    Posted Sep 28, 2018 06:04 AM

    Thanks Danny for your reply. i will try and let you know.