Skip to content

Commit c80563e

Browse files
committed
- Various code cleanup from Problems highlighted by VS Code Java parsers.
- Cleanup POM.xml from various Problems highlighted by VS Code Maven xml parser (which apparently uses M2Eclipse processor). - Fix bugs in processing Font paths when run in Windows from auto-detection of existing fonts. - Disabled tests by default in Maven to minimize build/run time.
1 parent 211b900 commit c80563e

File tree

12 files changed

+67
-78
lines changed

12 files changed

+67
-78
lines changed

apachefop-serverless-az-func/.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"debug.internalConsoleOptions": "neverOpen",
66
"azureFunctions.preDeployTask": "package (functions)",
77
"java.configuration.updateBuildConfiguration": "automatic",
8-
"maven.view": "flat"
8+
"maven.view": "hierarchical",
9+
"cSpell.words": [
10+
"Gzipped",
11+
"xslfo"
12+
]
913
}

apachefop-serverless-az-func/pom.xml

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44

55
<groupId>com.cajuncoding</groupId>
66
<artifactId>apachefop-serverless-az-func</artifactId>
7-
<version>1.3-SNAPSHOT</version>
7+
<version>1.4-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>Azure Java Functions</name>
1111

1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<java.version>11</java.version>
15-
<appBaseName>apachefop-serverless-az-func</appBaseName>
16-
<stagingDirectory>${project.build.directory}/azure-functions/${appBaseName}</stagingDirectory>
1715
<functionAppName>apachefop-serverless-az-func</functionAppName>
16+
<stagingDirectory>${project.build.directory}/azure-functions/${functionAppName}</stagingDirectory>
1817
<!-- <functionAppRegion>westus</functionAppRegion> -->
1918
</properties>
2019

@@ -76,21 +75,6 @@
7675

7776
<build>
7877
<plugins>
79-
<!-- Microsoft Azure Plugins require UNIQUE Names for deployment to work correctly
80-
therefore we use this UUID plugin to generate a unique ID for each build -->
81-
<plugin>
82-
<groupId>us.springett</groupId>
83-
<artifactId>maven-uuid-generator</artifactId>
84-
<version>1.0.1</version>
85-
<executions>
86-
<execution>
87-
<phase>validate</phase>
88-
<goals>
89-
<goal>generate</goal>
90-
</goals>
91-
</execution>
92-
</executions>
93-
</plugin>
9478
<plugin>
9579
<groupId>com.microsoft.azure</groupId>
9680
<artifactId>azure-functions-maven-plugin</artifactId>
@@ -99,14 +83,8 @@
9983
<!-- The App Name & Resource Group Name must both be Unique or deployment issues may arise
10084
as NOTED here: https://github.com/Azure/azure-functions-java-worker/issues/140 -->
10185
<!-- function app name -->
102-
<!--suppress UnresolvedMavenProperty -->
103-
<!-- <appName>${appBaseName}-${project.build.uuid}</appName> -->
104-
<appName>${appBaseName}</appName>
105-
<!-- function app resource group -->
106-
<!--suppress UnresolvedMavenProperty -->
107-
<!-- <resourceGroup>java-functions-group-${project.build.uuid}</resourceGroup> -->
86+
<appName>${functionAppName}</appName>
10887
<resourceGroup>java-functions-group</resourceGroup>
109-
<!-- function app service plan name -->
11088
<appServicePlanName>java-functions-app-service-plan</appServicePlanName>
11189
<!-- function app region-->
11290
<!-- refers https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Functions:-Configuration-Details#supported-regions for all valid values -->
@@ -146,6 +124,7 @@
146124
<version>1.7</version>
147125
<executions>
148126
<execution>
127+
<?m2e execute onConfiguration,onIncremental?>
149128
<phase>validate</phase>
150129
<goals>
151130
<goal>run</goal>
@@ -158,6 +137,29 @@
158137
</execution>
159138
</executions>
160139
</plugin>
140+
<!--Remove obj folder generated by .NET SDK in maven clean-->
141+
<plugin>
142+
<groupId>org.apache.maven.plugins</groupId>
143+
<artifactId>maven-clean-plugin</artifactId>
144+
<version>3.1.0</version>
145+
<configuration>
146+
<filesets>
147+
<fileset>
148+
<directory>obj</directory>
149+
</fileset>
150+
</filesets>
151+
</configuration>
152+
<executions>
153+
<execution>
154+
<?m2e execute onConfiguration,onIncremental?>
155+
<id>auto-clean</id>
156+
<phase>initialize</phase>
157+
<goals>
158+
<goal>clean</goal>
159+
</goals>
160+
</execution>
161+
</executions>
162+
</plugin>
161163
<plugin>
162164
<groupId>org.apache.maven.plugins</groupId>
163165
<artifactId>maven-compiler-plugin</artifactId>
@@ -218,28 +220,14 @@
218220
</execution>
219221
</executions>
220222
</plugin>
221-
<!--Remove obj folder generated by .NET SDK in maven clean-->
222223
<plugin>
223224
<groupId>org.apache.maven.plugins</groupId>
224-
<artifactId>maven-clean-plugin</artifactId>
225-
<version>3.1.0</version>
225+
<artifactId>maven-surefire-plugin</artifactId>
226+
<version>2.22.1</version>
226227
<configuration>
227-
<filesets>
228-
<fileset>
229-
<directory>obj</directory>
230-
</fileset>
231-
</filesets>
228+
<skipTests>true</skipTests>
232229
</configuration>
233-
<executions>
234-
<execution>
235-
<id>auto-clean</id>
236-
<phase>initialize</phase>
237-
<goals>
238-
<goal>clean</goal>
239-
</goals>
240-
</execution>
241-
</executions>
242-
</plugin>
230+
</plugin>
243231
</plugins>
244232
</build>
245233
</project>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.cajuncoding.apachefop.serverless;
22

3-
import com.cajuncoding.apachefop.serverless.apachefop.ApacheFopRenderer;
43
import com.cajuncoding.apachefop.serverless.web.ApacheFopServerlessFunctionExecutor;
54
import com.microsoft.azure.functions.*;
65
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
76
import com.microsoft.azure.functions.annotation.FunctionName;
87
import com.microsoft.azure.functions.annotation.HttpTrigger;
98

109
import java.util.Optional;
11-
import java.util.logging.Level;
1210

1311
/**
1412
* Azure Functions with HTTP Trigger.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Resource getResource(URI uri) throws IOException {
4141

4242
@Override
4343
public OutputStream getOutputStream(URI uri) throws IOException {
44-
//For Output Streams we simply default to original Apache FOP behaviour using the original default Fop Resource Resolver...
44+
//For Output Streams we simply default to original Apache FOP behavior using the original default Fop Resource Resolver...
4545
return defaultFopResolver.getOutputStream(uri);
4646

4747
//return ResourceUtils.GetClassLoader()

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ApacheFopRenderer {
2121

2222
//FOPFactory is expected to be re-used as noted in Apache 'overview' section here:
2323
// https://xmlgraphics.apache.org/fop/1.1/embedding.html
24-
private static FopFactory fopFactory = null;
24+
private static FopFactory staticFopFactory = null;
2525

2626
//TransformerFactory may be re-used as a singleton as long as it's never mutated/modified directly by
2727
// more than one thread (e.g. configuration changes on the Factory class).
@@ -54,7 +54,7 @@ public ApacheFopRenderResult renderPdfResult(String xslFOSource, boolean gzipEna
5454
) {
5555
//Enable the Event Listener for capturing Logging details (e.g. parsing/processing Events)...
5656
var eventListener = new ApacheFopEventListener(logger);
57-
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
57+
FOUserAgent foUserAgent = staticFopFactory.newFOUserAgent();
5858
foUserAgent.getEventBroadcaster().addEventListener(eventListener);
5959

6060
//In order to transform the input source into the Binary Pdf output we must initialize a new
@@ -64,7 +64,7 @@ public ApacheFopRenderResult renderPdfResult(String xslFOSource, boolean gzipEna
6464
// Fop is just processing events as they are raised by the transformer. This is efficient
6565
// because the Xml tree is only processed 1 time which aids in optimizing both performance
6666
// and memory utilization.
67-
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, fopOutputStream);
67+
Fop fop = staticFopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, fopOutputStream);
6868
Transformer transformer = transformerFactory.newTransformer();
6969

7070
try(StringReader stringReader = new StringReader(xslFOSource)) {
@@ -88,7 +88,7 @@ public ApacheFopRenderResult renderPdfResult(String xslFOSource, boolean gzipEna
8888
}
8989

9090
protected synchronized void initApacheFopFactorySafely() {
91-
if(this.fopFactory == null) {
91+
if(staticFopFactory == null) {
9292
var baseUri = new File(".").toURI();
9393
var configFilePath = ApacheFopServerlessConstants.ConfigXmlResourceName;
9494
FopFactory newFopFactory = null;
@@ -127,7 +127,7 @@ protected synchronized void initApacheFopFactorySafely() {
127127
newFopFactory = FopFactory.newInstance(baseUri);
128128
}
129129

130-
this.fopFactory = newFopFactory;
130+
staticFopFactory = newFopFactory;
131131
}
132132
}
133133

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import java.util.Map;
99

10-
public class ApacheFopServerlessConfig<T> {
10+
public class ApacheFopServerlessConfig {
1111
//Request Configuration Parameters...
1212
private boolean isGzipRequestEnabled = false;
1313
private boolean isGzipResponseEnabled = false;
@@ -131,12 +131,12 @@ private String getConfigValue(String name) {
131131
return value;
132132
}
133133

134-
private String getConfigValueOrDefault(String name, String defaultValue) {
135-
String value = getConfigValue(name);
136-
return StringUtils.isBlank(value)
137-
? defaultValue
138-
: value;
139-
}
134+
// private String getConfigValueOrDefault(String name, String defaultValue) {
135+
// String value = getConfigValue(name);
136+
// return StringUtils.isBlank(value)
137+
// ? defaultValue
138+
// : value;
139+
// }
140140

141141
private boolean getConfigAsBooleanOrDefault(String name, boolean defaultValue) {
142142
String value = getConfigValue(name);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import java.io.IOException;
77
import java.nio.charset.StandardCharsets;
8-
import java.util.Optional;
98

109
public class AzureFunctionUtils {
1110

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public static Path MapServerPath(Path pathToMap) {
3838
var basePath = getBaseMappedPath();
3939

4040
//Guard to ensure that the path is something inside of the current Base Path,
41-
// otherwise relativize() will throw Exceptions.
41+
// otherwise path.relativize() will throw Exceptions.
42+
//NOTE: the Path.startsWith() will be provide a safe/case-insensitive test...
4243
if(!pathToMap.startsWith(basePath))
4344
return null;
4445

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public HttpResponseMessage ExecuteByteArrayRequest(
2828
var config = new ApacheFopServerlessConfig(request.getHeaders(), request.getQueryParameters());
2929

3030
//Create the Response Builder to handle the various responses we support.
31-
var responseBuilder = new ApacheFopServerlessResponseBuilder(request);
31+
var responseBuilder = new ApacheFopServerlessResponseBuilder<byte[]>(request);
3232

3333
//Get the XslFO Source from the Request (handling GZip Payloads if specified)...
3434
var xslFOBodyContent = request.getBody().isPresent()
@@ -50,7 +50,7 @@ public HttpResponseMessage ExecuteStringRequest(
5050
var config = new ApacheFopServerlessConfig(request.getHeaders(), request.getQueryParameters());
5151

5252
//Create the Response Builder to handle the various responses we support.
53-
var responseBuilder = new ApacheFopServerlessResponseBuilder(request);
53+
var responseBuilder = new ApacheFopServerlessResponseBuilder<String>(request);
5454

5555
//Get the XslFO Source from the Request (handling GZip Payloads if specified)...
5656
var xslFOBodyContent = request.getBody().isPresent()
@@ -62,10 +62,10 @@ public HttpResponseMessage ExecuteStringRequest(
6262
return ExecuteRequestInternal(xslFOBodyContent, config, responseBuilder, logger);
6363
}
6464

65-
protected HttpResponseMessage ExecuteRequestInternal(
65+
protected <TRequest> HttpResponseMessage ExecuteRequestInternal(
6666
String xslFOBodyContent,
6767
ApacheFopServerlessConfig config,
68-
ApacheFopServerlessResponseBuilder responseBuilder,
68+
ApacheFopServerlessResponseBuilder<TRequest> responseBuilder,
6969
Logger logger
7070
) throws TransformerException, IOException, FOPException {
7171
if (StringUtils.isBlank(xslFOBodyContent)) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public HttpResponseMessage BuildPdfResponse(
5353
? HttpEncodings.GZIP_ENCODING
5454
: HttpEncodings.IDENTITY_ENCODING;
5555

56-
//TODO: Dynamically Determine if Header is Gzipped by returning a Class with properties...
5756
var eventLogSafeHeaderValue = CreateSafeHeaderValue(eventLogText, config.getMaxHeaderBytesSize());
5857

5958
//Build the Http Response for the Client!

0 commit comments

Comments
 (0)