Lines 56-65
Link Here
|
56 |
import java.awt.BorderLayout; |
56 |
import java.awt.BorderLayout; |
57 |
import java.awt.event.ActionEvent; |
57 |
import java.awt.event.ActionEvent; |
58 |
import java.awt.event.ActionListener; |
58 |
import java.awt.event.ActionListener; |
|
|
59 |
import java.io.BufferedInputStream; |
60 |
import java.io.ByteArrayOutputStream; |
59 |
import java.io.File; |
61 |
import java.io.File; |
|
|
62 |
import java.io.FileInputStream; |
63 |
import java.io.FileNotFoundException; |
64 |
import java.io.IOException; |
65 |
import java.io.InputStream; |
66 |
import java.io.OutputStream; |
60 |
|
67 |
|
61 |
import javax.swing.BorderFactory; |
68 |
import javax.swing.BorderFactory; |
62 |
import javax.swing.JButton; |
69 |
import javax.swing.JButton; |
|
|
70 |
import javax.swing.JCheckBox; |
63 |
import javax.swing.JFileChooser; |
71 |
import javax.swing.JFileChooser; |
64 |
import javax.swing.JLabel; |
72 |
import javax.swing.JLabel; |
65 |
import javax.swing.JPanel; |
73 |
import javax.swing.JPanel; |
Lines 67-75
Link Here
|
67 |
|
75 |
|
68 |
import org.apache.jmeter.gui.util.FileDialoger; |
76 |
import org.apache.jmeter.gui.util.FileDialoger; |
69 |
import org.apache.jmeter.protocol.http.sampler.HTTPSampler; |
77 |
import org.apache.jmeter.protocol.http.sampler.HTTPSampler; |
|
|
78 |
import org.apache.jmeter.testelement.AbstractTestElement; |
70 |
import org.apache.jmeter.testelement.TestElement; |
79 |
import org.apache.jmeter.testelement.TestElement; |
71 |
import org.apache.jmeter.util.JMeterUtils; |
80 |
import org.apache.jmeter.util.JMeterUtils; |
72 |
import org.apache.jorphan.gui.layout.VerticalLayout; |
81 |
import org.apache.jorphan.gui.layout.VerticalLayout; |
|
|
82 |
import org.apache.log.Hierarchy; |
83 |
import org.apache.log.Logger; |
84 |
|
73 |
|
85 |
|
74 |
/**************************************** |
86 |
/**************************************** |
75 |
* Title: JMeter Description: Copyright: Copyright (c) 2000 Company: Apache |
87 |
* Title: JMeter Description: Copyright: Copyright (c) 2000 Company: Apache |
Lines 89-98
Link Here
|
89 |
JLabel paramNameLabel; |
101 |
JLabel paramNameLabel; |
90 |
JLabel mimetypeLabel; |
102 |
JLabel mimetypeLabel; |
91 |
JButton browseFileButton; |
103 |
JButton browseFileButton; |
|
|
104 |
JCheckBox evalFileVarsCheck; |
105 |
JLabel evalFileVarsLabel; |
106 |
|
92 |
private static String FILENAME = "filename"; |
107 |
private static String FILENAME = "filename"; |
93 |
private static String BROWSE = "browse"; |
108 |
private static String BROWSE = "browse"; |
94 |
private static String PARAMNAME = "paramname"; |
109 |
private static String PARAMNAME = "paramname"; |
95 |
private static String MIMETYPE = "mimetype"; |
110 |
private static String MIMETYPE = "mimetype"; |
|
|
111 |
private static String EVALFILEVARS = "evalfilevars"; |
112 |
|
113 |
transient private static Logger log = Hierarchy.getDefaultHierarchy().getLoggerFor( |
114 |
"jmeter.gui"); |
115 |
|
96 |
|
116 |
|
97 |
/**************************************** |
117 |
/**************************************** |
98 |
* !ToDo (Constructor description) |
118 |
* !ToDo (Constructor description) |
Lines 114-129
Link Here
|
114 |
ce.setProperty(HTTPSampler.MIMETYPE, mimetypeField.getText()); |
134 |
ce.setProperty(HTTPSampler.MIMETYPE, mimetypeField.getText()); |
115 |
ce.setProperty(HTTPSampler.FILE_NAME, filenameField.getText()); |
135 |
ce.setProperty(HTTPSampler.FILE_NAME, filenameField.getText()); |
116 |
ce.setProperty(HTTPSampler.FILE_FIELD, paramNameField.getText()); |
136 |
ce.setProperty(HTTPSampler.FILE_FIELD, paramNameField.getText()); |
|
|
137 |
ce.setProperty(HTTPSampler.EVAL_FILE_VARS, Boolean.valueOf(evalFileVarsCheck.isSelected())); |
138 |
if (evalFileVarsCheck.isSelected()){ |
139 |
ce.setProperty(HTTPSampler.FILE_CONTENT, getFileContent(filenameField.getText())); |
140 |
} |
117 |
return ce; |
141 |
return ce; |
118 |
} |
142 |
} |
119 |
|
143 |
|
120 |
public void configureSampler(HTTPSampler sampler) |
144 |
private String getFileContent(String filename){ |
|
|
145 |
try { |
146 |
InputStream in = new BufferedInputStream(new FileInputStream(filename)); |
147 |
OutputStream out = new ByteArrayOutputStream(); |
148 |
StringBuffer outBuf = new StringBuffer(); |
149 |
byte[] buf = new byte[1024 * 100]; |
150 |
int read; |
151 |
while ((read = in.read(buf)) > 0){ |
152 |
out.write(buf, 0, read); |
153 |
} |
154 |
in.close(); |
155 |
return out.toString(); |
156 |
} catch (FileNotFoundException e) { |
157 |
log.error("Attached file not found", e); |
158 |
return ""; |
159 |
} catch (IOException e) { |
160 |
log.error("Error reading attached file", e); |
161 |
return ""; |
162 |
} |
163 |
} |
164 |
|
165 |
/* commented out by Michal Kostrzewa |
166 |
* What was this for? |
167 |
public void configureSampler(HTTPSampler sampler) |
121 |
{ |
168 |
{ |
122 |
sampler.setMimetype(mimetypeField.getText()); |
169 |
sampler.setMimetype(mimetypeField.getText()); |
123 |
sampler.setFileField(paramNameField.getText()); |
170 |
sampler.setFileField(paramNameField.getText()); |
124 |
sampler.setFilename(filenameField.getText()); |
171 |
sampler.setFilename(filenameField.getText()); |
|
|
172 |
sampler.setEvalFileVars(evalFileVarsCheck.isSelected()); |
125 |
super.configureSampler(sampler); |
173 |
super.configureSampler(sampler); |
126 |
} |
174 |
} |
|
|
175 |
*/ |
127 |
|
176 |
|
128 |
/**************************************** |
177 |
/**************************************** |
129 |
* !ToDo (Method description) |
178 |
* !ToDo (Method description) |
Lines 136-141
Link Here
|
136 |
mimetypeField.setText((String)el.getProperty(HTTPSampler.MIMETYPE)); |
185 |
mimetypeField.setText((String)el.getProperty(HTTPSampler.MIMETYPE)); |
137 |
filenameField.setText((String)el.getProperty(HTTPSampler.FILE_NAME)); |
186 |
filenameField.setText((String)el.getProperty(HTTPSampler.FILE_NAME)); |
138 |
paramNameField.setText((String)el.getProperty(HTTPSampler.FILE_FIELD)); |
187 |
paramNameField.setText((String)el.getProperty(HTTPSampler.FILE_FIELD)); |
|
|
188 |
evalFileVarsCheck.setSelected(((AbstractTestElement)el).getPropertyAsBoolean(HTTPSampler.EVAL_FILE_VARS)); |
139 |
} |
189 |
} |
140 |
|
190 |
|
141 |
/**************************************** |
191 |
/**************************************** |
Lines 245-254
Link Here
|
245 |
filenamePanel.add(filenameField); |
295 |
filenamePanel.add(filenameField); |
246 |
filenamePanel.add(browseFileButton); |
296 |
filenamePanel.add(browseFileButton); |
247 |
|
297 |
|
|
|
298 |
|
299 |
// ---- EVAL FILE PANEL |
300 |
JPanel evalFileVarsPanel = new JPanel(); |
301 |
evalFileVarsPanel.setBorder(BorderFactory.createEmptyBorder(0, 25, 0, 0)); |
302 |
evalFileVarsLabel = new JLabel(JMeterUtils.getResString("send_file_eval_file_vars_label")); |
303 |
evalFileVarsLabel.setEnabled(true); |
304 |
evalFileVarsCheck = new JCheckBox(); |
305 |
evalFileVarsCheck.setName(EVALFILEVARS); |
306 |
evalFileVarsCheck.setEnabled(true); |
307 |
|
308 |
evalFileVarsPanel.add(evalFileVarsCheck); |
309 |
evalFileVarsPanel.add(evalFileVarsLabel); |
310 |
|
311 |
|
248 |
// PARAM NAME PANEL (contains param name label and text field) |
312 |
// PARAM NAME PANEL (contains param name label and text field) |
249 |
JPanel paramNamePanel = new JPanel(); |
313 |
JPanel paramNamePanel = new JPanel(); |
250 |
paramNamePanel.setBorder(BorderFactory.createEmptyBorder(0, 25, 0, 0)); |
314 |
paramNamePanel.setBorder(BorderFactory.createEmptyBorder(0, 25, 0, 0)); |
251 |
|
315 |
|
252 |
// --- PARAM NAME LABEL |
316 |
// --- PARAM NAME LABEL |
253 |
paramNameLabel = new JLabel(JMeterUtils.getResString("send_file_param_name_label")); |
317 |
paramNameLabel = new JLabel(JMeterUtils.getResString("send_file_param_name_label")); |
254 |
paramNameLabel.setEnabled(true); |
318 |
paramNameLabel.setEnabled(true); |
Lines 278-283
Link Here
|
278 |
mimePanel.add(mimetypeField); |
342 |
mimePanel.add(mimetypeField); |
279 |
|
343 |
|
280 |
filePanel.add(filenamePanel); |
344 |
filePanel.add(filenamePanel); |
|
|
345 |
filePanel.add(evalFileVarsPanel); |
281 |
filePanel.add(paramNamePanel); |
346 |
filePanel.add(paramNamePanel); |
282 |
filePanel.add(mimePanel); |
347 |
filePanel.add(mimePanel); |
283 |
|
348 |
|