java - JMeter not decoding base64 correctly - Results in blank PDF -
in jmeter, base64 encoded pdf in response extract using regex extractor. working great.
then need decode base64 encoded document , write out file, i'm doing following in beanshell post processor:
import org.apache.commons.io.fileutils; import org.apache.commons.codec.binary.base64; // set response variable string response = vars.get("documenttext"); // remove carriage return hex code , condense single string string encodedfile = response.replace("
","").replaceall("[\n]+",""); // decode encoded string vars.put("decodedfile",new string(base64.decodebase64(encodedfile))); // write out decoded file output = vars.get("decodedfile"); f = new fileoutputstream("c:\\users\\user\\desktop\\decodedfile.pdf"); p = new printstream(f); this.interpreter.setout(p); print(output); p.flush(); f.close();
my problem file gets decoded , written out opens blank pdf.
in troubleshooting this, wrote out file encoded string jmeter , manually decoded using this base64 tool. when manually decoded file, opened expected.
i compared text of file produced jmeter , 1 decoded tool , noticed file produced jmeter included random ?'s throughout
i assuming must culprit, however, not know causing these show or how fix it.
jmeter not decoding base64 correctly because jmeter cannot decode base64. if using custom code suggest code first.
given need magic:
string encodedfile = response.replace("
","").replaceall("[\n]+","");
my expectation either regular expression or server response shitty
- given use scripting-based post-processor ain't gonna need "regex" interim step, should able access parent sampler response beanshell postprocessor via
data
shorthand
so great script can optimized like:
fileutils.writebytearraytofile(new file("c:\\users\\user\\desktop\\decodedfile.pdf"), base64.decodebase64(data));
as fallback option can execute decb64.exe
program using os process sampler.
Comments
Post a Comment