J.S Lee
J.S Lee

Reputation: 29

Jmeter decompress gzip response

I write performance test script with JMeter, but the target site using gzip to compress response. So Jmeter can't display any response and only show EOFException.

java.io.EOFException
    at java.base/java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:269)

To solve this problem. I write JSR223 PostProcessor for decompress response, but my script always show "Not in GZIP format" message.

java.util.zip.ZipException: Not in GZIP format

I don't have any idea about this message. Please help me.

This is my "JSR223 PostProcessor" script.

import java.util.zip.GZIPInputStream;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

byte[] responseBody = prev.getResponseData();
ByteArrayOutputStream decompressBaos = new ByteArrayOutputStream();
try(InputStream gzip = new GZIPInputStream(new ByteArrayInputStream(responseBody))) {
    int b;
    while ((b = gzip.read()) != -1) {
        decompressBaos.write(b);
    }
}catch(Exception ex){
    log.info("Exception:"+ex);
}

byte[] decompressed = decompressBaos.toByteArray();
prev.setResponseData(decompressed); 

response header

Upvotes: 0

Views: 619

Answers (1)

Dmitri T
Dmitri T

Reputation: 168042

Are you sure the response is in GZIP format? In order to be able to request it in GZIP you need to add HTTP Header Manager and configure it to send Accept-Encoding header with the value of gzip,deflate

Upvotes: 1

Related Questions