Search in sources :

Example 1 with HTTPSamplerBase

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

the class RegExUserParameters method process.

@Override
public void process() {
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug("{} Running up named: {}", Thread.currentThread().getName(), getName());
    }
    Sampler entry = getThreadContext().getCurrentSampler();
    if (!(entry instanceof HTTPSamplerBase)) {
        return;
    }
    Map<String, String> paramMap = buildParamsMap();
    if (paramMap == null || paramMap.isEmpty()) {
        log.info("RegExUserParameters element: {} => Referenced RegExp was not found, no parameter will be changed", getName());
        return;
    }
    HTTPSamplerBase sampler = (HTTPSamplerBase) entry;
    for (JMeterProperty jMeterProperty : sampler.getArguments()) {
        Argument arg = (Argument) jMeterProperty.getObjectValue();
        String oldValue = arg.getValue();
        // if parameter name exists in http request
        // then change its value with value obtained with regular expression
        String val = paramMap.get(arg.getName());
        if (val != null) {
            arg.setValue(val);
        }
        if (log.isDebugEnabled()) {
            log.debug("RegExUserParameters element: {} => changed parameter: {} = {}, was: {}", getName(), arg.getName(), arg.getValue(), oldValue);
        }
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) Sampler(org.apache.jmeter.samplers.Sampler) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 2 with HTTPSamplerBase

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

the class AbstractSamplerCreator method createAndPopulateSampler.

/**
 * @see org.apache.jmeter.protocol.http.proxy.SamplerCreator#createAndPopulateSampler(org.apache.jmeter.protocol.http.proxy.HttpRequestHdr,
 *      java.util.Map, java.util.Map)
 */
@Override
public HTTPSamplerBase createAndPopulateSampler(HttpRequestHdr request, Map<String, String> pageEncodings, Map<String, String> formEncodings) throws Exception {
    HTTPSamplerBase sampler = createSampler(request, pageEncodings, formEncodings);
    populateSampler(sampler, request, pageEncodings, formEncodings);
    return sampler;
}
Also used : HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 3 with HTTPSamplerBase

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

the class AnchorModifier method process.

/**
 * Modifies an Entry object based on HTML response text.
 */
@Override
public void process() {
    JMeterContext context = getThreadContext();
    Sampler sam = context.getCurrentSampler();
    SampleResult res = context.getPreviousResult();
    HTTPSamplerBase sampler;
    HTTPSampleResult result;
    if (!(sam instanceof HTTPSamplerBase) || !(res instanceof HTTPSampleResult)) {
        log.info("Can't apply HTML Link Parser when the previous" + " sampler run is not an HTTP Request.");
        return;
    } else {
        sampler = (HTTPSamplerBase) sam;
        result = (HTTPSampleResult) res;
    }
    List<HTTPSamplerBase> potentialLinks = new ArrayList<>();
    String responseText = result.getResponseDataAsString();
    // $NON-NLS-1$
    int index = responseText.indexOf('<');
    if (index == -1) {
        index = 0;
    }
    if (log.isDebugEnabled()) {
        log.debug("Check for matches against: " + sampler.toString());
    }
    Document html = (Document) HtmlParsingUtils.getDOM(responseText.substring(index));
    addAnchorUrls(html, result, sampler, potentialLinks);
    addFormUrls(html, result, sampler, potentialLinks);
    addFramesetUrls(html, result, sampler, potentialLinks);
    if (!potentialLinks.isEmpty()) {
        HTTPSamplerBase url = potentialLinks.get(ThreadLocalRandom.current().nextInt(potentialLinks.size()));
        if (log.isDebugEnabled()) {
            log.debug("Selected: " + url.toString());
        }
        sampler.setDomain(url.getDomain());
        sampler.setPath(url.getPath());
        if (url.getMethod().equals(HTTPConstants.POST)) {
            for (JMeterProperty jMeterProperty : sampler.getArguments()) {
                Argument arg = (Argument) jMeterProperty.getObjectValue();
                modifyArgument(arg, url.getArguments());
            }
        } else {
            sampler.setArguments(url.getArguments());
        }
        sampler.setProtocol(url.getProtocol());
    } else {
        log.debug("No matches found");
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) JMeterContext(org.apache.jmeter.threads.JMeterContext) HTTPSampleResult(org.apache.jmeter.protocol.http.sampler.HTTPSampleResult) Sampler(org.apache.jmeter.samplers.Sampler) ArrayList(java.util.ArrayList) SampleResult(org.apache.jmeter.samplers.SampleResult) HTTPSampleResult(org.apache.jmeter.protocol.http.sampler.HTTPSampleResult) Document(org.w3c.dom.Document) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 4 with HTTPSamplerBase

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

the class AnchorModifier method addFramesetUrls.

private void addFramesetUrls(Document html, HTTPSampleResult result, HTTPSamplerBase config, List<HTTPSamplerBase> potentialLinks) {
    String base = "";
    // $NON-NLS-1$
    NodeList baseList = html.getElementsByTagName("base");
    if (baseList.getLength() > 0) {
        base = // $NON-NLS-1$
        baseList.item(0).getAttributes().getNamedItem("href").getNodeValue();
    }
    // $NON-NLS-1$
    NodeList nodeList = html.getElementsByTagName("frame");
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node tempNode = nodeList.item(i);
        NamedNodeMap nnm = tempNode.getAttributes();
        // $NON-NLS-1$
        Node namedItem = nnm.getNamedItem("src");
        if (namedItem == null) {
            continue;
        }
        String hrefStr = namedItem.getNodeValue();
        try {
            HTTPSamplerBase newUrl = HtmlParsingUtils.createUrlFromAnchor(hrefStr, ConversionUtils.makeRelativeURL(result.getURL(), base));
            newUrl.setMethod(HTTPConstants.GET);
            if (log.isDebugEnabled()) {
                log.debug("Potential <frame src> 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 5 with HTTPSamplerBase

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

the class URLRewritingModifier method process.

@Override
public void process() {
    JMeterContext ctx = getThreadContext();
    Sampler sampler = ctx.getCurrentSampler();
    if (!(sampler instanceof HTTPSamplerBase)) {
        // Ignore non-HTTP samplers
        return;
    }
    SampleResult responseText = ctx.getPreviousResult();
    if (responseText == null) {
        return;
    }
    initRegex(getArgumentName());
    String text = responseText.getResponseDataAsString();
    Perl5Matcher matcher = JMeterUtils.getMatcher();
    String value = "";
    if (isPathExtension() && isPathExtensionNoEquals() && isPathExtensionNoQuestionmark()) {
        if (matcher.contains(text, pathExtensionNoEqualsNoQuestionmarkRegexp)) {
            MatchResult result = matcher.getMatch();
            value = result.group(1);
        }
    } else if (// && !isPathExtensionNoQuestionmark()
    isPathExtension() && isPathExtensionNoEquals()) {
        if (matcher.contains(text, pathExtensionNoEqualsQuestionmarkRegexp)) {
            MatchResult result = matcher.getMatch();
            value = result.group(1);
        }
    } else if (// && !isPathExtensionNoEquals()
    isPathExtension() && isPathExtensionNoQuestionmark()) {
        if (matcher.contains(text, pathExtensionEqualsNoQuestionmarkRegexp)) {
            MatchResult result = matcher.getMatch();
            value = result.group(1);
        }
    } else if (// && !isPathExtensionNoEquals() && !isPathExtensionNoQuestionmark()
    isPathExtension()) {
        if (matcher.contains(text, pathExtensionEqualsQuestionmarkRegexp)) {
            MatchResult result = matcher.getMatch();
            value = result.group(1);
        }
    } else // if ! isPathExtension()
    {
        if (matcher.contains(text, parameterRegexp)) {
            MatchResult result = matcher.getMatch();
            for (int i = 1; i < result.groups(); i++) {
                value = result.group(i);
                if (value != null) {
                    break;
                }
            }
        }
    }
    // Bug 15025 - save session value across samplers
    if (shouldCache()) {
        if (value == null || value.length() == 0) {
            value = savedValue;
        } else {
            savedValue = value;
        }
    }
    modify((HTTPSamplerBase) sampler, value);
}
Also used : JMeterContext(org.apache.jmeter.threads.JMeterContext) Sampler(org.apache.jmeter.samplers.Sampler) SampleResult(org.apache.jmeter.samplers.SampleResult) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult) 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