You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2007/05/04 00:26:48 UTC
svn commit: r534998 -
/jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java
Author: sebb
Date: Thu May 3 15:26:44 2007
New Revision: 534998
URL: http://svn.apache.org/viewvc?view=rev&rev=534998
Log:
Add extra debug logging; tidyup
Modified:
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java
Modified: jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java?view=diff&rev=534998&r1=534997&r2=534998
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java (original)
+++ jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java Thu May 3 15:26:44 2007
@@ -77,22 +77,32 @@
result = (HTTPSampleResult) res;
}
List potentialLinks = new ArrayList();
- String responseText = "";
+ String responseText = ""; // $NON-NLS-1$
try {
responseText = new String(result.getResponseData(), result.getDataEncoding());
} catch (UnsupportedEncodingException e) {
}
Document html;
- int index = responseText.indexOf("<");
+ int index = responseText.indexOf("<"); // $NON-NLS-1$
if (index == -1) {
index = 0;
}
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Check for matches against: "+sampler.getUrl().toExternalForm());
+ }
+ } catch (MalformedURLException e) {
+ log.debug("BAD URL"+e.getMessage());
+ }
html = (Document) HtmlParsingUtils.getDOM(responseText.substring(index));
addAnchorUrls(html, result, sampler, potentialLinks);
addFormUrls(html, result, sampler, potentialLinks);
addFramesetUrls(html, result, sampler, potentialLinks);
if (potentialLinks.size() > 0) {
HTTPSamplerBase url = (HTTPSamplerBase) potentialLinks.get(rand.nextInt(potentialLinks.size()));
+ if (log.isDebugEnabled()) {
+ log.debug("Selected: "+url.toString());
+ }
sampler.setDomain(url.getDomain());
sampler.setPath(url.getPath());
if (url.getMethod().equals(HTTPSamplerBase.POST)) {
@@ -107,12 +117,16 @@
}
sampler.setProtocol(url.getProtocol());
return;
+ } else {
+ log.debug("No matches found");
}
return;
}
private void modifyArgument(Argument arg, Arguments args) {
- log.debug("Modifying argument: " + arg);
+ if (log.isDebugEnabled()) {
+ log.debug("Modifying argument: " + arg);
+ }
List possibleReplacements = new ArrayList();
PropertyIterator iter = args.iterator();
Argument replacementArg;
@@ -123,7 +137,7 @@
possibleReplacements.add(replacementArg);
}
} catch (Exception ex) {
- log.error("", ex);
+ log.error("Problem adding Argument", ex);
}
}
@@ -131,7 +145,9 @@
replacementArg = (Argument) possibleReplacements.get(rand.nextInt(possibleReplacements.size()));
arg.setName(replacementArg.getName());
arg.setValue(replacementArg.getValue());
- log.debug("Just set argument to values: " + arg.getName() + " = " + arg.getValue());
+ if (log.isDebugEnabled()) {
+ log.debug("Just set argument to values: " + arg.getName() + " = " + arg.getValue());
+ }
args.removeArgument(replacementArg);
}
}
@@ -149,7 +165,11 @@
while (iter.hasNext()) {
HTTPSamplerBase newUrl = (HTTPSamplerBase) iter.next();
newUrl.setMethod(HTTPSamplerBase.POST);
+ if (log.isDebugEnabled()) {
+ log.debug("Potential Form match: " + newUrl.toString());
+ }
if (HtmlParsingUtils.isAnchorMatched(newUrl, config)) {
+ log.debug("Matched!");
potentialLinks.add(newUrl);
}
}
@@ -157,15 +177,15 @@
private void addAnchorUrls(Document html, HTTPSampleResult result, HTTPSamplerBase config, List potentialLinks) {
String base = "";
- NodeList baseList = html.getElementsByTagName("base");
+ NodeList baseList = html.getElementsByTagName("base"); // $NON-NLS-1$
if (baseList.getLength() > 0) {
- base = baseList.item(0).getAttributes().getNamedItem("href").getNodeValue();
+ base = baseList.item(0).getAttributes().getNamedItem("href").getNodeValue(); // $NON-NLS-1$
}
- NodeList nodeList = html.getElementsByTagName("a");
+ NodeList nodeList = html.getElementsByTagName("a"); // $NON-NLS-1$
for (int i = 0; i < nodeList.getLength(); i++) {
Node tempNode = nodeList.item(i);
NamedNodeMap nnm = tempNode.getAttributes();
- Node namedItem = nnm.getNamedItem("href");
+ Node namedItem = nnm.getNamedItem("href"); // $NON-NLS-1$
if (namedItem == null) {
continue;
}
@@ -173,9 +193,11 @@
try {
HTTPSamplerBase newUrl = HtmlParsingUtils.createUrlFromAnchor(hrefStr, new URL(result.getURL(), base));
newUrl.setMethod(HTTPSamplerBase.GET);
- log.debug("possible match: " + newUrl);
+ if (log.isDebugEnabled()) {
+ log.debug("Potential <a href> match: " + newUrl);
+ }
if (HtmlParsingUtils.isAnchorMatched(newUrl, config)) {
- log.debug("Is a match! " + newUrl);
+ log.debug("Matched!");
potentialLinks.add(newUrl);
}
} catch (MalformedURLException e) {
@@ -186,16 +208,16 @@
private void addFramesetUrls(Document html, HTTPSampleResult result,
HTTPSamplerBase config, List potentialLinks) {
String base = "";
- NodeList baseList = html.getElementsByTagName("base");
+ NodeList baseList = html.getElementsByTagName("base"); // $NON-NLS-1$
if (baseList.getLength() > 0) {
- base = baseList.item(0).getAttributes().getNamedItem("href")
+ base = baseList.item(0).getAttributes().getNamedItem("href") // $NON-NLS-1$
.getNodeValue();
}
- NodeList nodeList = html.getElementsByTagName("frame");
+ NodeList nodeList = html.getElementsByTagName("frame"); // $NON-NLS-1$
for (int i = 0; i < nodeList.getLength(); i++) {
Node tempNode = nodeList.item(i);
NamedNodeMap nnm = tempNode.getAttributes();
- Node namedItem = nnm.getNamedItem("src");
+ Node namedItem = nnm.getNamedItem("src"); // $NON-NLS-1$
if (namedItem == null) {
continue;
}
@@ -204,9 +226,11 @@
HTTPSamplerBase newUrl = HtmlParsingUtils.createUrlFromAnchor(
hrefStr, new URL(result.getURL(), base));
newUrl.setMethod(HTTPSamplerBase.GET);
- log.debug("possible match: " + newUrl);
+ if (log.isDebugEnabled()) {
+ log.debug("Potential <frame src> match: " + newUrl);
+ }
if (HtmlParsingUtils.isAnchorMatched(newUrl, config)) {
- log.debug("Is a match! " + newUrl);
+ log.debug("Matched!");
potentialLinks.add(newUrl);
}
} catch (MalformedURLException e) {
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org