Closed Sil68 closed 7 years ago
Would be, but requires coding either in the sampler or coding in the script inside JMeter. Sampler does not provide that currently.
Is this something I potentially could achieve on my own, given that I'm barely familiar with Java, and having no knowledge whatsoever of Groovy (but having some programming experience eg in R, Python and shell scripting)?
How would I go about it?
===================== Sent from my Sinclair ZX Spectrum 128
On 4 Apr 2017, at 16:08, Lukasz W notifications@github.com wrote:
Would be, but requires coding either in the sampler or coding in the script inside JMeter. Sampler does not provide that currently.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
You can achieve this by adding beanshell or other type of script, as block in jMeter scenario, and inside it by putting "for" loop that would read the attachment path from csv and then attach it to the request. If there is issue with parsing csv file easily you could look for libraries that enable you do that, in order to serialize the csv, namely to make an object out of it.
Brilliant! Thanks a bunch!
On 4 Apr 2017, at 17:07, Lukasz W notifications@github.com wrote:
You can achieve this by adding beanshell or other type of script, as block in jMeter scenario, and inside it by putting "for" loop that would read the attachment path from csv and then attach it to the request. If there is issue with parsing csv file easily you could look for libraries that enable you do that, in order to serialize the csv, namely to make an object out of it.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
How would I remove all already registered attachments from the sampler, in case I'm inclined to build up the attachment list from scratch?
I'm trying to create a groovy-based pre-processor for *Custom SOAP Sampler plugin, which is intended to cover to following tasks:
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:
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 JSR233 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>
I suspect that this part you did:
if (oldAtts.size() > 0) {
for (attDef in oldAtts) {
attDef.attachment = null;
attDef.contentID = null;
attDef.contentType = null;
attDef.type = null;
} // for
} // if
is incorrect. Either you need to do this different way or most probably you don't need to clean the list of attachments for given sampler block at all, because you specify the attachments for the sampler programmatically here:
ctx.getCurrentSampler().setAttachments(newAtts);
I suspect that when you set attachments with empty list you will achieve your goal. But then you set attachments again so this seems redundant step.
Is it possible to read in a csv file, and for each line of this file, create a corresponding attachment entry?