webmetrics/browsermob-proxy — Issue #39: Unable to monitor requests via Har
Author: sgentry
Created: 2012-02-08 16:15:03+00:00
State: open

Issue created from [Patrick Lightbody's request](http://groups.google.com/group/browsermob-proxy/browse_thread/thread/c5bcf3a70e40c955).

The following test code will fail at line 38 due to a concurrent modification exception. This requires developers to implement the [HttpRequestInterceptor](http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpRequestInterceptor.html) interface to do this type of processing.

import java.util.Iterator;
import java.util.List;

import org.browsermob.core.har.Har;
import org.browsermob.core.har.HarEntry;
import org.browsermob.core.har.HarLog;
import org.browsermob.core.har.HarNameValuePair;
import org.browsermob.proxy.ProxyServer;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

public class SeleniumProxyTesting {

@Test
public void testYahoo() throws Exception {
ProxyServer server = new ProxyServer(9000);
server.start();
server.newHar("yahoo.com");

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, server.seleniumProxy());
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("http://www.yahoo.com");

boolean found = false;
Har har = null;

//This should never complete in this example
while(!found) {
har = server.getHar();
HarLog harLog = har.getLog();
List entries = harLog.getEntries();
for (Iterator i = entries.iterator(); i.hasNext() && !found;) {
for(HarNameValuePair queryData : i.next().getRequest().getQueryString()) { //CME occurrs here
found = (queryData.getName().compareToIgnoreCase("FOO_BAR") == 0) && (queryData.getValue().contains("FOO_BAZ"));
}
}
}
}
}