1 | public class BeanShellPostProcessor extends BeanShellTestElement ↵ | | 1 | public class BeanShellPreProcessor extends BeanShellTestElement↵
|
2 | implements Cloneable, PostProcessor, TestBean↵ | | 2 | implements Cloneable, PreProcessor, TestBean↵
|
3 | {↵ | | 3 | {↵
|
4 | private static final Logger log = LoggingManager.getLoggerForClass();↵ | | 4 | private static final Logger log = LoggingManager.getLoggerForClass();↵
|
5 | ↵ | | 5 | ↵
|
6 | private static final long serialVersionUID = 4;↵ | | 6 | private static final long serialVersionUID = 4;↵
|
7 | ↵ | | 7 | ↵
|
8 | // can be specified in jmeter.properties↵ | | 8 | // can be specified in jmeter.properties↵
|
9 | private static final String INIT_FILE = "beanshell.postprocessor.init"; //$NON-NLS-1$↵ | | 9 | private static final String INIT_FILE = "beanshell.preprocessor.init"; //$NON-NLS-1$↵
|
|
10 | protected String getInitFileProperty() {↵ | | 10 | protected String getInitFileProperty() {↵
|
11 | return INIT_FILE;↵ | | 11 | return INIT_FILE;↵
|
12 | }↵ | | 12 | }↵
|
13 | ↵ | | |
|
14 | public void process() {↵ | | 13 | public void process(){↵
|
15 | JMeterContext jmctx = JMeterContextService.getContext();↵ | | 14 | ↵
|
|
16 | SampleResult prev = jmctx.getPreviousResult();↵ | | |
|
17 | final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();↵ | | 15 | final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();↵
|
18 | if (prev == null || bshInterpreter == null) {↵ | | 16 | if (bshInterpreter == null) {↵
|
19 | log.error("BeanShell not found");↵ | | 17 | log.error("BeanShell not found");↵
|
20 | return;↵ | | 18 | return;↵
|
21 | }↵ | | |
|
|
22 | JMeterVariables vars = jmctx.getVariables↵ | | 19 | }↵
|
| | | 20 | JMeterContext jmctx = JMeterContextService.getContext();↵
|
| | | 21 | JMeterVariables vars = jmctx.getVariables();↵
|
| | | 22 | Sampler sam = jmctx.getCurrentSampler();↵
|
23 | ();↵ | | 23 | SampleResult prev = jmctx.getPreviousResult();↵
|
24 | try {↵ | | 24 | try {↵
|
25 | // Add variables for access to context and variables↵ | | 25 | // Add variables for access to context and variables↵
|
26 | bshInterpreter.set("ctx", jmctx);//$NON-NLS-1$↵ | | 26 | bshInterpreter.set("ctx", jmctx);//$NON-NLS-1$↵
|
27 | bshInterpreter.set("vars", vars);//$NON-NLS-1$↵ | | 27 | bshInterpreter.set("vars", vars);//$NON-NLS-1$↵
|
28 | bshInterpreter.set("prev", prev);//$NON-NLS-1$↵ | | 28 | bshInterpreter.set("sampler", sam);//$NON-NLS-1$↵
|
29 | bshInterpreter.set("data", prev.getResponseData());//$NON-NLS-1$↵ | | 29 | bshInterpreter.set("prev", prev);//$NON-NLS-1$↵
|
| | | 30 | ↵
|
30 | processFileOrScript(bshInterpreter);↵ | | 31 | processFileOrScript(bshInterpreter);↵
|
31 | } catch (JMeterException e) {↵ | | 32 | } catch (JMeterException e) {↵
|
32 | log.warn("Problem in BeanShell script "+e);↵ | | 33 | log.warn("Problem in BeanShell script "+e);↵
|
33 | | | 34 |
|