Skip to content

Commit 31f032c

Browse files
authored
Merge pull request #6 from cajuncoding/feature/add_support_for_vs_code_and_test_with_windows
Feature/add support for vs code and test with windows
2 parents 714e645 + 93844f6 commit 31f032c

File tree

16 files changed

+167
-95
lines changed

16 files changed

+167
-95
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"ms-azuretools.vscode-azurefunctions",
4+
"vscjava.vscode-java-debug"
5+
]
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Debug Java Functions",
9+
"type": "java",
10+
"request": "attach",
11+
"hostName": "127.0.0.1",
12+
"port": 5005,
13+
"preLaunchTask": "func: host start"
14+
}
15+
]
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"azureFunctions.deploySubpath": "target/azure-functions/apachefop-serverless-az-func",
3+
"azureFunctions.projectLanguage": "Java",
4+
"azureFunctions.projectRuntime": "~3",
5+
"debug.internalConsoleOptions": "neverOpen",
6+
"azureFunctions.preDeployTask": "package (functions)",
7+
"java.configuration.updateBuildConfiguration": "automatic",
8+
"maven.view": "hierarchical",
9+
"cSpell.words": [
10+
"Gzipped",
11+
"xslfo"
12+
]
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"type": "func",
8+
"command": "host start",
9+
"problemMatcher": "$func-java-watch",
10+
"isBackground": true,
11+
"options": {
12+
"cwd": "${workspaceFolder}/target/azure-functions/apachefop-serverless-az-func"
13+
},
14+
"dependsOn": "package (functions)"
15+
},
16+
{
17+
"label": "package (functions)",
18+
"command": "mvn clean package",
19+
"type": "shell",
20+
"group": {
21+
"kind": "build",
22+
"isDefault": true
23+
}
24+
}
25+
]
26+
}

apachefop-serverless-az-func/apachefop-serverless-az-func.iml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-dom:1.14" level="project" />
2424
<orderEntry type="library" name="Maven: xalan:xalan:2.7.2" level="project" />
2525
<orderEntry type="library" name="Maven: xalan:serializer:2.7.2" level="project" />
26-
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
2726
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-ext:1.14" level="project" />
2827
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-parser:1.14" level="project" />
2928
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-shared-resources:1.14" level="project" />

apachefop-serverless-az-func/pom.xml

Lines changed: 46 additions & 47 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

@@ -28,6 +27,19 @@
2827
<groupId>org.apache.xmlgraphics</groupId>
2928
<artifactId>fop</artifactId>
3029
<version>2.6</version>
30+
<!-- We MUST explicitly exclude these to ensure VS Code can correctly compile.
31+
NOTE: This is because they are referenced in from multiple libraries and while
32+
Maven (via IntelliJ) resolves it, VS Code Java Extensions will fail to compile -->
33+
<exclusions>
34+
<exclusion>
35+
<groupId>xml-apis</groupId>
36+
<artifactId>xml-apis</artifactId>
37+
</exclusion>
38+
<exclusion>
39+
<groupId>java.xml</groupId>
40+
<artifactId>java.xml</artifactId>
41+
</exclusion>
42+
</exclusions>
3143
</dependency>
3244
<dependency>
3345
<groupId>org.apache.commons</groupId>
@@ -63,35 +75,16 @@
6375

6476
<build>
6577
<plugins>
66-
<!-- Microsoft Azure Plugins require UNIQUE Names for deployment to work correctly
67-
therefore we use this UUID plugin to generate a unique ID for each build -->
68-
<plugin>
69-
<groupId>us.springett</groupId>
70-
<artifactId>maven-uuid-generator</artifactId>
71-
<version>1.0.1</version>
72-
<executions>
73-
<execution>
74-
<phase>validate</phase>
75-
<goals>
76-
<goal>generate</goal>
77-
</goals>
78-
</execution>
79-
</executions>
80-
</plugin>
8178
<plugin>
8279
<groupId>com.microsoft.azure</groupId>
8380
<artifactId>azure-functions-maven-plugin</artifactId>
84-
<version>1.9.2</version>
81+
<version>1.14.0</version>
8582
<configuration>
8683
<!-- The App Name & Resource Group Name must both be Unique or deployment issues may arise
8784
as NOTED here: https://github.com/Azure/azure-functions-java-worker/issues/140 -->
8885
<!-- function app name -->
89-
<!--suppress UnresolvedMavenProperty -->
90-
<appName>${appBaseName}-${project.build.uuid}</appName>
91-
<!-- function app resource group -->
92-
<!--suppress UnresolvedMavenProperty -->
93-
<resourceGroup>java-functions-group-${project.build.uuid}</resourceGroup>
94-
<!-- function app service plan name -->
86+
<appName>${functionAppName}</appName>
87+
<resourceGroup>java-functions-group</resourceGroup>
9588
<appServicePlanName>java-functions-app-service-plan</appServicePlanName>
9689
<!-- function app region-->
9790
<!-- refers https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Functions:-Configuration-Details#supported-regions for all valid values -->
@@ -107,10 +100,6 @@
107100
<!-- runtime os, could be windows, linux or docker-->
108101
<os>windows</os>
109102
<javaVersion>${java.version}</javaVersion>
110-
<!-- for docker function, please set the following parameters -->
111-
<!-- <image>[hub-user/]repo-name[:tag]</image> -->
112-
<!-- <serverId></serverId> -->
113-
<!-- <registryUrl></registryUrl> -->
114103
</runtime>
115104
<appSettings>
116105
<property>
@@ -135,6 +124,7 @@
135124
<version>1.7</version>
136125
<executions>
137126
<execution>
127+
<?m2e execute onConfiguration,onIncremental?>
138128
<phase>validate</phase>
139129
<goals>
140130
<goal>run</goal>
@@ -147,6 +137,29 @@
147137
</execution>
148138
</executions>
149139
</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>
150163
<plugin>
151164
<groupId>org.apache.maven.plugins</groupId>
152165
<artifactId>maven-compiler-plugin</artifactId>
@@ -207,28 +220,14 @@
207220
</execution>
208221
</executions>
209222
</plugin>
210-
<!--Remove obj folder generated by .NET SDK in maven clean-->
211223
<plugin>
212224
<groupId>org.apache.maven.plugins</groupId>
213-
<artifactId>maven-clean-plugin</artifactId>
214-
<version>3.1.0</version>
225+
<artifactId>maven-surefire-plugin</artifactId>
226+
<version>2.22.1</version>
215227
<configuration>
216-
<filesets>
217-
<fileset>
218-
<directory>obj</directory>
219-
</fileset>
220-
</filesets>
228+
<skipTests>true</skipTests>
221229
</configuration>
222-
<executions>
223-
<execution>
224-
<id>auto-clean</id>
225-
<phase>initialize</phase>
226-
<goals>
227-
<goal>clean</goal>
228-
</goals>
229-
</execution>
230-
</executions>
231-
</plugin>
230+
</plugin>
232231
</plugins>
233232
</build>
234233
</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: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ public class ApacheFopJavaResourcesFileResolver implements ResourceResolver {
2727
public Resource getResource(URI uri) throws IOException {
2828
InputStream resourceStream = null;
2929

30-
//We MUST ONLY attempt to handle FILE requests... any Http/Https requests need to use original/default behaviour!
30+
//We MUST ONLY attempt to handle FILE requests... any Http/Https requests need to use original/default behavior!
3131
if(uri.getScheme().equalsIgnoreCase(FILE_SCHEME)) {
32-
resourceStream = findJavaResourceWithCaching(uri);
32+
resourceStream = tryFindJavaResourceWithCaching(uri);
3333
}
3434

3535
//If the resource was located then we return it...
36-
//Otherwise we fallback to default Apache FOP behaviour using the original default Fop Resource Resolver...
36+
//Otherwise we fallback to default Apache FOP behavior using the original default Fop Resource Resolver...
3737
return resourceStream != null
3838
? new Resource(resourceStream)
3939
: defaultFopResolver.getResource(uri);
4040
}
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()
@@ -52,23 +52,33 @@ public OutputStream getOutputStream(URI uri) throws IOException {
5252

5353
//Find the Resource and utilize the internal cache for performance since Embedded Resources can't change without
5454
// deployments to update, we can keep these elements (e.g. Fonts) loaded in Memory for performance!
55-
protected InputStream findJavaResourceWithCaching(URI uri) {
55+
protected InputStream tryFindJavaResourceWithCaching(URI uri) {
56+
var requestPath = Paths.get(uri);
5657

5758
//Use cached results from our Concurrent HashMap cached data if possible!
5859
var resourceBytes = javaResourceFileCache.computeIfAbsent(uri, key -> {
59-
6060
//Map the requested Uri to the base application path to determine it's relative path as a Resource!
61-
var requestPath = Paths.get(uri);
62-
var mappedPath = ResourceUtils.MapServerPath(requestPath);
63-
64-
//Now with the relative path for our resource we can attempt to retrieve it...
65-
var resultStream = ResourceUtils.loadResourceAsStream(mappedPath.toString());
6661
try {
67-
68-
return resultStream != null ? IOUtils.toByteArray(resultStream) : null;
69-
70-
} catch (IOException e) {
62+
var mappedPath = ResourceUtils.MapServerPath(requestPath);
63+
64+
//If the path can't be safely mapped we return null to be cached so future lookups are not attempted.
65+
//NOTE: So that we don't black hole this we attempt to log to the system out...
66+
if(mappedPath == null) {
67+
System.out.print("Java Resource Path could not be resolved for: " + uri.toString());
68+
return null;
69+
}
70+
71+
//Now with the relative path for our resource we can attempt to retrieve it...
72+
var resultStream = ResourceUtils.loadResourceAsStream(mappedPath.toString());
73+
74+
return resultStream != null
75+
? IOUtils.toByteArray(resultStream)
76+
: null;
77+
}
78+
catch (Exception e) {
7179
//e.printStackTrace();
80+
//NOTE: So that we don't black hole this we attempt to log to the system out...
81+
System.out.print("EXCEPTION occurred trying to resolve Java Resource for [" + uri.toString() + "]: " + e.getMessage());
7282
return null;
7383
}
7484
});

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);

0 commit comments

Comments
 (0)