私のJavaアプリケーションは残りのエンドポイントを呼び出し、レスポンスボディは10GBのXMLファイルです。残りのクエストを送信する前に、ファイルに記録されるレコードの数をサービスに尋ねます。私はその後、ファイルを取得します。アプリを実行すると、ファイルは正常に保存されますが、予想されるレコードの約50%しか保存されません。ファイルには、すべてのレコードを持っていない2つの理由があります:ファイルの保存ロジックは正しいですか?
- 残りのエンドポイントから送信されたファイルのみが期待されるレコードの50%を持っている それはのダウンロードが終了する前にするとき私のアプリが倒れている
私の質問は、シナリオ2で私のアプリが転倒した場合、私はそういう例外がありますか?私は例外が表示されません、実際には、私は私のログステートメントは、保存が保存された後、 'File successfully saved'と表示されます。
EDIT:私のアプリの外で、カール要求によってファイルをダウンロードしました。同じことが起こりました - 予想された人口の50%だけがダウンロードされました。これは私のファイルを保存するロジックに問題がないことを証明します。
public void saveFile() {
try {
downloadAndSaveFile();
} catch (Exception e) {
LOGGER.error("A error has occurred processing all content, caused by {}", e.getMessage(), e);
throw new RuntimeException(e);
}
}
private void downloadAndSaveFile() throws Exception {
long recordCount = countRecords();
LOGGER.info("Number of records to process is {}", recordCount);
if (recordCount > 0) {
InputStream dataToSave = getAllContent();
saveStream(dataToSave);
LOGGER.info("File successfully saved.");
} else {
LOGGER.error("No content to retrieve");
throw new RuntimeException("There are no records to process");
}
}
public InputStream getAllContent() throws Exception {
return callRestEndpoint(webTarget).readEntity(InputStream.class);
}
private Response callRestEndpoint(WebTarget target) throws InterruptedException {
Response response = null;
for (int numberOfTries = 0; numberOfTries < reconnectRetries; numberOfTries++) {
try {
response = makeGetRequest(target);
if (OK.getStatusCode() == response.getStatus()) {
break;
}
} catch (Exception ex) {
retryRequest(numberOfTries, ex);
}
}
return response;
}
public void saveStream(InputStream inputStream) throws IOException {
File fileToCreate = new File(fileName);
if (!fileToCreate.exists()) {
fileToCreate.mkdirs();
}
Files.copy(
inputStream,
fileToCreate.toPath(),
StandardCopyOption.REPLACE_EXISTING
);
closeQuietly(inputStream);
}
この場合、ファイルが保存され、ログに例外が表示されず、「ファイルが正常に保存されました」というメッセージが表示されるため、残りのエンドポイントで問題が発生しているとします。 – TheCoder