Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/api_assured/Caller.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import api_assured.exceptions.FailedCallException;
import com.fasterxml.jackson.core.JsonProcessingException;
import okhttp3.ResponseBody;
import okio.Buffer;
import properties.PropertyUtilities;
import retrofit2.Call;
Expand Down Expand Up @@ -138,7 +139,9 @@ private static <T> Response<T> getResponse(Call<T> call, boolean printBody) thro
T body = response.body();
if (keepLogs) log.success("The response code is: " + response.code());
if (keepLogs && response.message().length()>0) log.info(response.message());
if (printBody) log.info("The response body is: \n" + getJsonString(body));
if (printBody && !(body instanceof ResponseBody)) {
Copy link
Author

@egecansen egecansen Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skips logging the body if it's a binary file (like PDF) to prevent StackOverFlowError

log.info("The response body is: \n" + getJsonString(body));
}
return Response.success(body, response.raw());
}
else {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/utils/FileUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ public static String getPDFFileText(URL url, String fileDestinationPath) throws
} catch (IOException exception) {
log.error(exception.getMessage(), exception);
}
return parsePDFFileToText(fileDestinationPath);
}

/**
* Returns a text of the PDF file.
*
* @param fileDestinationPath The destination path for the PDF file.
* @return The text of PDF.
*/
public static String parsePDFFileToText(String fileDestinationPath) throws IOException {
File file = new File(fileDestinationPath);
PDDocument document = Loader.loadPDF(file);
PDFTextStripper stripper = new PDFTextStripper();
Expand Down