I'm trying to record response resources and for that I have add a filter to the proxy. Problem is that once a filter is added no communication is passing through the proxy not the filter is called. Simply removing the filter makes everything work. Here's a sample code using WebDriver and a Browser as the proxy client. Any help will be appreciated.
public class GroupExampleInterceptor {
public static void main(String[] args) throws InterruptedException {
HttpResponseFilters responseFilters = new HttpResponseFilters() {
@Override
public HttpFilter getFilter(String s) {
return defaultHttpFilter;
}
private DefaultHttpFilter defaultHttpFilter = new DefaultHttpFilter(new HttpResponseFilter() {
@Override
public HttpResponse filterResponse(HttpRequest httpRequest, HttpResponse httpResponse) {
return httpResponse;
}
});
};
int port = 9090;
HttpProxyServer proxyServer = new DefaultHttpProxyServer(port, responseFilters);
proxyServer.start();
Proxy proxy = new Proxy();
proxy.setProxyType(Proxy.ProxyType.MANUAL);
String proxyStr = String.format("localhost:%d", port);
proxy.setHttpProxy(proxyStr);
proxy.setSslProxy(proxyStr);
DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(capability);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.get(urlString);
driver.close();
System.out.println("Driver closed");
proxyServer.stop();
System.out.println("Proxy stopped");
}
}