1

RemoteConverterjBoss Web アプリケーションから、server-standalonedocuments4j プロジェクトに含まれるデフォルトとして構築されたスタンドアロン サーバーまでを使用しています。

jboss 内には必要なライブラリhttpclient-4.0.1.jarと関連の古いバージョンがあるため、JVM によってロードされた jar の異なるバージョンが原因httpcore-4.0.1.jarで多くの問題に直面しています。ClassDefNotFoundException

HttpClientConnectionManagerバージョンでまだ使用できないオブジェクトに特定の問題があります

この問題を回避するために、 用のカスタム http クライアントを構築したいと考えています。standalone-server以前の問題により、 を使用できないからJerseyです。

誰かがそのために別のクライアントを構築しましたstandalone-serverか? カスタムを構築するための仕様は何RemoteClientですか?

更新 1

スニッフィングツールを使用して少し分析した後、メッセージの構成を把握したので、HttpClientそのサーバーのカスタムを次のように終了しました。

    File wordFile = new File("C:/temp/test.docx");
    InputStream targetStream = new FileInputStream(wordFile);

    URL url = new URL("http://localhost:9998");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setDoOutput(true);
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Content-Type", "application/vnd.com.documents4j.any-msword");
    conn.setRequestProperty("Accept", "application/pdf");
    conn.setRequestProperty("Converter-Job-Priority", "1000");


    OutputStream os = conn.getOutputStream();
    os.write(IOUtils.toByteArray(targetStream));
    os.flush();

    if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
        throw new RuntimeException("Failed : HTTP error code : "
            + conn.getResponseCode());
    }

    BufferedReader br = new BufferedReader(new InputStreamReader(
            (conn.getInputStream())));
    FileWriter ostream = new FileWriter("C:/temp/test.pdf");
    BufferedWriter out = new BufferedWriter(ostream);
    String output;
    System.out.println("Output from Server .... \n");
    while ((output = br.readLine()) != null) {
        System.out.println(output);
        out.write(output+"\n");
    }
    br.close();
    out.close();
    os.close();
    conn.disconnect();

作成したばかりのtest.pdfファイルを開こうとすると、すべて白ですが、ページ数は適切です。テキスト エディターでファイルを開き、ファイルの先頭と末尾を分析すると、次の文字が見つかりました。

%PDF-1.5
%µµµµ
1 0 obj  
[...]
startxref
1484122
%%EOF

PDFファイルが良さそうです。

REST サーバーから受け取ったそのファイルと何か関係がありますか?

4

1 に答える 1

2

質問に答える前に、依存関係を再実装するよりも、依存関係を陰にすることをお勧めします。

独自のサービスを実装するときにエンコードの問題に直面していると想像できます。BufferedReaderは受信データを文字データに変換します。データを文字行で読み取らず、バイナリとして扱います。Writerクラスの代わりにStreamクラスを使用します。これが、メタデータが文字で表されているため正しく処理されますが、実際のデータはバイナリ情報であるため不正である理由です。

InputStream in = conn.getInputStream();
OutputStream out = new FileOutputStream("C:/temp/test.pdf");
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) != -1) {
    out.write(buffer, 0, len);
}
于 2016-05-05T22:07:06.137 に答える