1
votes

I'm trying to create a groovy-based pre-processor for **Custom SOAP Sampler* plugin, which is intended to cover to following tasks:

  • read a list of file attachments from a csv input file;
  • empty the list of attachments currently registered with the Custom SOAP Sampler;
  • register the attachments read from the csv file with the Custom SOAP Sampler.

After some quite extensive research on the net--I'm completely new to whole groovy, java, jmeter topic--, I managed to assemble the groovy script shown below.

// 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

Unfortunately this appears to be failing, so I've added some debugging information, eg. setting variables ('DBG....'). 'DBGtmstmp', 'DBGprodid', 'DBGtenid', and 'DBGfnam' are getting set as expected, when trying to retrieve the currently defined attachments and set 'DBGoldatts' to the number of attachments found, an exception is thrown.

Setting a breakpoint at my groovy script (JSR223PreProcessor) and starting the debugger (BlazeMeter) yields

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 

continuing test plan execution (Step Over) produces

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

and finishing the execution results in

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 

I have to admit, I'm utterly at a loss, as how to tackle this issue.

My setup comprises:

  • 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 (scripting engine 2.0).

Sample input csv file

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>
'

This file is getting read twice: (1) by the JSR223 pre-processor to build the attachment list; (2) by the Custom SOAP Sampler, which subsequently iterates over each entry of this file, and passes the relevant bits & bobs to the 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
Please see api, there is no such method for Sample Interface. jmeter.apache.org/api/index.html?org/apache/jmeter/samplers/…Rao
@Rao When looking at the corresponding GitHub wiki page of the "Custom SOAP Sampler", there this particular sampler call is mentioned in an example. I've also found this at a different site (IT Quality)as an example.user4338

1 Answers

0
votes

You should report an issue at :

The plugin wraps Samplers into a custom SamplerDebug.

So your code :

 ctx.getCurrentSampler()

Returns a SamplerDebug instead of the class mentioned in this doc:

  • JMeterSoapSampler

See: