public void process()
{
JMeterContext context = getThreadContext();
Sampler sam = context.getCurrentSampler();
SampleResult res = context.getPreviousResult();
HTTPSampler sampler = null;
HTTPSampleResult result = null;
if (res == null
|| !(sam instanceof HTTPSampler)
|| !(res instanceof HTTPSampleResult))
{
log.info("Can't apply HTML Link Parser when the previous"
+" sampler run is not an HTTP Request.");
return;
}
else
{
sampler = (HTTPSampler) sam;
result = (HTTPSampleResult) res;
}
List potentialLinks = new ArrayList();
String responseText = "";
try
{
responseText = new String(result.getResponseData(), "8859_1");
}
catch (UnsupportedEncodingException e)
{}
Document html;
try
{
int index = responseText.indexOf("<");
if (index == -1)
{
index = 0;
}
html = (Document) HtmlParsingUtils.getDOM(responseText.substring(index));
}
catch (SAXException e)
{
return;
}
addAnchorUrls(html, result, sampler, potentialLinks);
addFormUrls(html, result, sampler, potentialLinks);
if (potentialLinks.size() > 0)
{
HTTPSampler url =
(HTTPSampler) potentialLinks.get(
rand.nextInt(potentialLinks.size()));
sampler.setDomain(url.getDomain());
sampler.setPath(url.getPath());
if (url.getMethod().equals(HTTPSampler.POST))
{
PropertyIterator iter = sampler.getArguments().iterator();
while (iter.hasNext())
{
Argument arg = (Argument) iter.next().getObjectValue();
modifyArgument(arg, url.getArguments());
}
}
else
{
sampler.setArguments(url.getArguments());
//config.parseArguments(url.getQueryString());
}
sampler.setProtocol(url.getProtocol());
return;
}
return;
}