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();
}
}
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);
}
}
}
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);
}
}
}
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;
}
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;
}
Aggregations