Skip to content

Commit 563aeea

Browse files
committed
Initial work to resolve VS Code issues for compiling and running; updated to latest Microsoft Azure Functions Maven Plugin, and removed GUID naming that was previously added but breaks Debug launching in VS Code.
Initial fixes for bugs when loading local Fonts vs Font Resources via Azure Function running with Windows OS.
1 parent 714e645 commit 563aeea

File tree

6 files changed

+99
-21
lines changed

6 files changed

+99
-21
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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": "flat"
9+
}
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/pom.xml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@
2828
<groupId>org.apache.xmlgraphics</groupId>
2929
<artifactId>fop</artifactId>
3030
<version>2.6</version>
31+
<!-- We MUST explicitly exclude these to ensure VS Code can correctly compile.
32+
NOTE: This is because they are referenced in from multiple libraries and while
33+
Maven (via IntelliJ) resolves it, VS Code Java Extensions will fail to compile -->
34+
<exclusions>
35+
<exclusion>
36+
<groupId>xml-apis</groupId>
37+
<artifactId>xml-apis</artifactId>
38+
</exclusion>
39+
<exclusion>
40+
<groupId>java.xml</groupId>
41+
<artifactId>java.xml</artifactId>
42+
</exclusion>
43+
</exclusions>
3144
</dependency>
3245
<dependency>
3346
<groupId>org.apache.commons</groupId>
@@ -81,16 +94,18 @@
8194
<plugin>
8295
<groupId>com.microsoft.azure</groupId>
8396
<artifactId>azure-functions-maven-plugin</artifactId>
84-
<version>1.9.2</version>
97+
<version>1.14.0</version>
8598
<configuration>
8699
<!-- The App Name & Resource Group Name must both be Unique or deployment issues may arise
87100
as NOTED here: https://github.com/Azure/azure-functions-java-worker/issues/140 -->
88101
<!-- function app name -->
89102
<!--suppress UnresolvedMavenProperty -->
90-
<appName>${appBaseName}-${project.build.uuid}</appName>
103+
<!-- <appName>${appBaseName}-${project.build.uuid}</appName> -->
104+
<appName>${appBaseName}</appName>
91105
<!-- function app resource group -->
92106
<!--suppress UnresolvedMavenProperty -->
93-
<resourceGroup>java-functions-group-${project.build.uuid}</resourceGroup>
107+
<!-- <resourceGroup>java-functions-group-${project.build.uuid}</resourceGroup> -->
108+
<resourceGroup>java-functions-group</resourceGroup>
94109
<!-- function app service plan name -->
95110
<appServicePlanName>java-functions-app-service-plan</appServicePlanName>
96111
<!-- function app region-->
@@ -107,10 +122,6 @@
107122
<!-- runtime os, could be windows, linux or docker-->
108123
<os>windows</os>
109124
<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> -->
114125
</runtime>
115126
<appSettings>
116127
<property>

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

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ 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);
@@ -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
});

0 commit comments

Comments
 (0)