diff --git a/src/main/java/api_assured/Caller.java b/src/main/java/api_assured/Caller.java index 1656553..65376ad 100644 --- a/src/main/java/api_assured/Caller.java +++ b/src/main/java/api_assured/Caller.java @@ -135,10 +135,12 @@ protected static ResponsePair, private static Response getResponse(Call call, boolean printBody) throws IOException { Response response = call.execute(); if (response.isSuccessful()) { + String contentType = response.headers().get("content-type"); + boolean printableResponse = contentType != null && contentType.contains("application/json"); 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 (keepLogs && !response.message().isEmpty()) log.info(response.message()); + if (printBody && printableResponse) log.info("The response body is: \n" + getJsonString(body)); return Response.success(body, response.raw()); } else { diff --git a/src/main/java/utils/FileUtilities.java b/src/main/java/utils/FileUtilities.java index 6f2999d..2c754cc 100644 --- a/src/main/java/utils/FileUtilities.java +++ b/src/main/java/utils/FileUtilities.java @@ -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();