Prash's Blog

com.gargoylesoftware.htmlunit.ScriptException: Exception invoking jsxGet_cookie February 14, 2012

Filed under: Google App Engine — prazjain @ 2:20 pm
Tags: , ,

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;
}
});

Advertisements
 

2 Responses to “com.gargoylesoftware.htmlunit.ScriptException: Exception invoking jsxGet_cookie”

  1. Victor Figueroa Says:

    Thanks for sharing. But quick question, in what file should your workaround script go?

    webClient.setCookieManager(new CookieManager()
    {
    protected int getPort(final URL url)
    {
    final int r = super.getPort(url);
    return r != -1 ? r : 80;
    }
    });

    • prazjain Says:

      This goes in wherever u initialize webClient object. After initializing webClient, u set this setting.
      Cheers


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s