Search in sources :

Example 61 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class HTTPFileArgsPanel method configure.

/**
 * A newly created component can be initialized with the contents of a
 * HTTPSamplerBase object by calling this method. The component is responsible for
 * querying the Test Element object for the relevant information to display
 * in its GUI.
 *
 * @param testElement the HTTPSamplerBase to be used to configure the GUI
 */
public void configure(TestElement testElement) {
    if (testElement instanceof HTTPSamplerBase) {
        HTTPSamplerBase base = (HTTPSamplerBase) testElement;
        tableModel.clearData();
        for (HTTPFileArg file : base.getHTTPFiles()) {
            tableModel.addRow(file);
        }
        checkButtonsStatus();
    }
}
Also used : HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 62 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class AnchorModifier method addAnchorUrls.

private void addAnchorUrls(Document html, HTTPSampleResult result, HTTPSamplerBase config, List<HTTPSamplerBase> potentialLinks) {
    String base = "";
    // $NON-NLS-1$
    NodeList baseList = html.getElementsByTagName("base");
    if (baseList.getLength() > 0) {
        // $NON-NLS-1$
        base = baseList.item(0).getAttributes().getNamedItem("href").getNodeValue();
    }
    // $NON-NLS-1$
    NodeList nodeList = html.getElementsByTagName("a");
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node tempNode = nodeList.item(i);
        NamedNodeMap nnm = tempNode.getAttributes();
        // $NON-NLS-1$
        Node namedItem = nnm.getNamedItem("href");
        if (namedItem == null) {
            continue;
        }
        String hrefStr = namedItem.getNodeValue();
        if (hrefStr.startsWith("javascript:")) {
            // No point trying these
            continue;
        }
        try {
            HTTPSamplerBase newUrl = HtmlParsingUtils.createUrlFromAnchor(hrefStr, ConversionUtils.makeRelativeURL(result.getURL(), base));
            newUrl.setMethod(HTTPConstants.GET);
            if (log.isDebugEnabled()) {
                log.debug("Potential <a href> match: " + newUrl);
            }
            if (HtmlParsingUtils.isAnchorMatched(newUrl, config)) {
                log.debug("Matched!");
                potentialLinks.add(newUrl);
            }
        } catch (MalformedURLException e) {
            log.warn("Bad URL " + e);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 63 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class AnchorModifier method addFormUrls.

private void addFormUrls(Document html, HTTPSampleResult result, HTTPSamplerBase config, List<HTTPSamplerBase> potentialLinks) {
    NodeList rootList = html.getChildNodes();
    List<HTTPSamplerBase> urls = new ArrayList<>();
    for (int x = 0; x < rootList.getLength(); x++) {
        urls.addAll(HtmlParsingUtils.createURLFromForm(rootList.item(x), result.getURL()));
    }
    for (HTTPSamplerBase newUrl : urls) {
        newUrl.setMethod(HTTPConstants.POST);
        if (log.isDebugEnabled()) {
            log.debug("Potential Form match: " + newUrl.toString());
        }
        if (HtmlParsingUtils.isAnchorMatched(newUrl, config)) {
            log.debug("Matched!");
            potentialLinks.add(newUrl);
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 64 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class HtmlParsingUtils method createUrlFromAnchor.

/**
 * Create a new Sampler based on an HREF string plus a contextual URL
 * object. Given that an HREF string might be of three possible forms, some
 * processing is required.
 *
 * @param parsedUrlString
 *            the url from the href
 * @param context
 *            the context in which the href was found. This is used to
 *            extract url information that might be missing in
 *            <code>parsedUrlString</code>
 * @return sampler with filled in information about the fully parsed url
 * @throws MalformedURLException
 *             when the given url (<code>parsedUrlString</code> plus
 *             <code>context</code> is malformed)
 */
public static HTTPSamplerBase createUrlFromAnchor(String parsedUrlString, URL context) throws MalformedURLException {
    if (log.isDebugEnabled()) {
        log.debug("Creating URL from Anchor: {}, base: {}", parsedUrlString, context);
    }
    URL url = ConversionUtils.makeRelativeURL(context, parsedUrlString);
    HTTPSamplerBase sampler = HTTPSamplerFactory.newInstance();
    sampler.setDomain(url.getHost());
    sampler.setProtocol(url.getProtocol());
    sampler.setPort(url.getPort());
    sampler.setPath(url.getPath());
    sampler.parseArguments(url.getQuery());
    return sampler;
}
Also used : URL(java.net.URL) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 65 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class DefaultSamplerCreator method createSampler.

/**
 * @see org.apache.jmeter.protocol.http.proxy.SamplerCreator#createSampler(org.apache.jmeter.protocol.http.proxy.HttpRequestHdr,
 *      java.util.Map, java.util.Map)
 */
@Override
public HTTPSamplerBase createSampler(HttpRequestHdr request, Map<String, String> pageEncodings, Map<String, String> formEncodings) {
    // Instantiate the sampler
    HTTPSamplerBase sampler = HTTPSamplerFactory.newInstance(request.getHttpSamplerName());
    sampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());
    // Defaults
    sampler.setFollowRedirects(false);
    sampler.setUseKeepAlive(true);
    if (log.isDebugEnabled()) {
        log.debug("getSampler: sampler path = {}", sampler.getPath());
    }
    return sampler;
}
Also used : HttpTestSampleGui(org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Aggregations

HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)65 Test (org.junit.jupiter.api.Test)40 SampleResult (org.apache.jmeter.samplers.SampleResult)20 Arguments (org.apache.jmeter.config.Arguments)18 HTTPSampleResult (org.apache.jmeter.protocol.http.sampler.HTTPSampleResult)14 HTTPNullSampler (org.apache.jmeter.protocol.http.sampler.HTTPNullSampler)6 HttpTestSampleGui (org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui)5 NodeList (org.w3c.dom.NodeList)4 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)3 Sampler (org.apache.jmeter.samplers.Sampler)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 ClientCookie (org.apache.http.cookie.ClientCookie)2 BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)2 Argument (org.apache.jmeter.config.Argument)2 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)2 JMeterContext (org.apache.jmeter.threads.JMeterContext)2 Node (org.w3c.dom.Node)2