HtmlUnit Java パッケージから Htmlpage をデシリアライズする際に問題があります。
TL;DR
私が得るエラー(オンラインで発生しますObject o = in.readObject();
):
java.lang.ClassNotFoundException: com.gargoylesoftware.htmlunit.util.Cookie
完全なスタック トレース: http://pastebin.com/geH7SgWu
質問
この問題の原因は何ですか? 何か不足していますか、それとも SVN コードに欠陥がありますか?
私が使用するコード:
シリアライゼーション:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = null;
try {
out = new ObjectOutputStream(bos);
out.writeObject(this.htmlPage);
} catch (Exception ex) {
ex.printStackTrace(System.out);
} finally {
out.close();
bos.close();
}
return bos.toByteArray();
逆シリアル化:
ByteArrayInputStream bis = new ByteArrayInputStream(content.getContent());
ObjectInput in = null;
HtmlPage htmlPage2 = null;
try {
in = new ObjectInputStream(bis);
Object o = in.readObject();
htmlPage2 = (HtmlPage) o;
} catch (Exception ex) {
ex.printStackTrace(System.out);
} finally {
bis.close();
in.close();
}
content
シリアル化されたオブジェクトは、変数のバイトとして送信されます ( Nutch のプロトコル プラグイン)。content.getContent()
その後、メソッドを使用して受信されます (これは Nutchの解析プラグインで発生します)。
コードからアクセスできる HtmlUnit と HtmlUnit 自体のすべての依存関係があります。
Cookie
奇妙なのは、どこでもクラスを使用していないことです。その後、テスト目的で Cookie を作成しましたが、すべてうまくいきました。
次のいずれかの jar に含まれていることを確認しました。
$ jar -tf htmlunit-2.11-SNAPSHOT.jar | grep Cookie
com/gargoylesoftware/htmlunit/HtmlUnitCookieStore.class
com/gargoylesoftware/htmlunit/util/Cookie.class
com/gargoylesoftware/htmlunit/HtmlUnitBrowserCompatCookieSpec.class
com/gargoylesoftware/htmlunit/HtmlUnitBrowserCompatCookieSpec$2.class
com/gargoylesoftware/htmlunit/CookieManager.class
com/gargoylesoftware/htmlunit/HtmlUnitBrowserCompatCookieSpec$1.class
com/gargoylesoftware/htmlunit/HtmlUnitBrowserCompatCookieSpec$3.class
バージョン:
表示される JAR:
commons-codec-1.6.jar
commons-collections-3.2.1.jar
commons-io-2.4.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
cssparser-0.9.7.jar
htmlunit-2.11-SNAPSHOT.jar
htmlunit-core-js-2.11-20120814.002723-22.jar
httpclient-4.2.1.jar
httpcore-4.2.1.jar
httpmime-4.2.1.jar
jetty-http-8.1.5.v20120716.jar
jetty-io-8.1.5.v20120716.jar
jetty-util-8.1.5.v20120716.jar
jetty-websocket-8.1.5.v20120716.jar
nekohtml-1.9.16.jar
sac-1.3.jar
serializer-2.7.1.jar
xalan-2.7.1.jar
xercesImpl-2.10.0.jar
xml-apis-1.4.01.jar
HtmlUnit - この短いチュートリアルhttp://htmlunit.sourceforge.net/gettingLatestCode.htmlに従ってコンパイルされた 10.09.2012 の SVN スナップショット
ナット 1.4
私が提供した情報で十分であることを願っています。そうでない場合は、コメントでお知らせください。質問を更新させていただきます。
よろしくお願いします。
サルスキ