Search code examples
performance-testingjmeter-5.0

JSR223 Sampler return Response same as Request for EDIFACT message in JMeter


JSR223 Sampler return Response same as Request for EDIFACT message. Request:

def payload = "UNB+IATA:1+1S+XX+121103+FF168019110033++ETK1+O'\n" +
"UNH+1+TKCREQ:00:1:IA'\n" +
"MSG+:131'\n" +
"ORG+1S+99999999:X7HH+VZX++T+GR+CXN'\n" +
"TKT+676713121:T'\n" +
"UNT+5+1'\n" +
"UNZ+1+FF168019110033

Response:

"UNB+IATA:1+1S+XX+121103+FF168019110033++ETK1+O'\n" +
"UNH+1+TKCREQ:00:1:IA'\n" +
"MSG+:131'\n" +
"ORG+1S+99999999:X7HH+VZX++T+GR+CXN'\n" +
"TKT+676713121:T'\n" +
"UNT+5+1'\n" +
"UNZ+1+FF168019110033

Log:

2023-02-07 15:33:39,890 DEBUG o.a.j.p.t.s.TCPSampler: Created org.apache.jmeter.protocol.tcp.sampler.TCPSampler@4a6c4b41
2023-02-07 15:33:39,912 DEBUG o.a.j.p.t.s.TCPSampler: Created org.apache.jmeter.protocol.tcp.sampler.TCPSampler@7bd45f7b
2023-02-07 15:33:39,939 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2023-02-07 15:33:39,939 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2023-02-07 15:33:39,942 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2023-02-07 15:33:40,147 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2023-02-07 15:33:40,147 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2023-02-07 15:33:40,147 INFO o.a.j.e.StandardJMeterEngine: Thread will start next loop on error
2023-02-07 15:33:40,147 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 perThread=1000.0 delayedStart=false
2023-02-07 15:33:40,150 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2023-02-07 15:33:40,150 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2023-02-07 15:33:40,150 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2023-02-07 15:33:40,162 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2023-02-07 15:33:40,162 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2023-02-07 15:33:40,162 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2023-02-07 15:33:40,162 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

SampleResult fields:
ContentType:
DataEncoding: windows-1252

Steps followed:

  1. Set up TCP in JMeter properties:
  • tcp.handler=TCPClientImpl
  • eolByte = 111
  • tcp.eolByte=1000
  • tcp.charset=
  • tcp.status.prefix=Status=
  • tcp.status.suffix=.
  • tcp.binarylength.prefix.length=2
  1. TCP Sampler Config
  • TCPClient classname=TCPClientImpl
  • Servername=xxxxxx
  • Port: 3432
  • Timeouts: Connect(2000ms,)Response: 2000ms
  • Reuse Connection -enabled
  1. JSR223 Sampler Payload Request :
def payload = "UNB+IATA:1+1S+XX+121103+FF168019110033++ETK1+O'\n" +
"UNH+1+TKCREQ:00:1:IA'\n" +
"MSG+:131'\n" +
"ORG+1S+99999999:X7HH+VZX++T+GR+CXN'\n" +
"TKT+676713121:T'\n" +
"UNT+5+1'\n" +
"UNZ+1+FF168019110033'

Solution

  • If this code:

    def payload = "UNB+IATA:1+1S+XX+121103+FF168019110033++ETK1+O'\n" +
    "UNH+1+TKCREQ:00:1:IA'\n" +
    "MSG+:131'\n" +
    "ORG+1S+99999999:X7HH+VZX++T+GR+CXN'\n" +
    "TKT+676713121:T'\n" +
    "UNT+5+1'\n" +
    "UNZ+1+FF168019110033"
    

    is the complete code for the JSR223 Sampler - it does absolutely nothing.

    If you want to send it over TCP you need to put the payload into "Text to send" field of the TCP Sampler:

    enter image description here

    If you want to send the "payload" using JSR223 Sampler you need to add the relevant code to do it, the simplest one is:

    def payload = "UNB+IATA:1+1S+XX+121103+FF168019110033++ETK1+O'\n" +
            "UNH+1+TKCREQ:00:1:IA'\n" +
            "MSG+:131'\n" +
            "ORG+1S+99999999:X7HH+VZX++T+GR+CXN'\n" +
            "TKT+676713121:T'\n" +
            "UNT+5+1'\n" +
            "UNZ+1+FF168019110033"
    
    def socket = new Socket('xxxxxx', 3432)
    
    socket.withStreams { input, output ->
        log.info(input.newReader().readLine())
        output << payload
    }
    

    The output will go to jmeter.log file.

    More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?