Skip to content

Commit f8d07f8

Browse files
committed
Small code improvements, and some logging added to better know when successful rendering was completed (including Pdf Bytes Size).
1 parent aea44e3 commit f8d07f8

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

apachefop-serverless-az-func/src/main/java/com/cajuncoding/apachefop/serverless/apachefop/ApacheFopRenderResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class ApacheFopRenderResult {
77
private final ApacheFopEventListener eventListener;
88

99
public ApacheFopRenderResult(byte[] pdfBytes, ApacheFopEventListener eventListener) {
10-
this.pdfBytes = pdfBytes;
10+
this.pdfBytes = pdfBytes != null ? pdfBytes : new byte[0];
1111
this.eventListener = eventListener;
1212
}
1313

apachefop-serverless-az-func/src/main/java/com/cajuncoding/apachefop/serverless/apachefop/ApacheFopRenderer.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
import org.apache.fop.apps.*;
1111
import org.apache.fop.configuration.ConfigurationException;
1212
import org.apache.fop.configuration.DefaultConfigurationBuilder;
13-
import org.xml.sax.SAXException;
1413

15-
import javax.xml.parsers.ParserConfigurationException;
1614
import javax.xml.transform.*;
1715
import javax.xml.transform.sax.SAXResult;
1816
import javax.xml.transform.stream.StreamSource;
@@ -94,8 +92,6 @@ public ApacheFopRenderResult renderPdfResult(String xslFOSource, boolean gzipEna
9492
}
9593
}
9694

97-
98-
9995
protected synchronized void initApacheFopFactorySafely() {
10096
if(staticFopFactory == null) {
10197
var baseUri = new File(".").toURI();
@@ -104,7 +100,7 @@ protected synchronized void initApacheFopFactorySafely() {
104100

105101
try {
106102
String configXmlText = ResourceUtils.loadResourceAsString(configFilePath);
107-
if (!StringUtils.isBlank(configXmlText)) {
103+
if (StringUtils.isNotBlank(configXmlText)) {
108104

109105
//When Debugging log the full Configuration file...
110106
if(this.apacheFopConfig.isDebuggingEnabled()) {

apachefop-serverless-az-func/src/main/java/com/cajuncoding/apachefop/serverless/config/ApacheFopServerlessConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected void readRequestQueryParamsConfig(Map<String, String> queryParams) {
8383

8484
//Determine if Event Log Dump mode is enabled (vs PDF Binary return).
8585
this.eventLogDumpModeEnabled = BooleanUtils.toBoolean(
86-
queryParams.getOrDefault(ApacheFopServerlessQueryParams.EventLogDump, null)
86+
queryParams.getOrDefault(ApacheFopServerlessQueryParams.EventLogDump, null)
8787
);
8888

8989
}

apachefop-serverless-az-func/src/main/java/com/cajuncoding/apachefop/serverless/utils/TextUtils.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ public static String getCurrentW3cDateTime() {
1818
return currentW3cDateTime;
1919
}
2020

21-
public static boolean isNullOrWhiteSpace(String value) {
22-
return value == null || value.isBlank();
23-
}
24-
2521
/**
2622
* Truncates a string to the number of characters that fit in X bytes avoiding multi byte characters being cut in
2723
* half at the cut off point. Also handles surrogate pairs where 2 characters in the string is actually one literal

apachefop-serverless-az-func/src/main/java/com/cajuncoding/apachefop/serverless/web/ApacheFopServerlessFunctionExecutor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ protected <TRequest> HttpResponseMessage ExecuteRequestInternal(
9292
//Execute the transformation of the XSL-FO source content to Binary PDF format...
9393
var pdfRenderResult = fopHelper.renderPdfResult(xslFOBodyContent, config.isGzipResponseEnabled());
9494

95+
//Add some contextual Logging so we can know if the PDF bytes were rendered...
96+
logger.info(MessageFormat.format("[SUCCESS] Successfully Rendered PDF with [{0}] bytes.", pdfRenderResult.getPdfBytes().length));
97+
9598
//Render the PDF Response (or EventLog Dump if specified)...
9699
var response = config.isEventLogDumpModeEnabled()
97100
? responseBuilder.BuildEventLogDumpResponse(pdfRenderResult, config)

apachefop-serverless-az-func/src/main/java/com/cajuncoding/apachefop/serverless/web/SafeHeader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.cajuncoding.apachefop.serverless.web;
22

33
import com.cajuncoding.apachefop.serverless.http.HttpEncodings;
4-
import com.cajuncoding.apachefop.serverless.utils.TextUtils;
4+
5+
import org.apache.commons.lang3.StringUtils;
56
import org.apache.commons.text.StringEscapeUtils;
67

78
import java.io.UnsupportedEncodingException;
@@ -19,10 +20,10 @@ public SafeHeader(String value, String encoding) throws UnsupportedEncodingExcep
1920
public String getValue() { return value; }
2021

2122
protected String sanitizeTextForHttpHeader(String value, String encoding) throws UnsupportedEncodingException {
22-
if(TextUtils.isNullOrWhiteSpace(value))
23+
if(StringUtils.isBlank(value))
2324
return value;
2425

25-
if(encoding != null && encoding != HttpEncodings.IDENTITY_ENCODING)
26+
if(StringUtils.isNotBlank(encoding) && !encoding.equalsIgnoreCase(HttpEncodings.IDENTITY_ENCODING))
2627
return value;
2728

2829
//BBernard - 09/29/2021

0 commit comments

Comments
 (0)