private void addFormUrls(Document html, HTTPSampleResult result, HTTPSamplerBase config, List<HTTPSamplerBase> potentialLinks) { NodeList rootList = html.getChildNodes(); List<HTTPSamplerBase> urls = new LinkedList<>(); 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); } } }
HTTPSamplerBase newUrl = HtmlParsingUtils.createUrlFromAnchor( hrefStr, ConversionUtils.makeRelativeURL(result.getURL(), base)); newUrl.setMethod(HTTPConstants.GET); log.debug("Potential <frame src> match: " + newUrl); if (HtmlParsingUtils.isAnchorMatched(newUrl, config)) { log.debug("Matched!"); potentialLinks.add(newUrl);
if (tag.equalsIgnoreCase("form")) { // $NON-NLS-1$ try { urlConfigs.add(createFormUrlConfig(tempNode, context)); } catch (MalformedURLException e) { inForm = false; url.addEncodedArgument(getAttributeValue(nodeAtts, "name"), // $NON-NLS-1$ getAttributeValue(nodeAtts, "value")); // $NON-NLS-1$ } else if (tag.equalsIgnoreCase("textarea")) { // $NON-NLS-1$ try { url.addEncodedArgument(getAttributeValue(nodeAtts, "name"), // $NON-NLS-1$ tempNode.getFirstChild().getNodeValue()); } catch (NullPointerException e) { url.addArgument(getAttributeValue(nodeAtts, "name"), ""); // $NON-NLS-1$ selectName = getAttributeValue(nodeAtts, "name"); // $NON-NLS-1$ } else if (tag.equalsIgnoreCase("option")) { // $NON-NLS-1$ String value = getAttributeValue(nodeAtts, "value"); // $NON-NLS-1$ if (value == null) { try { urlConfigs.add(createFormUrlConfig(tempNode, context)); inForm = true; } catch (MalformedURLException e) { log.warn("Some bad HTML " + printNode(tempNode), ex); inForm = recurseForm(childNodes.item(x), urlConfigs, context, selectName, inForm);
private static HTTPSamplerBase createFormUrlConfig(Node tempNode, URL context) throws MalformedURLException { NamedNodeMap atts = tempNode.getAttributes(); if (atts.getNamedItem("action") == null) { // $NON-NLS-1$ throw new MalformedURLException(); } String action = atts.getNamedItem("action").getNodeValue(); // $NON-NLS-1$ return createUrlFromAnchor(action, context); }
private void modifyArgument(Argument arg, Arguments args) { if (log.isDebugEnabled()) { log.debug("Modifying argument: " + arg); } List<Argument> possibleReplacements = new ArrayList<>(); PropertyIterator iter = args.iterator(); Argument replacementArg; while (iter.hasNext()) { replacementArg = (Argument) iter.next().getObjectValue(); try { if (HtmlParsingUtils.isArgumentMatched(replacementArg, arg)) { possibleReplacements.add(replacementArg); } } catch (Exception ex) { log.error("Problem adding Argument", ex); } } if (!possibleReplacements.isEmpty()) { replacementArg = possibleReplacements.get(ThreadLocalRandom.current().nextInt(possibleReplacements.size())); arg.setName(replacementArg.getName()); arg.setValue(replacementArg.getValue()); if (log.isDebugEnabled()) { log.debug("Just set argument to values: " + arg.getName() + " = " + arg.getValue()); } args.removeArgument(replacementArg); } }
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);
/** * Match the input argument against the pattern using String.equals() or pattern matching if that fails * using case-insensitive matching. * * @param arg input string * @param pat pattern string * * @return true if input matches the pattern */ public static boolean isEqualOrMatches(String arg, String pat){ return isEqualOrMatches(arg, pat, JMeterUtils.getMatcher(), JMeterUtils.getPatternCache()); }
HtmlParsingUtils.extractStyleURLs(baseUrl.url, urls, styleTagStr);
/** * Returns a node representing a whole xml given an xml document. * * @param text * an xml document * @return a node representing a whole xml */ public static Node getDOM(String text) { log.debug("Start : getDOM1"); Node node = getParser() .parseDOM( new ByteArrayInputStream( text.getBytes(StandardCharsets.UTF_8)), null); if (log.isDebugEnabled()) { log.debug("node : " + node); } log.debug("End : getDOM1"); return node; }
HTTPSamplerBase newUrl = HtmlParsingUtils.createUrlFromAnchor(hrefStr, ConversionUtils.makeRelativeURL(result.getURL(), base)); newUrl.setMethod(HTTPConstants.GET);
replacementArg = (Argument) iter.next().getObjectValue(); try { if (HtmlParsingUtils.isArgumentMatched(replacementArg, arg)) { possibleReplacements.add(replacementArg);
html = (Document) HtmlParsingUtils.getDOM(responseText.substring(index)); addAnchorUrls(html, result, sampler); addFormUrls(html, result, sampler);
/** * Arguments match if the input name matches the corresponding pattern name * and the input value matches the pattern value, where the matching is done * first using String equals, and then Regular Expression matching if the equals test fails. * * @param arg - input Argument * @param patternArg - pattern to match against * @return true if both name and value match */ public static boolean isArgumentMatched(Argument arg, Argument patternArg) { final Perl5Matcher matcher = JMeterUtils.getMatcher(); final PatternCacheLRU patternCache = JMeterUtils.getPatternCache(); return isEqualOrMatches(arg.getName(), patternArg.getName(), matcher, patternCache) && isEqualOrMatches(arg.getValue(), patternArg.getValue(), matcher, patternCache); }
HtmlParsingUtils.extractStyleURLs(baseUrl, urls, style);
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);
private void addFormUrls(Document html, HTTPSampleResult result, HTTPSamplerBase config) { NodeList rootList = html.getChildNodes(); List<HTTPSamplerBase> urls = new LinkedList<HTTPSamplerBase>(); for (int x = 0; x < rootList.getLength(); x++) { urls.addAll(HtmlParsingUtils.createURLFromForm(rootList.item(x), result.getURL())); } for (Iterator<HTTPSamplerBase> it = urls.iterator(); it.hasNext();) { HTTPSamplerBase newUrl = it.next(); newUrl.setMethod(HTTPConstants.POST); /* * if (log.isDebugEnabled()) { log.debug("Potential Form match: " + * newUrl.toString()); } * */ if (HtmlParsingUtils.isAnchorMatched(newUrl, config)) { //log.debug("Matched!"); addURL(newUrl); } } }
final PatternCacheLRU patternCache = JMeterUtils.getPatternCache(); if (!isEqualOrMatches(newLink.getProtocol(), config.getProtocol(), matcher, patternCache)){ return false; if (!isEqualOrMatches(newLink.getDomain(), domain, matcher, patternCache)){ return false;
HtmlParsingUtils.extractStyleURLs(baseUrl.url, urls, styleTagStr.toString());
HTTPSamplerBase newUrl = HtmlParsingUtils.createUrlFromAnchor( hrefStr, ConversionUtils.makeRelativeURL(result.getURL(), base)); newUrl.setMethod(HTTPConstants.GET); if (HtmlParsingUtils.isAnchorMatched(newUrl, config)) {