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

(-)core/org/apache/jmeter/resources/messages.properties (+1 lines)
Lines 175-180 Link Here
175
send_file_browse=Browse...
175
send_file_browse=Browse...
176
send_file_param_name_label=Parameter Name:
176
send_file_param_name_label=Parameter Name:
177
send_file_mime_label=MIME Type:
177
send_file_mime_label=MIME Type:
178
send_file_eval_file_vars_label=Evaluate variables in file
178
optional_tasks=Optional Tasks
179
optional_tasks=Optional Tasks
179
proxy_title=HTTP Proxy Server
180
proxy_title=HTTP Proxy Server
180
view_results_title=View Results
181
view_results_title=View Results
(-)protocol/http/org/apache/jmeter/protocol/http/config/gui/MultipartUrlConfigGui.java (-2 / +67 lines)
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
(-)protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java (+33 lines)
Lines 113-118 Link Here
113
	public final static String FILE_DATA = "HTTPSampler.FILE_DATA";
113
	public final static String FILE_DATA = "HTTPSampler.FILE_DATA";
114
	public final static String FILE_MIMETYPE = "HTTPSampler.FILE_MIMETYPE";
114
	public final static String FILE_MIMETYPE = "HTTPSampler.FILE_MIMETYPE";
115
	public final static String CONTENT_TYPE = "HTTPSampler.CONTENT_TYPE";
115
	public final static String CONTENT_TYPE = "HTTPSampler.CONTENT_TYPE";
116
	public final static String EVAL_FILE_VARS = "HTTPSampler.eval_file_vars";
117
	public final static String FILE_CONTENT = "HTTPSampler.file_content";
116
	public final static String NORMAL_FORM = "normal_form";
118
	public final static String NORMAL_FORM = "normal_form";
117
	public final static String MULTIPART_FORM = "multipart_form";
119
	public final static String MULTIPART_FORM = "multipart_form";
118
	private static final int MAX_REDIRECTS=10;
120
	private static final int MAX_REDIRECTS=10;
Lines 283-288 Link Here
283
	{
285
	{
284
		return (String) getProperty(MIMETYPE);
286
		return (String) getProperty(MIMETYPE);
285
	}
287
	}
288
	
289
	
290
	
291
	/**
292
	 * Method setEvaluateFileVariables.
293
	 * @param value
294
	 * @author mkostrze
295
	 */
296
	public void setEvalFileVars(boolean value){
297
		setProperty(EVAL_FILE_VARS, Boolean.valueOf(value));
298
	}
299
	
300
	/**
301
	 * Method getEvaluateFileVariables.
302
	 * @return Boolean
303
	 * @author mkostrze
304
	 */
305
	public boolean isEvalFileVars(){
306
		return getPropertyAsBoolean(EVAL_FILE_VARS);
307
	}
308
	
309
	/**
310
	 * Method getFileContent.
311
	 * @return String
312
	 * @author mkostrze
313
	 */
314
	public String getFileContent(){
315
		return getPropertyAsString(FILE_CONTENT);
316
	}
317
	
318
	
286
	protected void addCustomTestElement(TestElement element)
319
	protected void addCustomTestElement(TestElement element)
287
	{
320
	{
288
		if (element instanceof Arguments)
321
		if (element instanceof Arguments)
(-)protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java (-1 / +9 lines)
Lines 104-111 Link Here
104
				writeFormMultipartStyle(out, arg.getName(), (String)arg.getValue());
104
				writeFormMultipartStyle(out, arg.getName(), (String)arg.getValue());
105
				writeln(out,"--" + BOUNDARY);
105
				writeln(out,"--" + BOUNDARY);
106
			}
106
			}
107
			
107
			writeFileToURL(out, filename, sampler.getFileField(),
108
			writeFileToURL(out, filename, sampler.getFileField(),
108
					 getFileStream(filename),sampler.getMimetype());
109
				 getAttachedFileStream(sampler),sampler.getMimetype());
109
110
110
			writeln(out,"--" + BOUNDARY+"--");
111
			writeln(out,"--" + BOUNDARY+"--");
111
			out.flush();
112
			out.flush();
Lines 148-153 Link Here
148
	private InputStream getFileStream(String filename) throws IOException
149
	private InputStream getFileStream(String filename) throws IOException
149
	{
150
	{
150
		return new BufferedInputStream(new FileInputStream(filename));
151
		return new BufferedInputStream(new FileInputStream(filename));
152
	}
153
	
154
	private InputStream getAttachedFileStream(HTTPSampler sampler) throws IOException{
155
		if (sampler.isEvalFileVars())
156
			return new ByteArrayInputStream(sampler.getFileContent().getBytes());
157
		else
158
			return getFileStream(sampler.getFilename());
151
	}
159
	}
152
160
153
	private String getContentLength(MultipartUrlConfig config)
161
	private String getContentLength(MultipartUrlConfig config)

Return to bug 15468