JMeter groovy pre-processor throws exception when trying to empty “Custom SOAP Sampler”'s list of registered attachments -
i'm trying create groovy-based pre-processor (jsr223preprocessor) **custom soap sampler* plugin, intended cover following tasks:
- read list of file attachments csv input file;
- empty list of attachments registered custom soap sampler;
- register attachments read csv file custom soap sampler.
after quite extensive research on net--i'm new whole groovy, java, jmeter topic--, managed assemble groovy script shown below.
// read data csv input file arraylist reclst = new arraylist(); string fldsep = vars.get("fldsep"); string fldhd = vars.get("fldhd"); new file(vars.get("indat")).eachline('utf-8') { if ((it != null) && (fldhd != null) && (!it.trim().equals(fldhd.trim()))) { reclst.add(it.trim()); } // if } // file.eachline // extract relevant parts , feed 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(); if (oldatts.size() > 0) { (attdef in oldatts) { attdef.attachment = null; attdef.contentid = null; attdef.contenttype = null; attdef.type = null; } // } // if // create new attachment list arraylist newatts = new arraylist(); (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"; // 1 of selections dropdown (no pdf listed there) attdef.type = 1; // 1 = resource, 2 = variable newatts.add(attdef); } // if (newatts.size() > 0) { ctx.getcurrentsampler().setattachments(newatts); } // if } // if
in previous post faced issue blazemeter's step-by-step-debugger plugin, resolved not using it. challenge popped existence.
executing test plan results in error message, reading
unable update attachment references, see log files details.
having peek jmeter.log file reveals
<nul><nul><nul><nul><nul><nul><nul><nul>... ...<nul><nul><nul><nul>... ... 2017/04/07 09:14:47 info - jmeter.engine.standardjmeterengine: running test! 2017/04/07 09:14:47 info - jmeter.samplers.sampleevent: list of sample_variables: [] 2017/04/07 09:14:48 info - jmeter.gui.util.jmetermenubar: setrunning(true,*local*) 2017/04/07 09:14:48 info - jmeter.engine.standardjmeterengine: starting threadgroup: 1 : number of users (single key) 2017/04/07 09:14:48 info - jmeter.engine.standardjmeterengine: starting 1 threads group number of users (single key). 2017/04/07 09:14:48 info - jmeter.engine.standardjmeterengine: thread continue on error 2017/04/07 09:14:48 info - jmeter.threads.threadgroup: starting thread group number 1 threads 1 ramp-up 1 perthread 1000.0 delayedstart=false 2017/04/07 09:14:48 info - jmeter.threads.threadgroup: started thread group number 1 2017/04/07 09:14:48 info - jmeter.engine.standardjmeterengine: thread groups have been started 2017/04/07 09:14:48 info - jmeter.threads.jmeterthread: thread started: number of users (single key) 1-1 2017/04/07 09:14:48 info - jmeter.services.fileserver: stored: /media/sf_projects/tstprj/archive/tstdoc.csv 2017/04/07 09:14:48 error - jmeter.modifiers.jsr223preprocessor: problem in jsr223 script jsr223 preprocessor javax.script.scriptexception: javax.script.scriptexception: java.lang.illegalargumentexception: can not set int field com.jmeter.protocol.soap.control.gui.attachmentdefinition.type null value @ org.codehaus.groovy.jsr223.groovyscriptengineimpl.eval(groovyscriptengineimpl.java:155) @ javax.script.abstractscriptengine.eval(abstractscriptengine.java:233) @ org.apache.jmeter.util.jsr223testelement.processfileorscript(jsr223testelement.java:220) @ org.apache.jmeter.modifiers.jsr223preprocessor.process(jsr223preprocessor.java:42) @ org.apache.jmeter.threads.jmeterthread.runpreprocessors(jmeterthread.java:798) @ org.apache.jmeter.threads.jmeterthread.executesamplepackage(jmeterthread.java:453) @ org.apache.jmeter.threads.jmeterthread.processsampler(jmeterthread.java:418) @ org.apache.jmeter.threads.jmeterthread.run(jmeterthread.java:249) @ java.lang.thread.run(thread.java:745) caused by: javax.script.scriptexception: java.lang.illegalargumentexception: can not set int field com.jmeter.protocol.soap.control.gui.attachmentdefinition.type null value @ org.codehaus.groovy.jsr223.groovyscriptengineimpl.eval(groovyscriptengineimpl.java:346) @ org.codehaus.groovy.jsr223.groovyscriptengineimpl.eval(groovyscriptengineimpl.java:152) ... 8 more caused by: java.lang.illegalargumentexception: can not set int field com.jmeter.protocol.soap.control.gui.attachmentdefinition.type null value @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl.java:167) @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl.java:171) @ sun.reflect.unsafeintegerfieldaccessorimpl.set(unsafeintegerfieldaccessorimpl.java:80) @ java.lang.reflect.field.set(field.java:764) @ org.codehaus.groovy.reflection.cachedfield.setproperty(cachedfield.java:74) @ groovy.lang.metaclassimpl.setproperty(metaclassimpl.java:2669) @ groovy.lang.metaclassimpl.setproperty(metaclassimpl.java:3747) @ org.codehaus.groovy.runtime.invokerhelper.setproperty(invokerhelper.java:199) @ org.codehaus.groovy.runtime.scriptbytecodeadapter.setproperty(scriptbytecodeadapter.java:484) @ script13.run(script13.groovy:33) @ org.codehaus.groovy.jsr223.groovyscriptengineimpl.eval(groovyscriptengineimpl.java:343) ... 9 more 2017/04/07 09:14:49 error - com.jmeter.protocol.soap.sampler.customsoapsampler: caught exception while updating attachments javax.xml.soap.soapexception: inputstream not represent valid soap 1.2 message @ com.sun.xml.internal.messaging.saaj.soap.ver1_2.soappart1_2impl.createenvelopefromsource(soappart1_2impl.java:72) @ com.sun.xml.internal.messaging.saaj.soap.soappartimpl.getenvelope(soappartimpl.java:128) @ com.jmeter.protocol.soap.sampler.customsoapsampler.updateattachmentreferences(customsoapsampler.java:448) @ com.jmeter.protocol.soap.sampler.customsoapsampler.sample(customsoapsampler.java:256) @ org.apache.jmeter.threads.jmeterthread.executesamplepackage(jmeterthread.java:475) @ org.apache.jmeter.threads.jmeterthread.processsampler(jmeterthread.java:418) @ org.apache.jmeter.threads.jmeterthread.run(jmeterthread.java:249) @ java.lang.thread.run(thread.java:745) 2017/04/07 09:14:51 info - jmeter.threads.jmeterthread: stopping thread: org.apache.jorphan.util.jmeterstopthreadexception: unable update attachment references 2017/04/07 09:14:51 info - jmeter.threads.jmeterthread: stop thread detected thread: number of users (single key) 1-1 2017/04/07 09:14:51 info - jmeter.threads.jmeterthread: thread finished: number of users (single key) 1-1 2017/04/07 09:14:51 info - jmeter.engine.standardjmeterengine: notifying test listeners of end of test 2017/04/07 09:14:51 info - jmeter.services.fileserver: close: /media/sf_projects/tstprj/archive/tstdoc.csv 2017/04/07 09:14:51 info - jmeter.gui.util.jmetermenubar: setrunning(false,*local*)
apparently approach taken empty list of registered attachments leading kind of error, begging question how implement correct fashion (where these nul entries coming from, making apprximately 95% of whole log file?).
one tackled, 1 go..
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 getting read twice: (1) jsr223 pre-processor build attachment list; (2) custom soap sampler, subsequently iterates on each entry of file, , passes relevant bits & bobs 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>
Comments
Post a Comment