Need to convert hex to string in jmeter

Go down

Need to convert hex to string in jmeter

Post  manohara on Tue Apr 22, 2014 1:46 pm


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?




Posts : 1
Join date : 2014-04-22

View user profile

Back to top Go down

Re: Need to convert hex to string in jmeter

Post  glinius on Wed Jun 04, 2014 8:50 pm

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:

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,



Posts : 6
Join date : 2013-10-23

View user profile

Back to top Go down

Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum