Search in sources :

Example 46 with JMeterProperty

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;
    }
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) UnknownHostException(java.net.UnknownHostException)

Example 47 with JMeterProperty

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());
        }
    }
}
Also used : CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) FileWriter(java.io.FileWriter) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 48 with JMeterProperty

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];
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) NullProperty(org.apache.jmeter.testelement.property.NullProperty) UnknownHostException(java.net.UnknownHostException) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress)

Example 49 with JMeterProperty

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();
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) HTTPArgument(org.apache.jmeter.protocol.http.util.HTTPArgument) Arguments(org.apache.jmeter.config.Arguments)

Example 50 with JMeterProperty

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) URL(java.net.URL)

Aggregations

JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)87 StringProperty (org.apache.jmeter.testelement.property.StringProperty)23 Test (org.junit.Test)23 PropertyIterator (org.apache.jmeter.testelement.property.PropertyIterator)13 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)12 Argument (org.apache.jmeter.config.Argument)11 ArrayList (java.util.ArrayList)9 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)8 File (java.io.File)7 Arguments (org.apache.jmeter.config.Arguments)7 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)6 TestElement (org.apache.jmeter.testelement.TestElement)6 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)5 URL (java.net.URL)4 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HashMap (java.util.HashMap)3 Sampler (org.apache.jmeter.samplers.Sampler)3 TestPlan (org.apache.jmeter.testelement.TestPlan)3 NullProperty (org.apache.jmeter.testelement.property.NullProperty)3