Need to convert hex to string in jmeter
2 posters
Page 1 of 1
Need to convert hex to string in jmeter
Hi,
For a test I use the regex to retrieve a hex data. I have to use this hex value
as a parameter. To do this I have to convert the hex value to string Could you please help in in letting to know how to tackle this?
Thanks,
Manohara.KS
manohara- Posts : 1
Join date : 2014-04-22
Re: Need to convert hex to string in jmeter
If you need to pass hex exactly as it is, you don't need to do any sort of conversion.
However if next step assumes passing converted hex, you will need to use Hex class which has decodeHex() method.
In i.e. Beanshell Pre Processor added as a child of request which needs to send hex string you can use the following code:
The code above assumes that your Regular Expression Extractor uses "myHex" as "Reference Name". Converted hex is stored as "myHexString". You will be able to access it as ${myHexString} or ${__V(myHexString)} wherever required.
See How to use BeanShell guide for more details on JMeter extension with scripting.
Hope this helps,
Dmitri.
However if next step assumes passing converted hex, you will need to use Hex class which has decodeHex() method.
In i.e. Beanshell Pre Processor added as a child of request which needs to send hex string you can use the following code:
- Code:
import org.apache.commons.codec.binary.Hex; // import necessary class
String hexString = vars.get("myHex"); // get "myHex" variable as string
byte[] bytes = Hex.decodeHex(hexString.toCharArray()); // decode it from hex
vars.put("myHexString", (new String(bytes, "UTF-8"))); // save result to a new variable called "myHexString"
The code above assumes that your Regular Expression Extractor uses "myHex" as "Reference Name". Converted hex is stored as "myHexString". You will be able to access it as ${myHexString} or ${__V(myHexString)} wherever required.
See How to use BeanShell guide for more details on JMeter extension with scripting.
Hope this helps,
Dmitri.
glinius- Posts : 6
Join date : 2013-10-23
Similar topics
» BeanShell assertion unable hold data in array
» Jmeter if condition is not working
» JMeter Interview Questions
» Execution of Jmeter
» Results in jmeter
» Jmeter if condition is not working
» JMeter Interview Questions
» Execution of Jmeter
» Results in jmeter
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum