Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JSR223 Pre Processor code should run for only HTTP Sampler

I have a JSR223 Preprocessor code given below:

String method = sampler.getMethod(); 

JMeter Test Plan given below:

      - JSR223 Pre Processor
      - HTTP Sampler
      - JSR223 Sampler / Any other sampler apart from HTTP

As JSR223 PreProcessor will apply to all the Samplers in the hierarchy, it gives below error for all the Samplers apart from HTTP Sampler.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

2022-05-18 17:32:43,668 ERROR o.a.j.m.JSR223PreProcessor: Problem in
JSR223 script, JSR223 PreProcessor javax.script.ScriptException:
groovy.lang.MissingMethodException: No signature of method:
org.apache.jmeter.protocol.java.sampler.JSR223Sampler.getMethod() is
applicable for argument types: () values: []
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320)
~[groovy-jsr223-3.0.7.jar:3.0.7]
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71)
~[groovy-jsr223-3.0.7.jar:3.0.7]
at javax.script.CompiledScript.eval(CompiledScript.java:89) ~[java.scripting:?]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:217)
~[ApacheJMeter_core.jar:5.4.3]
at org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:45)
[ApacheJMeter_components.jar:5.4.3]
at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:965)
[ApacheJMeter_core.jar:?]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:549)
[ApacheJMeter_core.jar:?]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489)
[ApacheJMeter_core.jar:?]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256)
[ApacheJMeter_core.jar:?]
at java.lang.Thread.run(Thread.java:834) [?:?] Caused by: groovy.lang.MissingMethodException: No signature of method:
org.apache.jmeter.protocol.java.sampler.JSR223Sampler.getMethod() is
applicable for argument types: () values: []
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:70)
~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
~[groovy-3.0.7.jar:3.0.7]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
~[groovy-3.0.7.jar:3.0.7]
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase$getMethod.call(Unknown
Source) ~[?:?]
at Script1366.run(Script1366.groovy:1) ~[?:?]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317)
~[groovy-jsr223-3.0.7.jar:3.0.7]
… 9 more

I want my JSR223 code to run only for HTTP Sampler

>Solution :

Check if HTTP Sampler before:

if (sampler instanceof org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) { 
   String method = sampler.getMethod(); 
}

Similar code in JMeter

if (testElement instanceof HTTPSamplerBase) {
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading