JSR223采样器返回与JMeter中的EDIFACT消息请求相同的响应。

huangapple go评论40阅读模式
英文:

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

问题

JSR223 Sampler 返回的响应与请求相同,用于EDIFACT消息。

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

步骤已经按照以下方式执行:

  1. 在JMeter属性中设置TCP:

    • tcp.handler = TCPClientImpl
    • eolByte = 111
    • tcp.eolByte = 1000
    • tcp.charset =
    • tcp.status.prefix = Status =
    • tcp.status.suffix = .
    • tcp.binarylength.prefix.length = 2
  2. TCP Sampler配置

    • TCPClient类名 = TCPClientImpl
    • 服务器名称 = xxxxxx
    • 端口:3432
    • 超时:连接(2000毫秒),响应:2000毫秒
    • 重用连接 - 启用
  3. JSR223 Sampler
    请求负载:

    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'"
    
英文:

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'

答案1

得分: 0

以下是翻译好的部分:

如果这段代码:

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"

JSR223 Sampler的完整代码 - 它实际上什么都不做。

如果您想通过TCP发送它,您需要将有效载荷放入TCP Sampler的“Text to send”字段中:

JSR223采样器返回与JMeter中的EDIFACT消息请求相同的响应。

如果您想使用JSR223 Sampler发送“payload”,您需要添加相关的代码来执行它,最简单的代码如下:

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
}

输出将会保存在jmeter.log文件中。

有关JMeter中Groovy脚本的更多信息:Apache Groovy: Groovy 用途是什么?

英文:

If this code:

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

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:

JSR223采样器返回与JMeter中的EDIFACT消息请求相同的响应。

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 = &quot;UNB+IATA:1+1S+XX+121103+FF168019110033++ETK1+O&#39;\n&quot; +
        &quot;UNH+1+TKCREQ:00:1:IA&#39;\n&quot; +
        &quot;MSG+:131&#39;\n&quot; +
        &quot;ORG+1S+99999999:X7HH+VZX++T+GR+CXN&#39;\n&quot; +
        &quot;TKT+676713121:T&#39;\n&quot; +
        &quot;UNT+5+1&#39;\n&quot; +
        &quot;UNZ+1+FF168019110033&quot;

def socket = new Socket(&#39;xxxxxx&#39;, 3432)

socket.withStreams { input, output -&gt;
    log.info(input.newReader().readLine())
    output &lt;&lt; payload
}

The output will go to jmeter.log file.

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

huangapple
  • 本文由 发表于 2023年2月8日 09:57:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75380701.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定