use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class DNSCacheManager method createResolver.
/**
* @return {@link Resolver}
*/
private Resolver createResolver() {
CollectionProperty dnsServers = getServers();
try {
String[] serverNames = new String[dnsServers.size()];
int index = 0;
for (JMeterProperty jMeterProperty : dnsServers) {
serverNames[index] = jMeterProperty.getStringValue();
index++;
}
ExtendedResolver result = new ExtendedResolver(serverNames);
if (log.isDebugEnabled()) {
log.debug("Using DNS Resolvers: {}", Arrays.asList((result).getResolvers()));
}
// resolvers will be chosen via round-robin
result.setLoadBalance(true);
return result;
} catch (UnknownHostException uhe) {
this.initFailed = true;
log.warn("Failed to create Extended resolver: {}", uhe.getMessage(), uhe);
return null;
}
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class HeaderManager method save.
/**
* Save the header data to a file.
*
* @param headFile
* name of the file to store headers into. If name is relative
* the system property <code>user.dir</code> will be prepended
* @throws IOException
* if writing the headers fails
*/
public void save(String headFile) throws IOException {
File file = new File(headFile);
if (!file.isAbsolute()) {
file = new File(// $NON-NLS-1$
System.getProperty("user.dir") + File.separator + headFile);
}
try (FileWriter fw = new FileWriter(file);
PrintWriter writer = new PrintWriter(fw)) {
// TODO Charset ?
// $NON-NLS-1$
writer.println("# JMeter generated Header file");
final CollectionProperty hdrs = getHeaders();
for (int i = 0; i < hdrs.size(); i++) {
final JMeterProperty hdr = hdrs.get(i);
Header head = (Header) hdr.getObjectValue();
writer.println(head.toString());
}
}
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class DNSCacheManager method fromStaticHost.
private InetAddress[] fromStaticHost(String host) {
JMeterProperty p = getProperty(HOSTS);
if (p instanceof NullProperty) {
removeProperty(HOSTS);
return new InetAddress[0];
}
CollectionProperty property = (CollectionProperty) p;
PropertyIterator iterator = property.iterator();
while (iterator.hasNext()) {
StaticHost entry = (StaticHost) ((TestElementProperty) iterator.next()).getObjectValue();
if (entry.getName().equals(host)) {
List<InetAddress> addresses = new ArrayList<>();
for (String address : Arrays.asList(entry.getAddress().split("\\s*,\\s*"))) {
try {
addresses.addAll(Arrays.asList(requestLookup(address)));
} catch (UnknownHostException e) {
log.warn("Couldn't resolve static address {} for host {}", address, host, e);
}
}
return addresses.toArray(new InetAddress[addresses.size()]);
}
}
return new InetAddress[0];
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class HTTPArgumentsPanel method configure.
@Override
public void configure(TestElement el) {
super.configure(el);
if (el instanceof Arguments) {
tableModel.clearData();
HTTPArgument.convertArgumentsToHTTP((Arguments) el);
for (JMeterProperty jMeterProperty : ((Arguments) el).getArguments()) {
HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
tableModel.addRow(arg);
}
}
checkButtonsStatus();
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class AuthManager method getAuthForURL.
public Authorization getAuthForURL(URL url) {
if (!isSupportedProtocol(url)) {
return null;
}
// TODO: replace all this url2 mess with a proper method
// "areEquivalent(url1, url2)" that
// would also ignore case in protocol and host names, etc. -- use that
// method in the CookieManager too.
URL url2 = null;
try {
if (url.getPort() == -1) {
// Obtain another URL with an explicit port:
int port = url.getProtocol().equalsIgnoreCase("http") ? HTTPConstants.DEFAULT_HTTP_PORT : HTTPConstants.DEFAULT_HTTPS_PORT;
// only http and https are supported
url2 = new URL(url.getProtocol(), url.getHost(), port, url.getPath());
} else if ((url.getPort() == HTTPConstants.DEFAULT_HTTP_PORT && url.getProtocol().equalsIgnoreCase("http")) || (url.getPort() == HTTPConstants.DEFAULT_HTTPS_PORT && url.getProtocol().equalsIgnoreCase("https"))) {
url2 = new URL(url.getProtocol(), url.getHost(), url.getPath());
}
} catch (MalformedURLException e) {
// this should never happen
log.error("Internal error!", e);
// anyway, we'll continue with url2 set to null.
}
String s1 = url.toString();
String s2 = null;
if (url2 != null) {
s2 = url2.toString();
}
log.debug("Target URL strings to match against: " + s1 + " and " + s2);
// TODO should really return most specific (i.e. longest) match.
for (JMeterProperty jMeterProperty : getAuthObjects()) {
Authorization auth = (Authorization) jMeterProperty.getObjectValue();
String uRL = auth.getURL();
log.debug("Checking match against auth'n entry: " + uRL);
if (s1.startsWith(uRL) || s2 != null && s2.startsWith(uRL)) {
log.debug("Matched");
return auth;
}
log.debug("Did not match");
}
return null;
}
Aggregations