0

I'm writing a load test that sends Time Stamping Requests to a Time Stamping Authority.

This is a standard protocol, described in rfc3161. This requires a POST execution, sending a small ASN1 object, that is binary.

I'm using Jmeter to generate the traffic. Now, I have written the groovy part that sets up the ASN1 object, and that creates the bytes[] array, but I cannot copy it to a variable, because the casting to a string modifies the content. However I cannot find any other way to pass this content.

Given the amount of traffic I have to generate, writing to a file and then attaching it is not a viable solution.

Is there any other way to work around this issue?

Cœur
  • 37,241
  • 25
  • 195
  • 267
sbos61
  • 554
  • 2
  • 9
  • can you give more details and code? you're writing groovy code, not java? You mean `new String(bytes)` modifies the content? – Curiosa Globunznik Feb 08 '20 at 11:57
  • The code I'm testing is: byte[] asn1seq = newReq.getEncoded(); String strArg = new String(asn1seq); The byte[] array is 48 byte long, the string has 92 chars – sbos61 Feb 08 '20 at 15:31
  • This is not surprising at all: you should not cast an arbitrary array of byte into a string – sbos61 Feb 08 '20 at 15:37
  • Without your original input it is hard to guess, what's going on. But you're not casting, you're creating a new string the proper way from a byte[]. There's another constructor for String which accepts the `byte[]` and the `Charset`, try to pass the proper encoding and see what's happening then. 92 chars fron 48 bytes sounds rather strange, though. – Curiosa Globunznik Feb 09 '20 at 16:32

1 Answers1

0

After some test (and some good suggestion), the solution came out converting the bytes array to a string using an 8-bit encoding like iso-8859-1. Here is the code:

byte[] asn1seq = asn1Object.getEncoded();
String strArg = new String(asn1seq, "ISO-8859-1");

Also, you have to set the same encoding into the Jmeter sampler configuration mask: enter image description here

sbos61
  • 554
  • 2
  • 9