From af0a6655c6bc612e29eeaa65e92492c10705687f Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Wed, 15 May 2024 16:32:55 +0300 Subject: [PATCH] add maxInMemorySizeInBytes --- .../docx/service/pdf/PdfServiceImpl.java | 9 ++++++--- .../service/pdf/PdfServiceProperties.java | 20 +++++++++++++------ .../word/WordBuilderImpl.java | 4 ++-- web/src/main/resources/config/pdf.yml | 3 ++- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/opencdmp/filetransformer/docx/service/pdf/PdfServiceImpl.java b/core/src/main/java/org/opencdmp/filetransformer/docx/service/pdf/PdfServiceImpl.java index 533c768..8c4b951 100644 --- a/core/src/main/java/org/opencdmp/filetransformer/docx/service/pdf/PdfServiceImpl.java +++ b/core/src/main/java/org/opencdmp/filetransformer/docx/service/pdf/PdfServiceImpl.java @@ -29,7 +29,10 @@ public class PdfServiceImpl implements PdfService { WebClient webClient = WebClient.builder().filters(exchangeFilterFunctions -> { exchangeFilterFunctions.add(logRequest()); exchangeFilterFunctions.add(logResponse()); - }).baseUrl(pdfServiceProperties.getUrl()).build(); + }).baseUrl(pdfServiceProperties.getUrl()) .codecs(codecs -> codecs + .defaultCodecs() + .maxInMemorySize(this.pdfServiceProperties.getMaxInMemorySizeInBytes()) + ).build(); MultipartBodyBuilder builder = new MultipartBodyBuilder(); builder.part("files", new ByteArrayResource(file)).filename(UUID.randomUUID() + ".docx"); @@ -47,7 +50,7 @@ public class PdfServiceImpl implements PdfService { private static ExchangeFilterFunction logRequest() { return ExchangeFilterFunction.ofRequestProcessor(clientRequest -> { - logger.debug(new MapLogEntry("Request").And("method", clientRequest.method()).And("url", clientRequest.url())); + logger.debug(new MapLogEntry("Request").And("method", clientRequest.method().toString()).And("url", clientRequest.url())); return Mono.just(clientRequest); }); } @@ -57,7 +60,7 @@ public class PdfServiceImpl implements PdfService { if (response.statusCode().isError()) { return response.mutate().build().bodyToMono(String.class) .flatMap(body -> { - logger.error(new MapLogEntry("Response").And("method", response.request().getMethod()).And("url", response.request().getURI()).And("status", response.statusCode()).And("body", body)); + logger.error(new MapLogEntry("Response").And("method", response.request().getMethod().toString()).And("url", response.request().getURI()).And("status", response.statusCode()).And("body", body)); return Mono.just(response); }); } diff --git a/core/src/main/java/org/opencdmp/filetransformer/docx/service/pdf/PdfServiceProperties.java b/core/src/main/java/org/opencdmp/filetransformer/docx/service/pdf/PdfServiceProperties.java index 8b1e217..8c5de16 100644 --- a/core/src/main/java/org/opencdmp/filetransformer/docx/service/pdf/PdfServiceProperties.java +++ b/core/src/main/java/org/opencdmp/filetransformer/docx/service/pdf/PdfServiceProperties.java @@ -5,14 +5,22 @@ import org.springframework.boot.context.properties.bind.ConstructorBinding; @ConfigurationProperties(prefix = "pdf.converter") public class PdfServiceProperties { - private final String url; - - @ConstructorBinding - public PdfServiceProperties(String url) { - this.url = url; - } + private String url; + private int maxInMemorySizeInBytes; public String getUrl() { return url; } + + public void setUrl(String url) { + this.url = url; + } + + public int getMaxInMemorySizeInBytes() { + return maxInMemorySizeInBytes; + } + + public void setMaxInMemorySizeInBytes(int maxInMemorySizeInBytes) { + this.maxInMemorySizeInBytes = maxInMemorySizeInBytes; + } } diff --git a/core/src/main/java/org/opencdmp/filetransformer/docx/service/wordfiletransformer/word/WordBuilderImpl.java b/core/src/main/java/org/opencdmp/filetransformer/docx/service/wordfiletransformer/word/WordBuilderImpl.java index 267e156..0d3623f 100644 --- a/core/src/main/java/org/opencdmp/filetransformer/docx/service/wordfiletransformer/word/WordBuilderImpl.java +++ b/core/src/main/java/org/opencdmp/filetransformer/docx/service/wordfiletransformer/word/WordBuilderImpl.java @@ -971,8 +971,8 @@ public class WordBuilderImpl implements WordBuilder { PositionInParagraph startPos = new PositionInParagraph(0, 0, 0); while((foundTextSegment = this.searchText(paragraph, textToFind, startPos)) != null) { // search all text segments having text to find - System.out.println(foundTextSegment.getBeginRun()+":"+foundTextSegment.getBeginText()+":"+foundTextSegment.getBeginChar()); - System.out.println(foundTextSegment.getEndRun()+":"+foundTextSegment.getEndText()+":"+foundTextSegment.getEndChar()); + logger.debug(foundTextSegment.getBeginRun()+":"+foundTextSegment.getBeginText()+":"+foundTextSegment.getBeginChar()); + logger.debug(foundTextSegment.getEndRun()+":"+foundTextSegment.getEndText()+":"+foundTextSegment.getEndChar()); // maybe there is text before textToFind in begin run XWPFRun beginRun = paragraph.getRuns().get(foundTextSegment.getBeginRun()); diff --git a/web/src/main/resources/config/pdf.yml b/web/src/main/resources/config/pdf.yml index fbf2400..e8ee592 100644 --- a/web/src/main/resources/config/pdf.yml +++ b/web/src/main/resources/config/pdf.yml @@ -1,3 +1,4 @@ pdf: converter: - url: ${PDF_CONVERTER_URL} \ No newline at end of file + url: ${PDF_CONVERTER_URL} + maxInMemorySizeInBytes: 6554000 \ No newline at end of file