use of org.apache.jmeter.protocol.http.util.HTTPFileArg in project jmeter by apache.
the class TestHTTPSamplers method testSetAndGetMimetype.
@Test
public void testSetAndGetMimetype() {
HTTPSamplerBase sampler = new HTTPNullSampler();
sampler.setHTTPFiles(new HTTPFileArg[] { new HTTPFileArg("", "", "mime") });
HTTPFileArg file = sampler.getHTTPFiles()[0];
assertEquals("mime", file.getMimeType());
sampler.setHTTPFiles(new HTTPFileArg[] { new HTTPFileArg("", "", "mime2") });
file = sampler.getHTTPFiles()[0];
assertEquals("mime2", file.getMimeType());
}
use of org.apache.jmeter.protocol.http.util.HTTPFileArg in project jmeter by apache.
the class TestHTTPSamplers method testSetAndGetFileField.
@Test
public void testSetAndGetFileField() {
HTTPSamplerBase sampler = new HTTPNullSampler();
sampler.setHTTPFiles(new HTTPFileArg[] { new HTTPFileArg("", "param", "") });
HTTPFileArg file = sampler.getHTTPFiles()[0];
assertEquals("param", file.getParamName());
sampler.setHTTPFiles(new HTTPFileArg[] { new HTTPFileArg("", "param2", "") });
file = sampler.getHTTPFiles()[0];
assertEquals("param2", file.getParamName());
}
use of org.apache.jmeter.protocol.http.util.HTTPFileArg in project jmeter by apache.
the class HTTPSamplerBase method mergeFileProperties.
/**
* JMeter 2.3.1 and earlier only had fields for one file on the GUI:
* <ul>
* <li>FILE_NAME</li>
* <li>FILE_FIELD</li>
* <li>MIMETYPE</li>
* </ul>
* These were stored in their own individual properties.
* <p>
* Version 2.3.3 introduced a list of files, each with their own path, name and mimetype.
* <p>
* In order to maintain backwards compatibility of test plans, the 3 original properties
* were retained; additional file entries are stored in an HTTPFileArgs class.
* The HTTPFileArgs class was only present if there is more than 1 file; this means that
* such test plans are backward compatible.
* <p>
* Versions after 2.3.4 dispense with the original set of 3 properties.
* Test plans that use them are converted to use a single HTTPFileArgs list.
*
* @see HTTPSamplerBaseConverter
*/
void mergeFileProperties() {
JMeterProperty fileName = getProperty(FILE_NAME);
JMeterProperty paramName = getProperty(FILE_FIELD);
JMeterProperty mimeType = getProperty(MIMETYPE);
HTTPFileArg oldStyleFile = new HTTPFileArg(fileName, paramName, mimeType);
HTTPFileArgs fileArgs = getHTTPFileArgs();
HTTPFileArgs allFileArgs = new HTTPFileArgs();
if (oldStyleFile.isNotEmpty()) {
// OK, we have an old-style file definition
// save it
allFileArgs.addHTTPFileArg(oldStyleFile);
// Now deal with any additional file arguments
if (fileArgs != null) {
HTTPFileArg[] infiles = fileArgs.asArray();
for (HTTPFileArg infile : infiles) {
allFileArgs.addHTTPFileArg(infile);
}
}
} else {
if (fileArgs != null) {
// for new test plans that don't have FILE/PARAM/MIME properties
allFileArgs = fileArgs;
}
}
// Updated the property lists
setHTTPFileArgs(allFileArgs);
removeProperty(FILE_FIELD);
removeProperty(FILE_NAME);
removeProperty(MIMETYPE);
}
use of org.apache.jmeter.protocol.http.util.HTTPFileArg in project jmeter by apache.
the class HTTPSamplerBase method setHTTPFiles.
/**
* Saves the list of files.
* The first file is saved in the Filename/field/mimetype properties.
* Any additional files are saved in the FILE_ARGS array.
*
* @param files list of files to save
*/
public void setHTTPFiles(HTTPFileArg[] files) {
HTTPFileArgs fileArgs = new HTTPFileArgs();
// Weed out the empty files
if (files.length > 0) {
for (HTTPFileArg file : files) {
if (file.isNotEmpty()) {
fileArgs.addHTTPFileArg(file);
}
}
}
setHTTPFileArgs(fileArgs);
}
use of org.apache.jmeter.protocol.http.util.HTTPFileArg in project jmeter by apache.
the class AjpSampler method setConnectionHeaders.
private String setConnectionHeaders(URL url, String host, String method) throws IOException {
HeaderManager headers = getHeaderManager();
AuthManager auth = getAuthManager();
StringBuilder hbuf = new StringBuilder();
// Allow Headers to override Host setting
//$NON-NLS-1$
hbuf.append("Host").append(COLON_SPACE).append(host).append(NEWLINE);
//Host
setInt(0xA00b);
setString(host);
if (headers != null) {
for (JMeterProperty jMeterProperty : headers.getHeaders()) {
Header header = (Header) jMeterProperty.getObjectValue();
String n = header.getName();
String v = header.getValue();
hbuf.append(n).append(COLON_SPACE).append(v).append(NEWLINE);
int hc = translateHeader(n);
if (hc > 0) {
setInt(hc + AJP_HEADER_BASE);
} else {
setString(n);
}
setString(v);
}
}
if (method.equals(HTTPConstants.POST)) {
int cl = -1;
HTTPFileArg[] hfa = getHTTPFiles();
if (hfa.length > 0) {
HTTPFileArg fa = hfa[0];
String fn = fa.getPath();
File input = new File(fn);
cl = (int) input.length();
if (body != null) {
JOrphanUtils.closeQuietly(body);
body = null;
}
body = new BufferedInputStream(new FileInputStream(input));
setString(HTTPConstants.HEADER_CONTENT_DISPOSITION);
setString("form-data; name=\"" + encode(fa.getParamName()) + "\"; filename=\"" + encode(fn) + //$NON-NLS-1$ //$NON-NLS-2$
"\"");
String mt = fa.getMimeType();
hbuf.append(HTTPConstants.HEADER_CONTENT_TYPE).append(COLON_SPACE).append(mt).append(NEWLINE);
// content-type
setInt(0xA007);
setString(mt);
} else {
hbuf.append(HTTPConstants.HEADER_CONTENT_TYPE).append(COLON_SPACE).append(HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED).append(NEWLINE);
// content-type
setInt(0xA007);
setString(HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED);
StringBuilder sb = new StringBuilder();
boolean first = true;
for (JMeterProperty arg : getArguments()) {
if (first) {
first = false;
} else {
sb.append('&');
}
sb.append(arg.getStringValue());
}
stringBody = sb.toString();
// TODO - charset?
byte[] sbody = stringBody.getBytes();
cl = sbody.length;
body = new ByteArrayInputStream(sbody);
}
hbuf.append(HTTPConstants.HEADER_CONTENT_LENGTH).append(COLON_SPACE).append(String.valueOf(cl)).append(NEWLINE);
// Content-length
setInt(0xA008);
setString(String.valueOf(cl));
}
if (auth != null) {
String authHeader = auth.getAuthHeaderForURL(url);
if (authHeader != null) {
// Authorization
setInt(0xA005);
setString(authHeader);
hbuf.append(HTTPConstants.HEADER_AUTHORIZATION).append(COLON_SPACE).append(authHeader).append(NEWLINE);
}
}
return hbuf.toString();
}
Aggregations