1

Does anyone know a solution to decode a base 64 format string in JMeter?

I have to decode the a response, but i don't want to reinvent the wheel...

Do i have to write the code by myself (hope not)?

Thanks

luistm
  • 1,027
  • 4
  • 18
  • 43
  • That's fine. Do you have problem in doing that? If not then everything is Ok. AFAIK, it is pretty good and popular open-source library. If you prefer Python you can use Python means http://stackoverflow.com/questions/8908287/base64-encoding-in-python-3 – olyv Jan 06 '14 at 18:53
  • I would prefer to use python, but, AFAIK, there is no jmeter plugin. – luistm Jan 07 '14 at 09:19
  • Not exactly Python but Jython. http://jmeter.512774.n5.nabble.com/Using-Python-or-Ruby-from-Jmeter-td5716088.html and http://www.jython.org/jythonbook/en/1.0/index.html – olyv Jan 07 '14 at 20:12

2 Answers2

5

Your solution is pretty good. However you can use Beanshell Post Processor and refer previous sampler response data as data (see JMeter Pre-defined Beanshell variables section)

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

vars.put("decoded_response", new String(Base64.decodeBase64(data)));
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
3

My current solution is:

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

log.info("Decoding base64 format");

String response = "b3JpZ2luYWwgU3RyaW5nIGJlZm9yZSBiYXNlNjQgZW5jb2RpbmcgaW4gSmF2YQ==";
byte[] decoded_response = Base64.decodeBase64(response);
log.info(new String(decoded_response));

Which is based on the solution provided by http://javarevisited.blogspot.pt/2012/02/how-to-encode-decode-string-in-java.html .

EDIT: Check Dmitri solution for more details.

Thanks

luistm
  • 1,027
  • 4
  • 18
  • 43