I was running HtmlUnit 2.9 with Google App Engine in development environment, and hit upon this exception when loading a url:
Truncated Exception is pasted below:
com.gargoylesoftware.htmlunit.ScriptException: Exception invoking jsxGet_cookie at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:595) at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537) ... Caused by: java.lang.RuntimeException: Exception invoking jsxGet_cookie at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:198) ... 65 more Caused by: java.lang.IllegalArgumentException: Invalid port: -1 at org.apache.http.cookie.CookieOrigin.<init>(CookieOrigin.java:58) ... 82 more
This is due to a bug in Google App Engine and following is the workaround to fix it in htmlunit for the time being.
Workaround
webClient.setCookieManager(new CookieManager()
{
protected int getPort(final URL url)
{
final int r = super.getPort(url);
return r != -1 ? r : 80;
}
});
