Create a subclass of CordaCaplet for the web server to put the cordapp JARs on its class path.

This commit is contained in:
Florian Friemel 2018-12-20 15:51:58 +00:00
parent 3c13c07c09
commit 12f14275c0
No known key found for this signature in database
GPG Key ID: B355EFB36013CB32
3 changed files with 32 additions and 5 deletions

View File

@ -12,8 +12,8 @@ import java.util.*;
public class CordaCaplet extends Capsule {
private Config nodeConfig = null;
private String baseDir = null;
protected Config nodeConfig = null;
protected String baseDir = null;
protected CordaCaplet(Capsule pred) {
super(pred);
@ -156,7 +156,7 @@ public class CordaCaplet extends Capsule {
} else return super.attribute(attr);
}
private void augmentClasspath(List<Path> classpath, File dir) {
protected void augmentClasspath(List<Path> classpath, File dir) {
try {
if (dir.exists()) {
// The following might return null if the directory is not there (we check this already) or if an I/O error occurs.
@ -179,7 +179,7 @@ public class CordaCaplet extends Capsule {
}
}
private Boolean checkIfCordappDirExists(File dir) {
protected Boolean checkIfCordappDirExists(File dir) {
try {
if (!dir.mkdir() && !dir.exists()) { // It is unlikely to enter this if-branch, but just in case.
logOnFailedCordappDir();

View File

@ -0,0 +1,25 @@
import java.io.File;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
public class CordaWebServerCaplet extends CordaCaplet {
protected CordaWebServerCaplet(Capsule pred) {
super(pred);
}
@Override
@SuppressWarnings("unchecked")
protected <T> T attribute(Map.Entry<String, T> attr) {
T cp = super.attribute(attr);
if (ATTR_APP_CLASS_PATH == attr) {
File cordappsDir = new File(baseDir, "cordapps");
// Create cordapps directory if it doesn't exist.
if (checkIfCordappDirExists(cordappsDir)) {
// Add additional directories of JARs to the classpath (at the end), e.g., for JDBC drivers.
augmentClasspath((List<Path>) cp, cordappsDir);
}
}
return cp;
}
}

View File

@ -38,7 +38,9 @@ task buildWebserverJar(type: FatCapsule, dependsOn: project(':node').tasks.jar)
applicationSource = files(
project(':webserver').configurations.runtimeClasspath,
project(':webserver').tasks.jar,
project(':node').sourceSets.main.java.outputDir.toString() + '/CordaWebServerCaplet.class',
project(':node').sourceSets.main.java.outputDir.toString() + '/CordaCaplet.class',
project(':node').sourceSets.main.java.outputDir.toString() + '/CordaWebServerCaplet$1.class',
project(':node').sourceSets.main.java.outputDir.toString() + '/CordaCaplet$1.class',
project(':node').buildDir.toString() + '/resources/main/reference.conf',
"$rootDir/config/dev/log4j2.xml",
@ -52,7 +54,7 @@ task buildWebserverJar(type: FatCapsule, dependsOn: project(':node').tasks.jar)
systemProperties['visualvm.display.name'] = 'Corda Webserver'
minJavaVersion = '1.8.0'
minUpdateVersion['1.8'] = java8_minUpdateVersion
caplets = ['CordaCaplet']
caplets = ['CordaWebServerCaplet']
// JVM configuration:
// - Constrain to small heap sizes to ease development on low end devices.