Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for NUTCH-2460 contributed by Hussein Alahmad #245

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/plugin/lib-selenium/ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<license name="Apache 2.0"/>
<ivyauthor name="Apache Nutch Team" url="http://nutch.apache.org"/>
<description>
Apache Nutch
Apache Nutch
</description>
</info>

Expand All @@ -37,16 +37,12 @@

<dependencies>
<!-- begin selenium dependencies -->
<dependency org="org.seleniumhq.selenium" name="selenium-java" rev="2.48.2" />

<dependency org="com.opera" name="operadriver" rev="1.5">
<dependency org="org.seleniumhq.selenium" name="selenium-java" rev="3.7.1" />
<dependency org="com.codeborne" name="phantomjsdriver" rev="1.4.0" >
<exclude org="org.seleniumhq.selenium" name="selenium-remote-driver" />
</dependency>
<dependency org="com.codeborne" name="phantomjsdriver" rev="1.2.1" >
<exclude org="org.seleniumhq.selenium" name="selenium-remote-driver" />
<exclude org="org.seleniumhq.selenium" name="selenium-java" />
<exclude org="org.seleniumhq.selenium" name="selenium-api" />
</dependency>
<!-- end selenium dependencies -->
</dependencies>

</ivy-module>
229 changes: 78 additions & 151 deletions src/plugin/lib-selenium/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,157 +19,84 @@
! A common framework for http protocol implementations
!-->
<plugin
id="lib-selenium"
name="HTTP Framework"
version="1.0"
provider-name="org.apache.nutch">
id="lib-selenium"
name="HTTP Framework"
version="1.0"
provider-name="org.apache.nutch">

<runtime>
<library name="lib-selenium.jar">
<export name="*"/>
</library>
<!-- all classes from dependent libraries are exported -->
<library name="cglib-nodep-2.1_3.jar">
<export name="*"/>
</library>
<library name="commons-codec-1.10.jar">
<export name="*"/>
</library>
<library name="commons-collections-3.2.1.jar">
<export name="*"/>
</library>
<library name="commons-exec-1.3.jar">
<export name="*"/>
</library>
<library name="commons-io-2.4.jar">
<export name="*"/>
</library>
<library name="commons-jxpath-1.3.jar">
<export name="*"/>
</library>
<library name="commons-lang3-3.4.jar">
<export name="*"/>
</library>
<library name="commons-logging-1.2.jar">
<export name="*"/>
</library>
<library name="cssparser-0.9.16.jar">
<export name="*"/>
</library>
<library name="gson-2.3.1.jar">
<export name="*"/>
</library>
<library name="guava-18.0.jar">
<export name="*"/>
</library>
<library name="htmlunit-2.18.jar">
<export name="*"/>
</library>
<library name="htmlunit-core-js-2.17.jar">
<export name="*"/>
</library>
<library name="httpclient-4.5.1.jar">
<export name="*"/>
</library>
<library name="httpcore-4.4.3.jar">
<export name="*"/>
</library>
<library name="httpmime-4.5.jar">
<export name="*"/>
</library>
<library name="ini4j-0.5.2.jar">
<export name="*"/>
</library>
<library name="jetty-io-9.2.12.v20150709.jar">
<export name="*"/>
</library>
<library name="jetty-util-9.2.12.v20150709.jar">
<export name="*"/>
</library>
<library name="jna-4.1.0.jar">
<export name="*"/>
</library>
<library name="jna-platform-4.1.0.jar">
<export name="*"/>
</library>
<library name="nekohtml-1.9.22.jar">
<export name="*"/>
</library>
<library name="netty-3.5.2.Final.jar">
<export name="*"/>
</library>
<library name="operadriver-1.5.jar">
<export name="*"/>
</library>
<library name="operalaunchers-1.1.jar">
<export name="*"/>
</library>
<library name="phantomjsdriver-1.2.1.jar">
<export name="*"/>
</library>
<library name="protobuf-java-2.4.1.jar">
<export name="*"/>
</library>
<library name="sac-1.3.jar">
<export name="*"/>
</library>
<library name="selenium-api-2.48.2.jar">
<export name="*"/>
</library>
<library name="selenium-chrome-driver-2.48.2.jar">
<export name="*"/>
</library>
<library name="selenium-edge-driver-2.48.2.jar">
<export name="*"/>
</library>
<library name="selenium-firefox-driver-2.48.2.jar">
<export name="*"/>
</library>
<library name="selenium-htmlunit-driver-2.48.2.jar">
<export name="*"/>
</library>
<library name="selenium-ie-driver-2.48.2.jar">
<export name="*"/>
</library>
<library name="selenium-java-2.48.2.jar">
<export name="*"/>
</library>
<library name="selenium-leg-rc-2.48.2.jar">
<export name="*"/>
</library>
<library name="selenium-remote-driver-2.48.2.jar">
<export name="*"/>
</library>
<library name="selenium-safari-driver-2.48.2.jar">
<export name="*"/>
</library>
<library name="selenium-support-2.48.2.jar">
<export name="*"/>
</library>
<library name="serializer-2.7.2.jar">
<export name="*"/>
</library>
<library name="webbit-0.4.14.jar">
<export name="*"/>
</library>
<library name="websocket-api-9.2.12.v20150709.jar">
<export name="*"/>
</library>
<library name="websocket-client-9.2.12.v20150709.jar">
<export name="*"/>
</library>
<library name="websocket-common-9.2.12.v20150709.jar">
<export name="*"/>
</library>
<library name="xalan-2.7.2.jar">
<export name="*"/>
</library>
<library name="xercesImpl-2.11.0.jar">
<export name="*"/>
</library>
<library name="xml-apis-1.4.01.jar">
<export name="*"/>
</library>
</runtime>
<runtime>
<library name="lib-selenium.jar">
<export name="*"/>
</library>
<library name="animal-sniffer-annotations-1.14.jar">
<export name="*"/>
</library>
<library name="byte-buddy-1.7.5.jar">
<export name="*"/>
</library>
<library name="commons-codec-1.9.jar">
<export name="*"/>
</library>
<library name="commons-exec-1.3.jar">
<export name="*"/>
</library>
<library name="commons-logging-1.2.jar">
<export name="*"/>
</library>
<library name="error_prone_annotations-2.0.18.jar">
<export name="*"/>
</library>
<library name="gson-2.8.2.jar">
<export name="*"/>
</library>
<library name="guava-23.0.jar">
<export name="*"/>
</library>
<library name="httpclient-4.5.3.jar">
<export name="*"/>
</library>
<library name="httpcore-4.4.6.jar">
<export name="*"/>
</library>
<library name="j2objc-annotations-1.1.jar">
<export name="*"/>
</library>
<library name="jsr305-1.3.9.jar">
<export name="*"/>
</library>
<library name="phantomjsdriver-1.4.0.jar">
<export name="*"/>
</library>
<library name="selenium-api-3.7.1.jar">
<export name="*"/>
</library>
<library name="selenium-chrome-driver-3.7.1.jar">
<export name="*"/>
</library>
<library name="selenium-edge-driver-3.7.1.jar">
<export name="*"/>
</library>
<library name="selenium-firefox-driver-3.7.1.jar">
<export name="*"/>
</library>
<library name="selenium-ie-driver-3.7.1.jar">
<export name="*"/>
</library>
<library name="selenium-java-3.7.1.jar">
<export name="*"/>
</library>
<library name="selenium-opera-driver-3.7.1.jar">
<export name="*"/>
</library>
<library name="selenium-remote-driver-3.7.1.jar">
<export name="*"/>
</library>
<library name="selenium-safari-driver-3.7.1.jar">
<export name="*"/>
</library>
<library name="selenium-support-3.7.1.jar">
<export name="*"/>
</library>
</runtime>

</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.io.TemporaryFilesystem;
import org.openqa.selenium.remote.DesiredCapabilities;
Expand All @@ -46,9 +47,8 @@
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opera.core.systems.OperaDriver;

import org.openqa.selenium.opera.OperaDriver;
import org.openqa.selenium.opera.OperaOptions;
public class HttpWebClient {

private static final Logger LOG = LoggerFactory
Expand All @@ -59,12 +59,14 @@ public class HttpWebClient {
@Override
protected WebDriver initialValue()
{
FirefoxOptions options = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("permissions.default.stylesheet", 2);
profile.setPreference("permissions.default.image", 2);
profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false");
profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "localhost");
WebDriver driver = new FirefoxDriver(profile);
options.setProfile(profile);
WebDriver driver = new FirefoxDriver(options);
return driver;
};
};
Expand All @@ -81,16 +83,23 @@ public static WebDriver getDriverForPage(String url, Configuration conf) {
String allowedHost = conf.get("selenium.firefox.allowed.hosts", "localhost");
long firefoxBinaryTimeout = conf.getLong("selenium.firefox.binary.timeout", 45);
boolean enableFlashPlayer = conf.getBoolean("selenium.firefox.enable.flash", false);
boolean headless = conf.getBoolean("selenium.firefox.headless", false);
int loadImage = conf.getInt("selenium.firefox.load.image", 1);
int loadStylesheet = conf.getInt("selenium.firefox.load.stylesheet", 1);
FirefoxProfile profile = new FirefoxProfile();
FirefoxBinary binary = new FirefoxBinary();
profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, allowedHost);
profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", enableFlashPlayer);
profile.setPreference("permissions.default.stylesheet", loadStylesheet);
profile.setPreference("permissions.default.image", loadImage);
binary.setTimeout(TimeUnit.SECONDS.toMillis(firefoxBinaryTimeout));
driver = new FirefoxDriver(binary, profile);
FirefoxOptions options = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
FirefoxBinary binary = new FirefoxBinary();
if(headless) {
binary.addCommandLineOptions("--headless");
}
profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, allowedHost);
profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", enableFlashPlayer);
profile.setPreference("permissions.default.stylesheet", loadStylesheet);
profile.setPreference("permissions.default.image", loadImage);
binary.setTimeout(TimeUnit.SECONDS.toMillis(firefoxBinaryTimeout));
options.setProfile(profile);
options.setBinary(binary);
driver = new FirefoxDriver(options);
break;
case "chrome":
driver = new ChromeDriver();
Expand Down Expand Up @@ -166,7 +175,7 @@ public static String getHTMLContent(WebDriver driver, Configuration conf) {
public static void cleanUpDriver(WebDriver driver) {
if (driver != null) {
try {
driver.close();
// driver.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hussein-alahmad Why is this commented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a driver.quit() statement after it , I was getting an error about trying to close a non existing connection , after searching about it , turned out that driver.quit() alone without the driver.close() do the work
as mentioned here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @hussein-alahmad

driver.quit();
TemporaryFilesystem.getDefaultTmpFS().deleteTemporaryFiles();
} catch (Exception e) {
Expand Down