use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class ReplaceStringWithFunctions method transformValue.
@Override
public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException {
JMeterProperty newValue = prop;
getMasterFunction().clear();
getMasterFunction().setParameters(prop.getStringValue());
if (getMasterFunction().hasFunction()) {
newValue = new FunctionProperty(prop.getName(), getMasterFunction().getFunction());
}
return newValue;
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class HTTPJavaImpl method setConnectionHeaders.
/**
* Extracts all the required headers for that particular URL request and
* sets them in the <code>HttpURLConnection</code> passed in
*
* @param conn
* <code>HttpUrlConnection</code> which represents the URL
* request
* @param u
* <code>URL</code> of the URL request
* @param headerManager
* the <code>HeaderManager</code> containing all the cookies
* for this <code>UrlConfig</code>
* @param cacheManager the CacheManager (may be null)
*/
private void setConnectionHeaders(HttpURLConnection conn, URL u, HeaderManager headerManager, CacheManager cacheManager) {
// Add all the headers from the HeaderManager
if (headerManager != null) {
CollectionProperty headers = headerManager.getHeaders();
if (headers != null) {
for (JMeterProperty jMeterProperty : headers) {
Header header = (Header) jMeterProperty.getObjectValue();
String n = header.getName();
String v = header.getValue();
conn.addRequestProperty(n, v);
}
}
}
if (cacheManager != null) {
cacheManager.setHeaders(conn, u);
}
}
use of org.apache.jmeter.testelement.property.JMeterProperty 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.testelement.property.JMeterProperty 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();
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class HTTPArgument method convertArgumentsToHTTP.
/**
* Converts all {@link Argument} entries in the collection to {@link HTTPArgument} entries.
*
* @param args collection of {@link Argument} and/or {@link HTTPArgument} entries
*/
public static void convertArgumentsToHTTP(Arguments args) {
List<Argument> newArguments = new LinkedList<>();
for (JMeterProperty jMeterProperty : args.getArguments()) {
Argument arg = (Argument) jMeterProperty.getObjectValue();
if (!(arg instanceof HTTPArgument)) {
newArguments.add(new HTTPArgument(arg));
} else {
newArguments.add(arg);
}
}
args.removeAllArguments();
args.setArguments(newArguments);
}
Aggregations