Search code examples
jmeterjmeter-pluginsjmeter-4.0

Zipping XML file in Jmeter


I need to create a xml file and then zip and upload. I am able to create xml file and upload but fail to zip the file. Can we zip xml files using Jmeter. Please let me know if anyone has a working code


Solution

  • There are multiple ways of archiving the file in JMeter, the easiest is calling 3rd-party program like zip or 7zip console archiver using OS Process Sampler.

    Alternatively you can use

    for generating a zip archive on the fly programmatically, example code would be something like:

    import org.apache.commons.io.IOUtils
    
    def xml = new File('/path/to/your/file.xml')
    
    def zip = new File('/path/to/created/archive.zip')
    
    def out = new java.util.zip.ZipOutputStream(new FileOutputStream(zip))
    
    out.putNextEntry(new java.util.zip.ZipEntry(xml.getName()))
    
    xml.withInputStream {
        IOUtils.copy(it, out)
    }
    
    IOUtils.closeQuietly(out)