View | Details | Raw Unified | Return to bug 40850
Collapse All | Expand All

(-)src/components/org/apache/jmeter/assertions/BeanShellAssertion.java (+6 lines)
Lines 42-47 Link Here
42
	public static final String SCRIPT = "BeanShellAssertion.query"; //$NON-NLS-1$
42
	public static final String SCRIPT = "BeanShellAssertion.query"; //$NON-NLS-1$
43
43
44
	public static final String PARAMETERS = "BeanShellAssertion.parameters"; //$NON-NLS-1$
44
	public static final String PARAMETERS = "BeanShellAssertion.parameters"; //$NON-NLS-1$
45
    
46
    public static final String RESET_INTREPRETER = "BeanShellSampler.resetInterpreter"; //$NON-NLS-1$
45
47
46
	// can be specified in jmeter.properties
48
	// can be specified in jmeter.properties
47
	public static final String INIT_FILE = "beanshell.assertion.init"; //$NON-NLS-1$
49
	public static final String INIT_FILE = "beanshell.assertion.init"; //$NON-NLS-1$
Lines 61-66 Link Here
61
	public String getParameters() {
63
	public String getParameters() {
62
		return getPropertyAsString(PARAMETERS);
64
		return getPropertyAsString(PARAMETERS);
63
	}
65
	}
66
    
67
    public boolean isResetInterpreter() {
68
        return getPropertyAsBoolean(RESET_INTREPRETER);
69
    }
64
70
65
	/*
71
	/*
66
	 * (non-Javadoc)
72
	 * (non-Javadoc)
(-)src/components/org/apache/jmeter/timers/BeanShellTimerResources.properties (+2 lines)
Lines 2-7 Link Here
2
scripting.displayName=Script (variables: ctx vars log)
2
scripting.displayName=Script (variables: ctx vars log)
3
script.displayName=
3
script.displayName=
4
script.shortDescription=Beanshell script to generate delay
4
script.shortDescription=Beanshell script to generate delay
5
resetGroup.displayName=Reset bsh.Interpreter before each call
6
resetInterpreter.displayName=Reset Interpreter
5
parameterGroup.displayName=Parameters to be passed to BeanShell (=> String Parameters and String []bsh.args)
7
parameterGroup.displayName=Parameters to be passed to BeanShell (=> String Parameters and String []bsh.args)
6
parameters.displayName=Parameters
8
parameters.displayName=Parameters
7
parameters.shortDescription=Parameters to be passed to BeanShell (file or script)
9
parameters.shortDescription=Parameters to be passed to BeanShell (file or script)
(-)src/components/org/apache/jmeter/visualizers/BeanShellListenerResources.properties (+2 lines)
Lines 2-7 Link Here
2
scripting.displayName=Script (variables: ctx vars sampleEvent sampleResult log)
2
scripting.displayName=Script (variables: ctx vars sampleEvent sampleResult log)
3
script.displayName=
3
script.displayName=
4
script.shortDescription=Beanshell script
4
script.shortDescription=Beanshell script
5
resetGroup.displayName=Reset bsh.Interpreter before each call
6
resetInterpreter.displayName=Reset Interpreter
5
parameterGroup.displayName=Parameters to be passed to BeanShell (=> String Parameters and String []bsh.args)
7
parameterGroup.displayName=Parameters to be passed to BeanShell (=> String Parameters and String []bsh.args)
6
parameters.displayName=Parameters
8
parameters.displayName=Parameters
7
parameters.shortDescription=Parameters to be passed to BeanShell (file or script)
9
parameters.shortDescription=Parameters to be passed to BeanShell (file or script)
(-)src/core/org/apache/jmeter/util/BeanShellTestElement.java (+18 lines)
Lines 44-49 Link Here
44
	private String filename; // file to source (overrides script)
44
	private String filename; // file to source (overrides script)
45
45
46
	private String script; // script (if file not provided)
46
	private String script; // script (if file not provided)
47
	
48
	private boolean resetInterpreter = false;
47
	//-- For TestBean implementations only
49
	//-- For TestBean implementations only
48
50
49
    
51
    
Lines 59-64 Link Here
59
    protected abstract String getInitFileProperty();
61
    protected abstract String getInitFileProperty();
60
62
61
    protected BeanShellInterpreter getBeanShellInterpreter() {
63
    protected BeanShellInterpreter getBeanShellInterpreter() {
64
        if (isResetInterpreter()) {
65
            try {
66
                bshInterpreter.reset();
67
            } catch (ClassNotFoundException e) {
68
                log.error("Cannot find BeanShell: "+e.toString());
69
            }
70
        }
71
62
        return bshInterpreter;
72
        return bshInterpreter;
63
    }
73
    }
64
74
Lines 203-207 Link Here
203
213
204
	public void setFilename(String s) {
214
	public void setFilename(String s) {
205
		filename = s;
215
		filename = s;
216
	}
217
	
218
	public boolean isResetInterpreter() {
219
	    return resetInterpreter;
220
	}
221
	
222
	public void setResetInterpreter(boolean b) {
223
	    resetInterpreter = b;
206
	}
224
	}
207
}
225
}
(-)src/core/org/apache/jmeter/util/BeanShellBeanInfoSupport.java (+8 lines)
Lines 32-37 Link Here
32
		super(beanClass);
32
		super(beanClass);
33
		PropertyDescriptor p;
33
		PropertyDescriptor p;
34
		
34
		
35
        p = property("resetInterpreter");
36
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
37
        p.setValue(DEFAULT, Boolean.FALSE);
38
        p.setValue(NOT_EXPRESSION, Boolean.TRUE);
39
        p.setValue(NOT_OTHER, Boolean.TRUE);
40
        
41
        createPropertyGroup("resetGroup", new String[] { "resetInterpreter" });
42
		
35
		p = property("parameters");
43
		p = property("parameters");
36
		p.setValue(NOT_UNDEFINED, Boolean.TRUE);
44
		p.setValue(NOT_UNDEFINED, Boolean.TRUE);
37
		p.setValue(DEFAULT, "");
45
		p.setValue(DEFAULT, "");
(-)src/core/org/apache/jmeter/util/BeanShellInterpreter.java (-20 / +35 lines)
Lines 89-108 Link Here
89
89
90
	// This class is not serialised
90
	// This class is not serialised
91
	private Object bshInstance = null; // The interpreter instance for this class
91
	private Object bshInstance = null; // The interpreter instance for this class
92
	
93
	private String initFile; // Script file to initialize the Interpreter with
94
	
95
	private Logger initLog; // Logger to use during initialization and script run
96
	
92
97
93
	public BeanShellInterpreter() throws ClassNotFoundException {
98
	public BeanShellInterpreter() throws ClassNotFoundException {
94
		if (bshClass == null) {
99
	    reset();
95
			throw new ClassNotFoundException(BSH_INTERPRETER);
96
		}
97
		try {
98
			bshInstance = bshClass.newInstance();
99
		} catch (InstantiationException e) {
100
			log.error("Can't instantiate BeanShell", e);
101
			throw new ClassNotFoundException("Can't instantiate BeanShell", e);
102
		} catch (IllegalAccessException e) {
103
			log.error("Can't instantiate BeanShell", e);
104
			throw new ClassNotFoundException("Can't instantiate BeanShell", e);
105
		}
106
	}
100
	}
107
101
108
	public void init(final String initFile, final Object logger) throws IOException, JMeterException {
102
	public void init(final String initFile, final Object logger) throws IOException, JMeterException {
Lines 140-153 Link Here
140
     * @param _log logger to pass to interpreter; also used to log errors in this method
134
     * @param _log logger to pass to interpreter; also used to log errors in this method
141
     */
135
     */
142
    public BeanShellInterpreter(String init, Logger _log)  throws ClassNotFoundException {
136
    public BeanShellInterpreter(String init, Logger _log)  throws ClassNotFoundException {
143
        this();
137
        initFile = init;
144
        try {
138
        initLog = _log;
145
            this.init(init, _log);
139
146
        } catch (IOException e) {
140
        reset();
147
			_log.warn("Could not initialise interpreter: "+e.toString()); // no need for stack trace
148
        } catch (JMeterException e) {
149
			_log.warn("Could not initialise interpreter: "+e.toString()); // no need for stack trace
150
        }
151
    }
141
    }
152
142
153
    private Object bshInvoke(Method m, Object[] o, boolean shouldLog) throws JMeterException {
143
    private Object bshInvoke(Method m, Object[] o, boolean shouldLog) throws JMeterException {
Lines 178-183 Link Here
178
            throw new JMeterException(message, e);
168
            throw new JMeterException(message, e);
179
        }
169
        }
180
        return r;
170
        return r;
171
    }
172
    
173
    public void reset() throws ClassNotFoundException {
174
        if (bshClass == null) {
175
            throw new ClassNotFoundException(BSH_INTERPRETER);
176
        }
177
        try {
178
            bshInstance = bshClass.newInstance();
179
        } catch (InstantiationException e) {
180
            log.error("Can't instantiate BeanShell", e);
181
            throw new ClassNotFoundException("Can't instantiate BeanShell", e);
182
        } catch (IllegalAccessException e) {
183
            log.error("Can't instantiate BeanShell", e);
184
            throw new ClassNotFoundException("Can't instantiate BeanShell", e);
185
        }
186
        
187
        if (initFile != null) {
188
            try {
189
                this.init(initFile, initLog);
190
            } catch (IOException e) {
191
                initLog.warn("Could not initialise interpreter: "+e.toString()); // no need for stack trace
192
            } catch (JMeterException e) {
193
                initLog.warn("Could not initialise interpreter: "+e.toString()); // no need for stack trace
194
            }
195
        }
181
    }
196
    }
182
197
183
	public Object eval(String s) throws JMeterException {
198
	public Object eval(String s) throws JMeterException {
(-)src/core/org/apache/jmeter/resources/messages.properties (+1 lines)
Lines 82-87 Link Here
82
bsh_script_variables=The following variables are defined for the script:\nSampleResult, ResponseCode, ResponseMessage, IsSuccess, Label, FileName, ctx, vars, log
82
bsh_script_variables=The following variables are defined for the script:\nSampleResult, ResponseCode, ResponseMessage, IsSuccess, Label, FileName, ctx, vars, log
83
bsh_script_file=Script file
83
bsh_script_file=Script file
84
bsh_script_parameters=Parameters (-> String Parameters and String []bsh.args)
84
bsh_script_parameters=Parameters (-> String Parameters and String []bsh.args)
85
bsh_script_reset_interpreter=Reset bsh.Interpreter before each call
85
busy_testing=I'm busy testing, please stop the test before changing settings
86
busy_testing=I'm busy testing, please stop the test before changing settings
86
cache_session_id=Cache Session Id?
87
cache_session_id=Cache Session Id?
87
cancel=Cancel
88
cancel=Cancel
(-)src/components/org/apache/jmeter/extractor/BeanShellPostProcessorResources.properties (+2 lines)
Lines 2-7 Link Here
2
scripting.displayName=Script (variables: ctx vars prev data log)
2
scripting.displayName=Script (variables: ctx vars prev data log)
3
script.displayName=
3
script.displayName=
4
script.shortDescription=Beanshell script
4
script.shortDescription=Beanshell script
5
resetGroup.displayName=Reset bsh.Interpreter before each call
6
resetInterpreter.displayName=Reset Interpreter
5
parameterGroup.displayName=Parameters to be passed to BeanShell (=> String Parameters and String []bsh.args)
7
parameterGroup.displayName=Parameters to be passed to BeanShell (=> String Parameters and String []bsh.args)
6
parameters.displayName=Parameters
8
parameters.displayName=Parameters
7
parameters.shortDescription=Parameters to be passed to BeanShell (file or script)
9
parameters.shortDescription=Parameters to be passed to BeanShell (file or script)
(-)src/protocol/java/org/apache/jmeter/protocol/java/sampler/BeanShellSampler.java (+6 lines)
Lines 48-53 Link Here
48
48
49
	public static final String INIT_FILE = "beanshell.sampler.init"; //$NON-NLS-1$
49
	public static final String INIT_FILE = "beanshell.sampler.init"; //$NON-NLS-1$
50
    
50
    
51
	public static final String RESET_INTREPRETER = "BeanShellSampler.resetInterpreter"; //$NON-NLS-1$
52
51
    protected String getInitFileProperty() {
53
    protected String getInitFileProperty() {
52
        return INIT_FILE;
54
        return INIT_FILE;
53
    }
55
    }
Lines 73-78 Link Here
73
	public String getParameters() {
75
	public String getParameters() {
74
		return getPropertyAsString(PARAMETERS);
76
		return getPropertyAsString(PARAMETERS);
75
	}
77
	}
78
	
79
    public boolean isResetInterpreter() {
80
        return getPropertyAsBoolean(RESET_INTREPRETER);
81
    }
76
82
77
	public SampleResult sample(Entry e)// Entry tends to be ignored ...
83
	public SampleResult sample(Entry e)// Entry tends to be ignored ...
78
	{
84
	{
(-)src/components/org/apache/jmeter/assertions/gui/BeanShellAssertionGui.java (+18 lines)
Lines 21-26 Link Here
21
import java.awt.BorderLayout;
21
import java.awt.BorderLayout;
22
22
23
import javax.swing.Box;
23
import javax.swing.Box;
24
import javax.swing.JCheckBox;
24
import javax.swing.JLabel;
25
import javax.swing.JLabel;
25
import javax.swing.JPanel;
26
import javax.swing.JPanel;
26
import javax.swing.JScrollPane;
27
import javax.swing.JScrollPane;
Lines 28-38 Link Here
28
import javax.swing.JTextField;
29
import javax.swing.JTextField;
29
30
30
import org.apache.jmeter.assertions.BeanShellAssertion;
31
import org.apache.jmeter.assertions.BeanShellAssertion;
32
import org.apache.jmeter.protocol.java.sampler.BeanShellSampler;
31
import org.apache.jmeter.testelement.TestElement;
33
import org.apache.jmeter.testelement.TestElement;
34
import org.apache.jmeter.testelement.property.BooleanProperty;
32
import org.apache.jmeter.util.JMeterUtils;
35
import org.apache.jmeter.util.JMeterUtils;
33
36
34
public class BeanShellAssertionGui extends AbstractAssertionGui {
37
public class BeanShellAssertionGui extends AbstractAssertionGui {
35
38
39
    private JCheckBox resetInterpreter;// reset the bsh.Interpreter before each execution
40
36
	private JTextField filename;// script file name (if present)
41
	private JTextField filename;// script file name (if present)
37
42
38
	private JTextField parameters;// parameters to pass to script file (or script)
43
	private JTextField parameters;// parameters to pass to script file (or script)
Lines 47-52 Link Here
47
		scriptField.setText(element.getPropertyAsString(BeanShellAssertion.SCRIPT));
52
		scriptField.setText(element.getPropertyAsString(BeanShellAssertion.SCRIPT));
48
		filename.setText(element.getPropertyAsString(BeanShellAssertion.FILENAME));
53
		filename.setText(element.getPropertyAsString(BeanShellAssertion.FILENAME));
49
		parameters.setText(element.getPropertyAsString(BeanShellAssertion.PARAMETERS));
54
		parameters.setText(element.getPropertyAsString(BeanShellAssertion.PARAMETERS));
55
        resetInterpreter.setSelected(element.getPropertyAsBoolean(BeanShellSampler.RESET_INTREPRETER));
50
		super.configure(element);
56
		super.configure(element);
51
	}
57
	}
52
58
Lines 67-72 Link Here
67
		te.setProperty(BeanShellAssertion.SCRIPT, scriptField.getText());
73
		te.setProperty(BeanShellAssertion.SCRIPT, scriptField.getText());
68
		te.setProperty(BeanShellAssertion.FILENAME, filename.getText());
74
		te.setProperty(BeanShellAssertion.FILENAME, filename.getText());
69
		te.setProperty(BeanShellAssertion.PARAMETERS, parameters.getText());
75
		te.setProperty(BeanShellAssertion.PARAMETERS, parameters.getText());
76
        te.setProperty(new BooleanProperty(BeanShellAssertion.RESET_INTREPRETER, resetInterpreter.isSelected()));
70
	}
77
	}
71
78
72
	public String getLabelResource() {
79
	public String getLabelResource() {
Lines 87-92 Link Here
87
		return filenamePanel;
94
		return filenamePanel;
88
	}
95
	}
89
96
97
    private JPanel createResetPanel() {
98
        resetInterpreter = new JCheckBox(JMeterUtils.getResString("bsh_script_reset_interpreter")); // $NON-NLS-1$
99
        resetInterpreter.setName(BeanShellSampler.PARAMETERS);
100
101
        JPanel resetInterpreterPanel = new JPanel(new BorderLayout());
102
        resetInterpreterPanel.add(resetInterpreter, BorderLayout.WEST);
103
        return resetInterpreterPanel;
104
	}
105
90
	private JPanel createParameterPanel() {
106
	private JPanel createParameterPanel() {
91
		JLabel label = new JLabel(JMeterUtils.getResString("bsh_script_parameters")); //$NON-NLS-1$
107
		JLabel label = new JLabel(JMeterUtils.getResString("bsh_script_parameters")); //$NON-NLS-1$
92
108
Lines 106-111 Link Here
106
122
107
		Box box = Box.createVerticalBox();
123
		Box box = Box.createVerticalBox();
108
		box.add(makeTitlePanel());
124
		box.add(makeTitlePanel());
125
		box.add(createResetPanel());
109
		box.add(createParameterPanel());
126
		box.add(createParameterPanel());
110
		box.add(createFilenamePanel());
127
		box.add(createFilenamePanel());
111
		add(box, BorderLayout.NORTH);
128
		add(box, BorderLayout.NORTH);
Lines 143-147 Link Here
143
		filename.setText(""); // $NON-NLS-1$
160
		filename.setText(""); // $NON-NLS-1$
144
		parameters.setText(""); // $NON-NLS-1$
161
		parameters.setText(""); // $NON-NLS-1$
145
		scriptField.setText(""); // $NON-NLS-1$
162
		scriptField.setText(""); // $NON-NLS-1$
163
        resetInterpreter.setSelected(false);
146
	}
164
	}
147
}
165
}
(-)src/components/org/apache/jmeter/modifiers/BeanShellPreProcessorResources.properties (+2 lines)
Lines 2-7 Link Here
2
scripting.displayName=Script (variables: ctx vars prev sampler log)
2
scripting.displayName=Script (variables: ctx vars prev sampler log)
3
script.displayName=
3
script.displayName=
4
script.shortDescription=Beanshell script
4
script.shortDescription=Beanshell script
5
resetGroup.displayName=Reset bsh.Interpreter before each call
6
resetInterpreter.displayName=Reset Interpreter
5
parameterGroup.displayName=Parameters to be passed to BeanShell (=> String Parameters and String []bsh.args)
7
parameterGroup.displayName=Parameters to be passed to BeanShell (=> String Parameters and String []bsh.args)
6
parameters.displayName=Parameters
8
parameters.displayName=Parameters
7
parameters.shortDescription=Parameters to be passed to BeanShell (file or script)
9
parameters.shortDescription=Parameters to be passed to BeanShell (file or script)
(-)src/protocol/java/org/apache/jmeter/protocol/java/control/gui/BeanShellSamplerGui.java (+17 lines)
Lines 21-26 Link Here
21
import java.awt.BorderLayout;
21
import java.awt.BorderLayout;
22
22
23
import javax.swing.Box;
23
import javax.swing.Box;
24
import javax.swing.JCheckBox;
24
import javax.swing.JLabel;
25
import javax.swing.JLabel;
25
import javax.swing.JPanel;
26
import javax.swing.JPanel;
26
import javax.swing.JScrollPane;
27
import javax.swing.JScrollPane;
Lines 30-38 Link Here
30
import org.apache.jmeter.protocol.java.sampler.BeanShellSampler;
31
import org.apache.jmeter.protocol.java.sampler.BeanShellSampler;
31
import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
32
import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
32
import org.apache.jmeter.testelement.TestElement;
33
import org.apache.jmeter.testelement.TestElement;
34
import org.apache.jmeter.testelement.property.BooleanProperty;
33
import org.apache.jmeter.util.JMeterUtils;
35
import org.apache.jmeter.util.JMeterUtils;
34
36
35
public class BeanShellSamplerGui extends AbstractSamplerGui {
37
public class BeanShellSamplerGui extends AbstractSamplerGui {
38
    
39
    private JCheckBox resetInterpreter;// reset the bsh.Interpreter before each execution
36
40
37
	private JTextField filename;// script file name (if present)
41
	private JTextField filename;// script file name (if present)
38
42
Lines 48-53 Link Here
48
		scriptField.setText(element.getPropertyAsString(BeanShellSampler.SCRIPT));
52
		scriptField.setText(element.getPropertyAsString(BeanShellSampler.SCRIPT));
49
		filename.setText(element.getPropertyAsString(BeanShellSampler.FILENAME));
53
		filename.setText(element.getPropertyAsString(BeanShellSampler.FILENAME));
50
		parameters.setText(element.getPropertyAsString(BeanShellSampler.PARAMETERS));
54
		parameters.setText(element.getPropertyAsString(BeanShellSampler.PARAMETERS));
55
		resetInterpreter.setSelected(element.getPropertyAsBoolean(BeanShellSampler.RESET_INTREPRETER));
51
		super.configure(element);
56
		super.configure(element);
52
	}
57
	}
53
58
Lines 68-73 Link Here
68
		te.setProperty(BeanShellSampler.SCRIPT, scriptField.getText());
73
		te.setProperty(BeanShellSampler.SCRIPT, scriptField.getText());
69
		te.setProperty(BeanShellSampler.FILENAME, filename.getText());
74
		te.setProperty(BeanShellSampler.FILENAME, filename.getText());
70
		te.setProperty(BeanShellSampler.PARAMETERS, parameters.getText());
75
		te.setProperty(BeanShellSampler.PARAMETERS, parameters.getText());
76
		te.setProperty(new BooleanProperty(BeanShellSampler.RESET_INTREPRETER, resetInterpreter.isSelected()));
71
	}
77
	}
72
    
78
    
73
    /**
79
    /**
Lines 79-84 Link Here
79
        filename.setText(""); //$NON-NLS-1$
85
        filename.setText(""); //$NON-NLS-1$
80
        parameters.setText(""); //$NON-NLS-1$
86
        parameters.setText(""); //$NON-NLS-1$
81
        scriptField.setText(""); //$NON-NLS-1$
87
        scriptField.setText(""); //$NON-NLS-1$
88
        resetInterpreter.setSelected(false);
82
    }    
89
    }    
83
90
84
	public String getLabelResource() {
91
	public String getLabelResource() {
Lines 112-123 Link Here
112
		return parameterPanel;
119
		return parameterPanel;
113
	}
120
	}
114
121
122
    private JPanel createResetPanel() {
123
        resetInterpreter = new JCheckBox(JMeterUtils.getResString("bsh_script_reset_interpreter")); // $NON-NLS-1$
124
        resetInterpreter.setName(BeanShellSampler.PARAMETERS);
125
126
        JPanel resetInterpreterPanel = new JPanel(new BorderLayout());
127
        resetInterpreterPanel.add(resetInterpreter, BorderLayout.WEST);
128
        return resetInterpreterPanel;
129
    }
130
115
	private void init() {
131
	private void init() {
116
		setLayout(new BorderLayout(0, 5));
132
		setLayout(new BorderLayout(0, 5));
117
		setBorder(makeBorder());
133
		setBorder(makeBorder());
118
134
119
		Box box = Box.createVerticalBox();
135
		Box box = Box.createVerticalBox();
120
		box.add(makeTitlePanel());
136
		box.add(makeTitlePanel());
137
		box.add(createResetPanel());
121
		box.add(createParameterPanel());
138
		box.add(createParameterPanel());
122
		box.add(createFilenamePanel());
139
		box.add(createFilenamePanel());
123
		add(box, BorderLayout.NORTH);
140
		add(box, BorderLayout.NORTH);

Return to bug 40850