尝试配置“自定义SOAP采样器”时,JMeter groovy预处理器抛出异常

时间:2017-04-06 13:44:33

标签: soap groovy jmeter

我正在尝试为 ** Custom SOAP Sampler * 插件创建一个基于groovy的预处理器,该插件旨在涵盖以下任务:

  • 从csv输入文件中读取文件附件列表;
  • 清空当前使用 自定义SOAP采样器 注册的附件列表;
  • 使用 自定义SOAP采样器 注册从csv文件中读取的附件。

经过对网络的一些相当广泛的研究 - 我对整个groovy,java,jmeter话题完全陌生 - 我设法组装了如下所示的groovy脚本。

// read data from csv input file
ArrayList recLst = new ArrayList();
String fldsep = vars.get("fldsep");
String fldhd = vars.get("fldhd");

Integer i = 0; // TODO: test/debugging only
new File(vars.get("indat")).eachLine('UTF-8') {
    if ((it != null) && (fldhd != null) && (!it.trim().equals(fldhd.trim())) && (i < 2)) {
        recLst.add(it.trim());
    } // if
    i++; // TODO: test/debugging only
} // File.eachLine

// TODO: test/debugging only
for (rec in recLst) {
    String[] flds = rec.split(fldsep);
    vars.put("DBGtmstmp", flds[0]);
    vars.put("DBGprodid", flds[1]);
    vars.put("DBGtenid", flds[2]);
    vars.put("DBGfnam", flds[3]);
}

ArrayList oldAtts = new ArrayList();
oldAtts = ctx.getCurrentSampler().getAttachments();
vars.put("DBGoldatts", oldAtts.size());
// TODO: test/debugging only

// extract relevant parts and feed into Custom SOAP Sampler (registered attachments)
// csv format:  TMSTMP;PRODID;TENID;FNAM;MDAT
if (recLst.size() > 0) {
    // empty current attachment list
//  ArrayList oldAtts = ctx.getCurrentSampler().getAttachments();
//  vars.put("DBGoldatts", oldAtts.size()); // TODO: test/debugging only

    if (oldAtts.size() > 0) {
        for (attDef in oldAtts) {
            attDef.attachment = null; 
            attDef.contentID = null;
            attDef.contentType = null;
            attDef.type = null;
        } // for
    } // if

    // create new attachment list
    ArrayList newAtts = new ArrayList();

    for (rec in recLst) {
        String[] flds = rec.split(fldsep);

        def attDef = ctx.getCurrentSampler().getAttachmentDefinition();
        attDef.attachment = new File(flds[3]); 
        attDef.contentID = "flds[0]"; 
        attDef.contentType = "application/pdf"; // one of selections from the dropdown (no PDF listed there)
        attDef.type = 1;                        // 1 = resource, 2 = variable

        newAtts.add(attDef);
    } // for

    if (newAtts.size() > 0) {
        ctx.getCurrentSampler().setAttachments(newAtts);
    } // if
} // if

不幸的是,这似乎失败了,所以我添加了一些调试信息,例如。设置变量('DBG ....')。 'DBGtmstmp','DBGprodid','DBGtenid'和'DBGfnam'按预期设置,当尝试检索当前定义的附件并将'DBGoldatts'设置为找到的附件数时,抛出异常。

在我的groovy脚本(JSR223PreProcessor)上设置断点并启动调试器(BlazeMeter)产生

2017/04/06 14:50:28 INFO  - jmeter.engine.StandardJMeterEngine: Running the test! 
2017/04/06 14:50:28 INFO  - jmeter.samplers.SampleEvent: List of sample_variables: [] 
2017/04/06 14:50:28 INFO  - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : Number of Users (single key) 
2017/04/06 14:50:28 INFO  - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group Number of Users (single key). 
2017/04/06 14:50:28 INFO  - jmeter.engine.StandardJMeterEngine: Thread will continue on error 
2017/04/06 14:50:28 INFO  - jmeter.engine.StandardJMeterEngine: All thread groups have been started 
2017/04/06 14:50:28 INFO  - jmeter.threads.JMeterThread: Thread started: Number of Users (single key) 1-1 
2017/04/06 14:50:28 INFO  - jmeter.services.FileServer: Stored: /media/sf_Projects/tstprj/archive/tstdoc.csv 

继续执行测试计划(Step Over)生成

2017/04/06 14:54:45 ERROR - jmeter.modifiers.JSR223PreProcessor: Problem in JSR223 script JSR223 PreProcessor javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.blazemeter.jmeter.debugger.elements.SamplerDebug.getAttachments() is applicable for argument types: () values: []
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:155)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
    at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:220)
    at org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:42)
    at com.blazemeter.jmeter.debugger.elements.PreProcessorDebug.process(PreProcessorDebug.java:11)
    at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:798)
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:453)
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:418)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:249)
    at com.blazemeter.jmeter.debugger.engine.DebuggingThread.run(DebuggingThread.java:23)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.blazemeter.jmeter.debugger.elements.SamplerDebug.getAttachments() is applicable for argument types: () values: []
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:346)
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:152)
    ... 10 more
Caused by: groovy.lang.MissingMethodException: No signature of method: com.blazemeter.jmeter.debugger.elements.SamplerDebug.getAttachments() is applicable for argument types: () values: []
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
    at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
    at Script6.run(Script6.groovy:31)
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:343)
    ... 11 more

并在

中完成执行结果
2017/04/06 15:00:06 ERROR - com.jmeter.protocol.soap.sampler.CustomSOAPSampler: Caught exception while updating attachments javax.xml.soap.SOAPException: InputStream does not represent a valid SOAP 1.2 Message
    at com.sun.xml.internal.messaging.saaj.soap.ver1_2.SOAPPart1_2Impl.createEnvelopeFromSource(SOAPPart1_2Impl.java:72)
    at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.getEnvelope(SOAPPartImpl.java:128)
    at com.jmeter.protocol.soap.sampler.CustomSOAPSampler.updateAttachmentReferences(CustomSOAPSampler.java:448)
    at com.jmeter.protocol.soap.sampler.CustomSOAPSampler.sample(CustomSOAPSampler.java:256)
    at com.blazemeter.jmeter.debugger.elements.SamplerDebug.sample(SamplerDebug.java:15)
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:475)
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:418)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:249)
    at com.blazemeter.jmeter.debugger.engine.DebuggingThread.run(DebuggingThread.java:23)
    at java.lang.Thread.run(Thread.java:745)

2017/04/06 15:00:09 INFO  - jmeter.threads.JMeterThread: Stopping Thread: org.apache.jorphan.util.JMeterStopThreadException: Unable to update attachment references 
2017/04/06 15:00:09 INFO  - jmeter.threads.JMeterThread: Stop Thread detected by thread: Number of Users (single key) 1-1 
2017/04/06 15:00:09 INFO  - jmeter.threads.JMeterThread: Thread finished: Number of Users (single key) 1-1 
2017/04/06 15:00:09 INFO  - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test 
2017/04/06 15:00:09 INFO  - jmeter.services.FileServer: Close: /media/sf_Projects/tstprj/archive/tstdoc.csv 

我必须承认,我完全不知道如何解决这个问题。

我的设置包括:

  • Ubuntu Linux 17.04;
  • Apache JMeter 3.1 r1770033;
  • BlazeMeter Step-by-step Debugger 0.3;
  • Custom SOAP Sampler 1.3;
  • Groovy 2.4.7(脚本引擎2.0)。

示例输入csv文件

TMSTMP;PRODID;TENID;FNAM;MDAT
'20170406112044044970077';'PROD01';'TENANT03';'/media/sf_Projects/tstprj/archive/tstdoc/tstdoc-00000.pdf';'<?xml version=1.0 encoding=UTF-8?><tstpfx:metainformation xmlns:tstpfx=http://my.host.local/tstprj/metainformation_v2.xsd id=000000069496>meta data #01</tstpfx:metainformation>
'
'20170406112047030620037';'PROD02';'TENANT01';'/media/sf_Projects/tstprj/archive/tstdoc/tstdoc-00001.pdf';'<?xml version=1.0 encoding=UTF-8?><tstpfx:metainformation xmlns:tstpfx=http://my.host.local/tstprj/metainformation_v2.xsd id=000000069496>meta data #02</tstpfx:metainformation>
'

此文件被读取两次:(1)由 JSR223预处理器 构建附件列表; (2)通过 自定义SOAP采样器 ,随后迭代该文件的每个条目,并传递相关的位&amp;对SOAP Envelop的抨击

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tstprj="http://my.host.local/">
   <soapenv:Header/>
   <soapenv:Body>
      <tstprj:archive>
         <product>${PRODID}</product>
         <tenant>${TENID}</tenant>
         <filename>${FNAM}</filename>
         <metadata>${MDAT}</metadata>
         <content>cid:${TMSTMP}</content>
      </tstprj:archive>
   </soapenv:Body>
</soapenv:Envelope>

1 个答案:

答案 0 :(得分:0)

您应该在以下位置报告问题:

插件将Samplers包装到自定义的SamplerDebug中。

所以你的代码:

 ctx.getCurrentSampler()

返回SamplerDebug而不是此doc中提到的类:

  • JMeterSoapSampler

请参阅: