0

I have an EDIFACT message, which looks something like this:

AAA:+.? '
ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'
DEF+ABCD+LH+FVKJUB+20000:2042+Y1234567+UN+D:21B'
GHI+1+ABCD:D:11A:AA:ABCD+ABCD12345678901123ABC123456'
JKL+745'
HHH+TN:IIAA891011213531235BNM422244:::001'
CCC+NT+++ABCDEFGHIJKLMNOPQRS'
STU+00123456789012:UF+0000000000:GY'
VXY+50+MI1234+++MI'
AAA+235+ABC'
BBB+200:3202062000:301'
FFF+90+USA'
BBB+232:2101051135:201'
CCC+FF+++AaBaBa001:TEST1'
DDD+3++G'
EEE+329:711013'
FFF+178+XXX'
FFF+179+YYY'
GGG+2+ZZZ'
HHH+BXG:ABCDEF'
HHH+ABC:12AB3E01234E8UD8'
III+P:110:111+100000001'
EEE+36:281105'
FFF+91+ASD'
VVV+50:2'
XXX+0011+1'
YYY+1+U0123456'
ZZZ+1+U1234560002'

Using a Jmeter JSR223 Sampler, I need to send it as a payload to an IBM MQ message queue.

I am trying to put this message in a variable so that I can pass it around, but I am getting errors because of all the special characters it contains.

def sessInboundQueue = System.getProperties().get("SessionInbound")
def destinationInboundQueue = System.getProperties().get("DestinationInbound")
def producer = sessInboundQueue.createProducer(destinationInboundQueue) 

def payload = "AAA:+.? '
ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'
DEF+ABCD+LH+FVKJUB+20000:2042+Y1234567+UN+D:21B'
GHI+1+ABCD:D:11A:AA:ABCD+ABCD12345678901123ABC123456'
JKL+745'
HHH+TN:IIAA891011213531235BNM422244:::001'
CCC+NT+++ABCDEFGHIJKLMNOPQRS'
STU+00123456789012:UF+0000000000:GY'
VXY+50+MI1234+++MI'
AAA+235+ABC'
BBB+200:3202062000:301'
FFF+90+USA'
BBB+232:2101051135:201'
CCC+FF+++AaBaBa001:TEST1'
DDD+3++G'
EEE+329:711013'
FFF+178+XXX'
FFF+179+YYY'
GGG+2+ZZZ'
HHH+BXG:ABCDEF'
HHH+ABC:12AB3E01234E8UD8'
III+P:110:111+100000001'
EEE+36:281105'
FFF+91+ASD'
VVV+50:2'
XXX+0011+1'
YYY+1+U0123456'
ZZZ+1+U1234560002'"
def msg = sessInboundQueue.createTextMessage(payload)

This is the error:

    Script87.groovy: 9: Unexpected input: '"' @ line 9, column 15.
   def payload = "AAA:+.? '
JustNatural
  • 375
  • 7
  • 19
  • what `String.format()` is doing in your code? show the real code instead of `ThatStringAbove`... – daggett Oct 26 '21 at 19:07
  • I updated the question. That String.format() method had no place there. Thanks for asking about it. Still the problem remains. I need to put that wall of text into a variable. – JustNatural Oct 26 '21 at 19:20
  • multiline string in groovy must be tripple-quoted: `""" miltilline groovy string """` or `''' multiline java string '''` – daggett Oct 26 '21 at 19:22
  • Wow, as simple as that! thanks a lot. You can write an answer if you want and I will accept your solution. – JustNatural Oct 26 '21 at 19:26

2 Answers2

2

multiline string in groovy must be tripple-quoted:

GString (with interpolation support)

def payload = """AAA:+.? '
ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'
DEF+ABCD+LH+FVKJUB+20000:2042+Y1234567+UN+D:21B'
...
"""

String (plain java string)

def payload = '''AAA:+.? '
ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'
DEF+ABCD+LH+FVKJUB+20000:2042+Y1234567+UN+D:21B'
...
'''
daggett
  • 26,404
  • 3
  • 40
  • 56
1

You need to escape special characters like quotation marks, line breaks, etc.

Something like:

def payload = "AAA:+.? '\n" +
        "ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'\n" +
        "DEF+ABCD+LH+FVKJUB+20000:2042+Y1234567+UN+D:21B'\n" +
        "GHI+1+ABCD:D:11A:AA:ABCD+ABCD12345678901123ABC123456'\n" +
        "JKL+745'\n" +
        "HHH+TN:IIAA891011213531235BNM422244:::001'\n" +
        "CCC+NT+++ABCDEFGHIJKLMNOPQRS'\n" +
        "STU+00123456789012:UF+0000000000:GY'\n" +
        "VXY+50+MI1234+++MI'\n" +
        "AAA+235+ABC'\n" +
        "BBB+200:3202062000:301'\n" +
        "FFF+90+USA'\n" +
        "BBB+232:2101051135:201'\n" +
        "CCC+FF+++AaBaBa001:TEST1'\n" +
        "DDD+3++G'\n" +
        "EEE+329:711013'\n" +
        "FFF+178+XXX'\n" +
        "FFF+179+YYY'\n" +
        "GGG+2+ZZZ'\n" +
        "HHH+BXG:ABCDEF'\n" +
        "HHH+ABC:12AB3E01234E8UD8'\n" +
        "III+P:110:111+100000001'\n" +
        "EEE+36:281105'\n" +
        "FFF+91+ASD'\n" +
        "VVV+50:2'\n" +
        "XXX+0011+1'\n" +
        "YYY+1+U0123456'\n" +
        "ZZZ+1+U1234560002'\n"

should do the trick for you.

You may also be interested in IBM MQ testing with JMeter - Learn How article

Dmitri T
  • 159,985
  • 5
  • 83
  • 133